Before starting working with java I am assuming that you have jdk installed on your local machine.
You can start writing java program using a notepad.
Below are the steps for writing hello world program in java :
1) Create a file and rename it to HelloWorld.java
2) Open the above file and put the blow code in it
1| public class HelloWorld
2| {
3| public static void main(String args[])
4| {
5| System.out.println("Hello World");
6| }
7| }
3) Save the file.
4) Open a command prompt go to the location where u have saved this file and run the following command :
C:>javac HelloWorld.java
5) This should run successfully with no errors.
6) Now run it using below command :
7) This should run successfully and should show you "Hello World" message on command prompt.
8) Congrats you are done with your first java program.
Description :
Line No.1
It's the declaration of a class.
public* : It's a java access modifier which decides the scope of the object.
class* : Java compiler identifies it as a class.
HelloWorld : This is the name of the class. (The name of the file and class must be same).
Line No.3
Method declaration.
static* : It can be accessed before any object of that class is created and without reference to any object. Both methods and variable can be declared as static.
void* : It's the return type of the method. Using 'void' as the return type represents that it doesn't return anything
main : It's the name of the method.While running a java program the java virtual machine identifies the this method name and will start executing the line of code from this method.If this method is not found then it will throw and exception asking for 'main' method.
String* args[] : These are the parameters sent to the main method. 'String' the type of the parameter. arg[] is the string array.
Line No.5
System.out.println("Hello World"): "System.out.println"
That's it for hello world program let me know your views or if you face any issue in this program.
* : They are java keywords
You can start writing java program using a notepad.
Below are the steps for writing hello world program in java :
1) Create a file and rename it to HelloWorld.java
2) Open the above file and put the blow code in it
1| public class HelloWorld
2| {
3| public static void main(String args[])
4| {
5| System.out.println("Hello World");
6| }
7| }
3) Save the file.
4) Open a command prompt go to the location where u have saved this file and run the following command :
C:>javac HelloWorld.java
5) This should run successfully with no errors.
6) Now run it using below command :
C:>java HelloWorld
7) This should run successfully and should show you "Hello World" message on command prompt.
8) Congrats you are done with your first java program.
Description :
Line No.1
It's the declaration of a class.
public* : It's a java access modifier which decides the scope of the object.
class* : Java compiler identifies it as a class.
HelloWorld : This is the name of the class. (The name of the file and class must be same).
Line No.3
Method declaration.
static* : It can be accessed before any object of that class is created and without reference to any object. Both methods and variable can be declared as static.
void* : It's the return type of the method. Using 'void' as the return type represents that it doesn't return anything
main : It's the name of the method.While running a java program the java virtual machine identifies the this method name and will start executing the line of code from this method.If this method is not found then it will throw and exception asking for 'main' method.
String* args[] : These are the parameters sent to the main method. 'String' the type of the parameter. arg[] is the string array.
Line No.5
System.out.println("Hello World"): "System.out.println"
This will print whatever data is given in the opening and closing brackets in this case it's 'Hello World'.
That's it for hello world program let me know your views or if you face any issue in this program.
* : They are java keywords
Comments
Post a Comment
.