- Computers & Software»
- Computer Science & Programming»
- Programming Languages
How to Write Program and Class in Java Using Netbeans: Easy Steps
Get A Website Plus a Free Domain Name in Just 1 Hour!
Bring the new technology in your hands! Share your skills, improve and impress. Get Your Own Website and a Free Domain Name Here!
This is a step by step process on how to program in Java. First, you must have a Java compiler or Java IDE, the word IDE stands for Integrated Development Environment, Java IDE is use to make simple Java projects. There are many Java IDE’s, as for myself, I use Netbeans IDE for my Java programming projects, and in this tutorial I will also use Netbeans IDE as an example on how to program in Java. Either you have Netbeans or other Java IDE’s it does not really matter, what matters is you must have an idea on how to program in Java in order to make some Java simple projects on whatever Java IDE you have. If you do not have an IDE you can download a free Java IDE or better download Netbeans IDE on the web, just look for it; if you want a safe free download you may browse it at cnet.com, just type cnet: Netbeans IDE on the google search box.
How to Program in Java: Complete Simple Easy Steps
Assuming that you now have an installed Netbeans IDE.
Step 1: Open your Netbeans IDE
Step 2: Click FILE located at the left upper side, near the edge, and click the NEW PROJECT.
Step 3: Click JAVA at the categories column and click JAVA APPLICATION on the projects column, then click NEXT button below the dialog box. See sample snapshot below.
Step 4: Change the name of the PROJECT NAME in the dialog box to whatever names you want that will best describe your ‘will be’ java program, as for this tutorial, I will name the PROJECT NAME ‘javaSampleCoding’. After you finish typing the projects name, click FINISH button below the dialog box. See sample snapshot below.
Step 5: After clicking FINISH, a tab would open which has an embedded name ‘Main.java’. The interface should be like this.
On this Main.java tab, you can now code your first program. You can copy and paste my code on just click this link in a new tab. There are Java simple codes written there especially made for beginners, But before you proceed, read the NOTE below.
Note: Before you copy and paste the code on the link, make sure that you erase all the codes on the Main.java except for the codes in lined with package, as it would duplicate some of the codes if you don’t. The codes on my link above are already complete. You must try first the code that outputs: “This is just an example…” before the second given code. It is just actually like a hello world program. After copying and pasting, your interface should look like this.
Step 6: Run it by pressing CTRL + F6 for keyboard shortcut or click RUN -> RUN MAIN PROJECT on the toolbar.
After clicking the RUN, wait a moment. You can see that the program is compiling by looking at the lower left side of the IDE. Then,finally, after a few seconds you can now see the output of the program. It will look like this.
If you intend to make a new project, just repeat the steps above. You can experiment on System.out.print(); by changing the text inside it then run again the program to see the word you typed.
To further deepen your experience with Java programming and with Netbeans IDE, you should know how to make a Java class. Almost all of my sample Java source codes are in OOP (Object Oriented Programming), meaning the program is chopped in classes and methods. The codes are divided and is not all placed at the Main.java. The purpose of programming in this way is for the programmers to easily debug the program. Meaning, if there is something wrong with the program the programmers can easily detect it because the codes are chopped in groups.
Furthermore, to make a program that contains Java class, just repeat the STEP 1 – STEP 5, then proceed to STEP 7 below. But before doing this read first the Note below.
Note: As an example for java program which contains class, I will pick the sample java source code for the RECURSIVE DIAMOND SHAPE,This is the link for it. You can name your PROJECT NAME: ‘recursiveDiamondShape’.
Moreover, to identify the codes for java class and the code for main class, find this sign ->//java class, and all the codes below it are java class codes and stop copying if you see this sign-> //main class, because the preceding codes below it is for Main.java.
Now ready? After completing the STEPS 1-5, proceed to next step below.
STEP 7: Bring your cursor to PROJECTS, located at the left upper side just below the tool bar. Click it, then find your PROJECT NAME which is ‘recursiveDiamondShape’ click it, you will see SOURCE PACKAGES folder, then below it is the folder which name ‘recurseiveDiamondShape’, your program’s name. RIGHT CLICK it, then NEW-> then JAVA CLASS -> then name the CLASS NAME this: ‘Diamond’ then click FINISH button below, after that, a new tab will open at your Netbeans IDE which has a name Diamond.java.
For your Diamond.java, copy and paste the //java class codes on the link below. The interface for the Diamond.java, after the copy and paste, should look like this.
For your Main.java, make sure to erase all except for the code in line with package. The interface for the Main.java should look like this.
Then run the program by CTRL + F6 while you are on the Main.java interface, the sample snapshot for the output looks like this.
The program's output look like the snapshot above if the entered number is 12, to test the program again, just click Run, or CTRL + F6 and enter the number you want then hit ENTER on the keyboard.
Is this hub clear to you?
Other Java Source Codes Examples
- Java Simple Codes for Beginners
- Java source code: Print Different Asterisk Shapes in Recursion
- Java Source Code: A Recursive Asterisk Diamond Shape
- Java Source code: How to Add Numbers inside an Array using For Loop
- Java Source code: How to Add numbers inside an Array Using Recursion
- Java Source code Print String Backward using Recursion
- Java Source Code on a Recursive Linear Search
- Java Source Code: Binary Search in Recursion
- Java Source Code: Sort Numbers in Bubble Sort
- Java Source Code: Sort Numbers using Selection Sort
- Java Source code on Printing the Greatest Common Divisor (GCD) using Recursion
- Java source code: Recursive function for X to the power Y
- Java Source Code Determine Person's Salutation and Current Age
- Java Source Code: Recursive Koch Snow Flakes