First java program


First java program ! Hello java Example

In this post ,we will learn how to develop first java program. we can write Hello java program after installing the JDK.

To create and execute first java program , you need to a class that contains main method. Before creating class we need to install JDK to compile and run the java program.

The Requirement for Hello java program

To compile and run any java program, you need to install latest version of JDK.

  • Install JDK if you don’t have to install it, Download the JDK and install it
  • Set path of JDK
  • develope the first java program.
  • compile and run the java program through cmd.

STRUCTURE of a java program

Package details:

class <clsname>

{

Data member’s declaration;

User defined methods;

Public static void main (string gk [])

{

Block of statements ();

}

}

  • Every program in JAVA must be developed with respect to class.
  • Data member’s declaration represents the type of data members which we use as a part of the class.
  • User-defined methods represent the type of methods which we use as a part of the class to perform some meaningful operation by making use of the data members of class.
  • Here main represents the name of the method where the program execution starts and void represents return type.
  • Since main method is executing only once hence it must be static method. Since main method can be called/accessed by everybody and hence it belongs to public method.
  • Block of statements represents the valid executable statements of JAVA which will call theuser defined methods.

class First{

public static void main(String args[])

{

System.out.println(“My First java program”);

}

}

Save this program using First.java

To compile the java program you will use following command.

To Compile javac First.java

And to run the java program you will use another command i.s

To run java First

Output : My First java program

Terminologies used in First java program.

we discuss different terminologies like class, public, static, void, main etc..

class: class is keyword used to declare class in java.

public: the public is keyword it represents the visibility modifiers, that is it visible to all.

static: Since main method is executing only once hence it must be static method

void: represents return type anything of main method which indicates main method does not return.

main: Here main represents the name of the method where the program execution starts.

String gk[]: it is used to array of string as input from command line arguments.

System: is class in java.

out : is object of PrintStream class.

println():is method of PrintStream class.


To print the message on the screen.


System.out.println(“My First java program”);

Leave a Reply