Classic Hello World in Java

Example of Classic "Hello! World"

1. Open any Code Editor (Eclipse is one of the most popular code editor) and create a Class by name FirstJavaProgram
2. If you are using Eclipse (either Neon, Oxygen, photon or  any other ..) , simply open Eclipse and go to File, then scroll down to  "New" and then scroll to "Project" and click on Project
3. In the "New Project" wizard Select "Java Project"
4.  In the "Create a Java Project" wizard, give a name of your project. Example: MyNewProject
5. Click "Finish"
6. A new empty Java Project is created which you can see in Package explorer on the left panel
7. Now, right click on the newly created Project and select "New" and scroll and click on "Class"in the wizard "Java Class".  Give a name of your java class. Example: FirstJavaProgram
8. In the bottom portion of the wizard, you will notice few check  boxes, you should select first check box which says " public static void main (String []args)
9. Click "Finish" and you will notice the wizard disappeared and a new Class (with some code) is displayed in the editor

[ Not sure what you did by following all these 9 steps as above? Well, by now you have learned how to open a new Java Project and a Java Class in editor. This way you will be able to open as many java project or java class you need in future. Pretty simple ....... right?]

If you used class name as "FirstJavaProgram"; then your code in the editor should look exactly like this as below:
Snippet A
public class FirstJavaProgram {
  public static void main(String[] args){
    
  }
}

[Yes! you are right ........... every time you open a Class it should look like it.]

Now what ?
Okay! lets make this code executable and insert an output message as "Hello Java world!"

Snippet B
public class FirstJavaProgram {
  public static void main(String[] args){
    System.out.println ("Hello Java world!")
  }
}

Explanation of Code:
a) Snippet A :
This the the default Class shell java imported for you by default every time you open a java class.
This shell has two parts
i) Class name ..... comes with 2 curly braces
ii) JVM class ...... comes with 2 curly braces

Well, JVM Class? what do you mean by that?
- JVM is Java Virtual Machine. For Code compilation and library file execution Java require this class so that it
understands what code it should be executing. Basically within this JVM class whatever you put Java understand
that, this is the portion of code JAVA suppose to execute when you run the code.

B) Snippet B: This snippet has one sentences extra than snippet A, which is basically your :Hello java world 
code.  "System.out.println" is the java code that you wrote to execute a print statement.
 
In the code console (at the bottom portion);you will notice the message is displayed "Hello Java World", 
when you executed this class

Congratulations! you just wrote your first Java Code.













Comments

Popular posts from this blog

How to Create an Issue in JIRA (2)

Fundamentals of Accessibility Testing ... 2