Recent Tutorials and Articles
    Hello World Java Program
    Published on: 2018-05-25 16:05:13

    Hello World Java program for Java beginners. This shall get you started with Java programming.

    Before you start writing your first program, you need to ensure that you have got the java installed on your machine. You can check it by going to command prompt and typing following command -

    java -version
    

    If you haven't got java installed in your system, you can download it from here and install it by running wizard.

    Once you have installed java or you already had installed, you need to add your java bin path to the environment variable named Path. Java is normally installed in Java folder in your "Program Files". For me, it was - C:\Program Files\Java\jdk1.6.0_35\bin. Additionally, please restart the command prompt if you have got it open already.

    We are all set to write our java program. Firstly write the below code in any of the text editor that you like. File name must be same as the public class name, therefore You need to save the file with name - HelloJava.java

    HelloJava.java
    
    public class HelloJava {
    	public static void main(String args[]){
    		System.out.println("Hello Java");
    	}
    }
    
    

    You would be curious about many things in the above program. Here are the explanation of some of the keywords -

    1. public is one of the access modifiers in the java allowing you to specify where this paticular unit(class, method, field) can be accessed from. public means this can be accessed from any where.
    2. static lets you access the methods and fields without creating the instance of the class. Since Java Virtual Machine (JVM) needs to access the main method to start execution of the program, JVM requires it to be static so that it doesn't need to create the object of the class.
    3. void means that this method doesn't return anything.
    4. main is not a keyword but this is the starting point of a standalone java program/application.

    Now it's time to run this program but in Java, we need to follow 2 steps before you can get your program executed. First step is to compile your java program. To compile your program, open command prompt and go to the folder where you have saved your java program file. Type in the below command to compile your program. If it compiles fine, it will simply run without any message.

    
    javac HelloJava.java
    
    

    If it compiles fine, you will see a new file called HelloJava.class which contains your program's bytecodes representation needed to run your program.

    Finally, enter the below command to run the program.

    
    java HelloJava
    
    

    Here is the output that you will see after running the program -

    
    Hello Java
    
    

    Thank you for reading through the tutorial. In case of any feedback/questions/concerns, you can communicate same to us through your comments and we shall get back to you as soon as possible.

    Published on: 2018-05-25 16:05:13

    Comment Form is loading comments...