GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C programming
  • C++ programming
  • Java programming
  • Python programming
  • HTML
  • CSS
  • Codenora IDE (opens in a new tab)
  • About us
  • Pricing
  • Contact us
  • Privacy policy
  • Terms of service
  • Refund and Cancellation

This view

  • Original page
  • New address

GeezerVison is showing www.dremendo.com — Learn the Basic Structure of a Java Program | Dremendo

  • Dremendo
  • C
  • C++
  • Java
  • Python
  • HTML
  • CSS
  • More
    • Home
    • C Tutorial
    • C++ Tutorial
    • Java Tutorial
    • Python Tutorial
    • HTML Tutorial
    • CSS Tutorial
?>
profile image
Announcements
No new announcements.
mentora icon
Java Programming Tutorial
  • Java Basic Concepts
    • Introduction
    • Variable
    • Data Types
    • Naming Conventions
    • Integer Variable
    • Long Variable
    • Short Variable
    • Byte Variable
    • Float and Double Variables
    • Character Variable
    • Boolean Variable
    • Constant Variable
    • Typecasting
  • Operators in Java
    • Operators
    • Assignment Operators
    • Arithmetic Operators
    • Relational Operators
    • Logical Operators
    • Operator Precedence
  • Input and Output in Java
    • Environment Setup
    • Program Basic Structure
    • Output
    • Input
    • Comments
  • Decision Making in Java
    • Decision Making
    • if Statement
    • if else Statement
    • if else if Statement
    • Conditional Operator
    • switch case Statement
  • Mathematical Functions
    • Mathematical Functions
  • Loops in Java
    • Loops
    • for Loop
    • while Loop
    • do while Loop
  • Arrays in Java
    • One Dimensional Array
    • Two Dimensional Array
  • String in Java
    • String
    • StringBuffer
    • StringBuilder
  • Searching in Java
    • Linear Search
    • Binary Search
  • Sorting in Java
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
  • Function in Java
    • Function
    • Recursive Function
    • Function Overloading
  • OOPs in Java
    • Classes and Objects
    • Instance Variables
    • Instance Methods
    • Access Modifiers
    • Constructor
    • Static Variables
    • Static Methods
    • Inheritance
    • Interface
    • Types of Inheritance
    • Polymorphism
    • Final Class and Method
    • Abstract Class and Method
    • Wrapper Classes
  • Data Structures in Java
    • Stack
    • Queue
    • Circular Queue
    • Double Ended Queue
    • Singly Linked List
    • Doubly Linked List
    • Stack using Linked List
    • Queue using Linked List
  • Packages in Java
    • Packages
  • Exception Handling in Java
    • Exception Handling
    • User-Defined Exception
  • Thread in Java
    • Thread
    • Thread Methods
  • File Handling in Java
    • Text File Handling
    • Binary File Handling
    • Random Access File Handling

bookmark
Table of Contents

    Learn the Basic Structure of a Java Program

    In this lesson, we will learn about the essential includes of a Java program and its basic structure.

    Basic Structure of a Java Program

    In this tutorial, we will explore a Java program's basic structure and its includes. By understanding the basics of a Java program, you will be better equipped to write your code and build more advanced programs.

    java program structure
    Video Explanation

    Click the button below to watch the explanation.

    Please wait while the video is loading....
    video image
    Example

    This is how a simple basic structure of a Java program looks like.

    public class Test
    {
        public static void main(String[] args)
        {
            // your program goes here
        }
    }

    Now we will discuss the various parts of the basic structure of a Java program given above.

    Class Declaration

    A Java program may contain several class definitions, and classes are an essential part of any Java program. Every program in Java will have at least one class with a main method. The class that contains the main method does not need to be declared public, but if it is declared public, the class name must match the filename in which the program is saved.

    Note

    It is generally considered good practice to declare a class as public if it contains the main method.

    Braces (Both Opening and Closing Brace)

    The curly braces are used to group all the commands together. To make sure that the commands belong to a class or a method.

    Main Method

    In Java, the public static void main(String[] args) is treated as the entry point of the program. The main method is called by the Java Runtime Environment (JRE) when the user runs the program.

    What is a Compiler

    In Java, a compiler (the javac tool) is a special program that translates Java source code (.java files) into an intermediate, platform-independent code called Bytecode (.class files), which can then be executed by the Java Virtual Machine (JVM).

    Steps Involved in Compiling and Running a Java Program

    Compiling a Java program is like turning your handwritten instructions into something a computer can understand. When you write a Java program and save it with a .java extension, the journey from source code to execution goes through five main steps and they are:

    Step 1: Write the Program
    You write your Java program (source code) in a text editor or IDE (e.g., Notepad, Eclipse, IntelliJ). Save it with a .java extension. Example: Hello.java.
    Step 2: Compilation
    In this step, the compiler takes the source code file (for example, Hello.java) and check it for Syntax errors (grammar mistakes in code). It ensures type correctness. If there are no errors, it generates a bytecode file. Example Hello.class.
    Step 3: Loading the Class (Class Loader)
    When you run the program, the Class Loader inside the JVM loads the .class (bytecode) file into memory. It also loads any required built-in or user-defined classes.
    Step 4: Bytecode Verification
    JVM’s Bytecode Verifier checks the bytecode for: Security (no illegal memory access), Type safety (data types used correctly) and Format correctness. This prevents malicious or corrupted code from harming the system.
    Step 5: Execution by JVM
    The Interpreter inside the JVM starts executing bytecode instructions line by line. Frequently used code is optimized by the Just-In-Time (JIT) compiler, which converts bytecode into native machine code for faster execution.

    java compilation steps jdk jre jvm

    Test Your Knowledge

    Attempt the questions in the exercise to check whether you have understood the lesson clearly.

    Exercise
    Test Your Knowledge
    Previous Next

    We care about your privacy

    Dremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy.

    Cookie Preferences

    Choose which types of cookies Dremendo may use.

    Necessary Cookies

    Required for essential website functionality and security.

    Allow
    Analytics Cookies

    Help us understand how visitors use Dremendo.

    Allow
    Marketing Cookies

    Help us measure advertising performance and understand interactions with our advertisements.

    Allow
    Mentora Question Asked: 0 / 20

    Hi, I’m Mentora!

    I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way.

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.