Friday, August 15, 2014

NETBEANS Java Basics 101 – Getting Started

---
NETBEANS Java Basics 101 – Getting Started

PREREQUISITE

Download NetBeans from https://netbeans.org/downloads/ 

STEPS

1) Create New Project.

1-1) Go to menu, select File/New Project…
1-2) Select Java Categories/ Java Application.
1-3) New Java Application.
Project Name: First Project
Create Main Class: firstproject.FirstProject
Info:
If you don’t select Create Main Class, your project will start without any source codes (Java Class).
You will have to add Java Class manually.
1-4) Project creation is done.
1-5) Look at the Code Editor window.
Ignore the comment lines.
The important codes are as shown below.
1-6) You can keep a copy of this codes first so that you can use them again as a starting point for future projects.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        // TODO code application logic here
    }
   
}
Startup Codes
1-7) Copy the Startup Code above and replace the original codes. We want to get rid of other unnecessary codes so that our codes look clean and tidy.
As for a start, we are going to focus at line no.6 (Application Logic).

2) Output Statement.

2-1) Replace // TODO code application logic here with an Output Statement.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        System.out.println("My First Project");
    }
   
}
2-2) Click Run button.
2-3) Outcome.

3) Variable Declaration Statement.

We will declare an integer variable, ie a storage for integer numbers (round numbers eg 0,1,2,3,4,5).
3-1) Add int first_number; before the Output Statement.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        int first_number;
        System.out.println("My First Project");
    }
   
}
3-2) Click Run button.
3-3) Outcome.

No changes to Output as the Variable Declaration Statement is internal to the program.

4) Variable Assignment Statement.

We will write a variable assignment statement, ie assign a value to the variable for keep.
4-1) Add first_number = 10; before the Output Statement.
4-2) Change the Output Statement.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        int first_number;
        first_number = 10;
        System.out.println( "First number = " + first_number );
    }    
}
4-3) Click Run button.
4-4) Outcome.

5) Data Operation on Number Variables

5-1) Add two more variable declaration statements.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        int first_number, second_number, answer;
        first_number = 10;
        System.out.println( "First number = " + first_number );
    }    
}
5-2) Add two more variable assignment statements.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        int first_number, second_number, answer;
        first_number = 10;
        second_number = 20;
        answer = first_number + second_number;
        System.out.println( "First number = " + first_number );
    }    
}
5-3) Change the output statement.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        int first_number, second_number, answer;
        first_number = 10;
        second_number = 20;
        answer = first_number + second_number;
        System.out.println("Addition Total = " + answer );
    }    
}
5-4) Click Run button.
5-5) Outcome.

REFERENCE

---


No comments:

Post a Comment