Menu
gps garage
  • Home
  • Health
  • Nature
  • IT & Software
  • Science
  • Technology
  • Offers
  • Write for Us
    • Privacy Policy
    • Terms & Conditions
gps garage
structure for java program

Structure for Java Program which will clear your all doubt (1st Java Program)

Posted on April 27, 2021May 7, 2021

Structure for Java Program

A basic java program (Hello program) is divided into following parts:

import java.io.*;                                          // Package

class Hello{                                                 // class name and opening curly brace

public static void main(String args[])         // Main Method

{                                                                 // opening curly brace

// comment or /* comment */                  // comment

System.out.println(“Hello World”);       // statement

}                                                               //closing curly braces
}                                                                  //closing curly braces

 

Explanation (structure for java program)-

  • Package: Here the package is declared according to the program. Programmers will declare More than one package according to their need. Packages define classes, interfaces and sub-packages. These packages are declared at the top of the program.
  • class name and opening curly brace: Here the name of the class is written with the keyword ‘class’. But the name of the class is not the keyword of java.
  • public static void main(String args[])
  • public: This is an access specifier. public means the method is accessed from any class.
  • static: static means the class is accessed without object or instance.
  • void: This main method allows nothing to be returned.
  • (String args []): This is String, it is not a keyword, it is a class since its first character is in uppercase and args [] is an array of the object of the String class. This is the argument of the main function.
  • Comment: This is a comment tag. It is not read by the compiler. It has two types.
  • One Line Comment: It is commented with two slashes. // comment
  • Multiple Line Comment: It is started with a slash and asterisk (/ *) and closed with asterisk and slash (* /). / * Multiple line comment * /
  • out.println ()–
  • System: This is a predefined class.
  • out: This is the object of the PrintStream class, it is defined in the System class with the public static final these keywords.
  • println: This is the method of PrintStream class. It is defined inside the PrintStream class with public. It is ‘ln’ with print. This allows the cursor to move to the new line.
  • closing curly braces: here the main method and class is closed.

structure for java program

How to Run Java Program?

Download JDK for all Operating System

Categories

  • Education
  • Entertainment
  • Features
  • Game
  • Health
  • IT & Software
  • Must Read
  • Nature
  • News
  • Offers
  • Popular News
  • Science
  • Technology
  • Trending News
  • World

Archives

  • March 2025
  • January 2025
  • December 2024
  • September 2022
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021

Categories

  • Education
  • Entertainment
  • Features
  • Game
  • Health
  • IT & Software
  • Must Read
  • Nature
  • News
  • Offers
  • Popular News
  • Science
  • Technology
  • Trending News
  • World

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2025 GPS Garage | Powered by SuperbThemes