Computer

Hello World Java

Hello World Java
Want create site? With Free visual composer you can do it easy.
First let’s see how to run a Java Program using a text editor like Note pad and command prompt and after that let’s move on to the NetBeans I.D.E.
Java is an Object Oriented, High-level programming language.

To run Java in your machine you have to install Java Development Kit  (JDK). You can download JDK and NetBeans  fom this link .

And we have to set the Java bin path to the path-variable.

1st Step :
C Drive -> Program Files -> Java -> jdk -> bin-> copy the path .
(when you click on the bar with the folder icon which contains the folder path you can copy the path) 
2nd Step :Computer -> Properties -> Advanced system settings -> Environment variables… -> select ‘path’ variable in System variables -> Edit… -> type a semicolon(;) and paste the path and then type a backslash() ->OK
Now let’s write our first code.1. Type this code in your text editor.
 public class MyFirstJavaProgram {

 public static void main(String[] args) {
 System.out.print("Hello world Java");
 }
}

Here I am going to briefly explain the code.

The method is declared inside a class. When we run a Java code ,the main method body will be to execute from top to bottom. We can’t run a Java code without the main method, but we can compile without the main method. In run time it seeks the main method.

Hello code Explain

2. Save this as MyFirstJavaProgram.java.
File -> Save As… ->  File name    : MyFirstJavaProgram.java -> Save
                                   Save as type: All Files
The name of the source file should be our class name with .java file extension.
3. Open the Command prompt and go to the place where you have saved your source file.
Shift + Right click -> Open command window here4. type javac MyFirstJavaProgram.java in the command prompt and press enter.
If there aren’t any errors it will move onto the next line.When we type our file name (class name) with .java extension in front of javac command we can compile our code. In our text editor we can see our code in a human readable format. When we compile the code, a class file will be automatically generated and it is in computer readable format. If you go to the place where you have saved your source file you can see MyFirstJavaProgram.class file.

Hello Code compile

5. Now type java MyFirstJavaProgram in the command line and press enter.
If there aren’t any errors the output will be displayed.When we type our file name(class name) with the java command and press enter we can run our code.

Hello Code run


Now let’s see how to use NetBeans I.D.E. to run our first program.

NetBeans -> File -> New Project -> from Categories select ‘Java’ and from Projects select ‘Java Application’ -> Next -> give the ‘Project Name ‘ as MyFirstJavaProgram -> Give a Location and a Folder to save the project -> tick the box in front of ‘create Main class’  ->Finish

Net beans New project

Net beans New application

NetBeans make our work easy. With this program we only have to type our print statement inside the main method body.

Net beans

Here we can use several ways to compile a project.

1. Main Menu -> Run -> Build Project
?
2.Use f11 keyboard short cut.

Net beans

3.Click on this icon in the icon menu.

If there aren’t any errors we can see  BUILD SUCCESSFUL  in the output window.

 

Here we have several ways to run a program also.

1. Main Menu -> Run -> Run Project

2.Use f6 keyboard shortcut.

Net beans run

3. Click on this icon in the icon menu.

After running the project we can see ‘Hello world Java’ in the output window.

Hello world java output

Dinuka Jayaweera
Dinuka is a Contributor at Nerdynaut Staff from Sri Lanka.
Did you find apk for android? You can find new Free Android Games and apps.
  • Fascinated
  • Happy
  • Sad
  • Angry
  • Bored
  • Afraid

FB comments

Use 3dcart to create your online store.
1 Comment

1 Comment

  1. Thilini

    December 19, 2015 at 10:47 am

    Nice work 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular

​Disclaimer : Nerdynaut is a tech company which consists of professionals in respective academic fields in its functional team facing challenging roles to quench the thirst of knowledge in cyberspace. Every article and majority of artworks in this website are copyright of Nerdynaut 2017. After a written permission from the publisher, the original content can be reused or referred for promotional work of education without any modification. Expressions of mass media with intentional harm on Nerdynaut brand may be liable to criminal prosecution and civil claims for the damages caused.
Protected by Copyscape
* = required field

Copyright©2014-2017.The Nerdynaut. All Rights Reserved. A game-changing subordinate of Naut's Holdings.
Made in Sri Lanka.

To Top