"Write Once, Run Anywhere!" |
The very first step into coding in a new language, whatever programming language that it might be, that you learn is to create a Hello World Program. We'll hence do so here using NetBeans IDE.
Creating such an elementary program is supposed to give you basic know-how over how to build JAVA Applications using NetBeans also.
Hence lets get started.
Open the NetBeans IDE by double-clicking on the icon shown below.
NetBeans IDE Icon |
Opening the NetBeans IDE, you'll be greeted by the following screen. Click the "New Project" button on the top left as shown.
Click the "New Project" button on the Top Left. |
After doing so, we'll be greeted with a dialogue asking us the type of project we want to build. We will make the following selections that will enable us to build a JAVA Application and click "Next".
Select JAVA Application to be the project type and click next. |
We will now be asked the particulars of our JAVA Project. We will hence be providing the project name and the corresponding main class name as shown below.
Type in the Project Name and cut the projectname.projectname to project name. |
One thing we need to keep in mind is that for now, we will create the main class of the pattern "project name" and NOT instead as it appears as "project name.project name".
Hence the name of the main class for us will be just "HelloWorld" and not "helloworld.HelloWorld".
The Project Screen you are greeted with following the previous dialogue box. Notice the comments and the main class you just created. |
For removing the clutter, you may delete the comment entries at the top and inside the class.
Comments can be given in three ways in JAVA.
The first type is the single line comments, given as \\comment.
The second is a multi-line comment, given as \*comment*\
The third is Javadoc comments, given as \**comment*\
These are used to create documentation in HTML Webpages using an application called Javadoc. This is also a multi-line comment.
Comments can be given in three ways in JAVA.
The first type is the single line comments, given as \\comment.
The second is a multi-line comment, given as \*comment*\
The third is Javadoc comments, given as \**comment*\
These are used to create documentation in HTML Webpages using an application called Javadoc. This is also a multi-line comment.
Now as you can see on your screen, we have a public class named HelloWorld. This is the main class for our program. It can or cannot be public, its totally your discretion.
It contains a method named main() which is the function our execution starts with.
It contains a method named main() which is the function our execution starts with.
The given signature of the main function is the default signature for main function everywhere in JAVA. It has to be public, it has to be static and it has to have the return type void.
The argument type String[] args is needed to give the arguments to the JAVA Application at runtime.
The argument type String[] args is needed to give the arguments to the JAVA Application at runtime.
To print "Hello World" on the screen, we will type the command
- System.out.println("Hello World");
Here System.out is the output stream object,
System is the class while out is a static object.
println is a method that tells the IDE that we want to print a line on the standard output (monitor) and then moves the cursor to the next line.
"Hello World" acts as the argument to the function println. Anything inside the parentheses of println(" ") will be treated as a string and will be printed on the monitor,
And finally, any command to be exceuted is terminated by a ; (semi-colon) in JAVA.
And finally, any command to be exceuted is terminated by a ; (semi-colon) in JAVA.
Hence after doing so, we will click the green triangle above (Run) and the output will be obtained in a small screen below as shown.
Successful Program Execution. |
Hence as you may see, you've just built your first JAVA Program using NetBeans. I hope this experience will remain with you forever and help you in building more advanced applications later on.
Also, working with Eclipse is a smooth affair altogether. Even though I couldve made the Hello World program on Eclipse, I made it on NetBeans. If anyone is interested in how to do the same using Eclipse, feel free to leave a comment below and I'll leave the steps for it.
Also, working with Eclipse is a smooth affair altogether. Even though I couldve made the Hello World program on Eclipse, I made it on NetBeans. If anyone is interested in how to do the same using Eclipse, feel free to leave a comment below and I'll leave the steps for it.
Have a good day :)
0 comments:
Post a Comment