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
9 Comments

9 Comments

  1. Thilini

    December 19, 2015 at 10:47 am

    Nice work 🙂

  2. Stefani

    April 26, 2017 at 5:16 pm

    Magnificent web site. A lot of helpful information here. I’m sending it to some buddies ans additionally sharing in delicious. And obviously, thanks to your effort!

  3. gpl-31t battery

    April 27, 2017 at 9:23 pm

    Hi, i feel that i saw you visited my web site thus i came to “return the want”.I am attempting to find things to enhance my website!I suppose its good enough to make use of a few of your ideas!!

  4. Kelsie

    April 29, 2017 at 7:35 pm

    Wow! Thank you! I continually needed to write on my blog something like that. Can I take a part of your post to my site?

  5. deep cycle battery charging

    April 29, 2017 at 10:34 pm

    Today, I went to the beach front with my kids. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

  6. Magali

    May 1, 2017 at 12:05 am

    Great items from you, man. I have have in mind your stuff previous to and you’re simply extremely excellent. I actually like what you’ve bought right here, certainly like what you’re saying and the way in which during which you assert it. You make it enjoyable and you continue to take care of to keep it smart. I can not wait to read much more from you. This is actually a wonderful website.

  7. Rafael

    May 1, 2017 at 12:16 pm

    Hello. splendid job. I did not anticipate this. This is a remarkable story. Thanks!

  8. Paris

    May 5, 2017 at 1:26 pm

    I and my pals appeared to be taking note of the good tricks on the blog while suddenly I had an awful suspicion I had not expressed respect to you for them. All the young men appeared to be as a result joyful to see them and now have definitely been tapping into those things. Appreciate your really being simply kind and then for figuring out some superior ideas most people are really desirous to discover. My sincere regret for not saying thanks to you sooner.

  9. eebest8

    May 13, 2017 at 6:58 am

    “Major thanks for the article post.Really looking forward to read more. Want more.”

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 Capital.
Made in Sri Lanka.

To Top