Sunday, July 27, 2014

Java Basics 104 - Operator Precedence

---
Java Basics 104 – Operator Precedence

STEPS

1) Browse http://ideone.com/1gau2Z 

2) Three numbers operation

Change line no. 13 to:
int first_number, second_number, third_number, answer;
Change line no.14-15 to:
first_number = 100;
second_number = 75;
third_number = 25;
Change line no. 16 to:
answer = first_number - second_number + third_number;
Change line no.18 to:
System.out.println("Total = " + answer );
Outcome:
3) Three numbers operation with bracket 1
Change line no. 17 to:
answer = (first_number - second_number) + third_number;
Outcome:
4) Three numbers operation with bracket 2
Change line no. 17 to:
answer = first_number - (second_number + third_number);
Outcome:
5) Three numbers operation with + and *
Change line no. 17 to:
answer = first_number + second_number * third_number;
Outcome:
The following codes also leads to the same outcome:
answer = first_number + (second_number * third_number);
Change the position of the brackets as follows. What would be the outcome?
answer = (first_number + second_number) * third_number;
6) Three numbers operation with () and /
Change line no. 17 as follows. What is the outcome?
answer = first_number + second_number / third_number;
Change line no. 17 as follows. What is the outcome?
answer = (first_number + second_number) / third_number;

LESSONS:

Here's a list on Operator Precedence
  • Multiply and Divide - Treated equally, but have priority over Addition and Subtraction
  • Add and Subtract - Treated equally but have a lower priority than multiplication and division
So if you think Java is giving you the wrong answer, remember that Operator Precedence is important, and add some round brackets.

REFERENCE

---

Java Basics 103 - Short and Float Variables

---
Java Basics 103 – Short and Float Variables

STEPS

1) Browse http://ideone.com/O5GIga 

2) Change the variables properties to Float Data Types.

Change line no.13 to:

float first_number, second_number, answer;
Change line no.14, 15 to:

first_number = 10.5f;
second_number = 20.8f;
Outcome:

3) Change the Operator to Division

Change the operator in line no.16 from “+” to “/”.
Outcome:

4) Double Variables

Change the Data Type for variables in line no.13 to Double.
Outcome:
Lessons:
When you use Float Data Type, the answer was 0.5048077. Java has taken the first 6 numbers after the point and then rounded up the rest.
However, the double variable type can hold more numbers than float. (Double is a 64 bit number and float is only 32 bit.)

REFERENCE

 

---

Java Basics 102 - Double Variables


---
Java Basics 102 – Double Variables

STEPS

1) Browse http://ideone.com/1gau2Z 

 

2) Change the variables properties to Double Data Types.

Change line no.13 to:
double first_number, second_number, answer;
Change line no.14, 15 to:
first_number = 10.5;
second_number = 20.8;
Outcome:

REFERENCE

 

---

Java Basics 101- Java Variables

---

ATTENTION!

An updated version of this article is available at http://javadevsteps.blogspot.com/2014/08/ideone-java-basics-101-getting-started.html


---
Java Basics 101 – Variables

STEPS

1) Browse  http://ideone.com/VOBd7C 

IdeOne.com is an Online Compiler that allows Java Code to be written and compiled online.
We would be able to learn a lot from here without even have to install Java Development Kit to our PC.

2) Understanding Java Code Structure

2-1) Package Name
2-2) Import Declarations
2-3) Class Declaration
2-4) Method Declaration
2-5) User Instructions

3) Basic Instructions – Variable Declaration and Print Statement

As a quick start, ignore Package Name, Import Declarations and Class Declarations first.
Let’s look at basic program instructions first (Line no. 12).
Replace line No.12 with the following codes:

int first_number;
System.out.println("My First Project");
Outcome:
Lesson:
- Variable is identified by its name and data type.
- Printing statement returns value to user. (in the above example it is a string)

4) Variable Assignment



public static void
 main(String[ ] args) {
int first_number;
first_number = 10;
System.out.println("My First Project");
}
Outcome:
Lessons:
- Variable can store value; a process called assignment gives a value for variable to store.

5) Print Variable Value

Change line no. 15 to the following:

System.out.println( "First number = " + first_number );
Outcome:
Lessons:
- We can combine string with variable.
- We join string and variable with join operator “+”; a process called Concatenation.

6) Variables and Data Operation

Change line no. 13 to the following:

int first_number, second_number, answer;
Change line no. 14 to the following:

first_number = 10;
second_number = 20;
answer = first_number + second_number;
Change line no.15 to the following

System.out.println("Addition Total = " + answer );
Outcome:
Lessons:
- You can declare many variables of the same daya type in a single statement.
- Number operation is similar to that of Mathematics.
---
Moderated from: http://www.homeandlearn.co.uk/java/java_int_variables.html
---

Tuesday, July 1, 2014

JAVA SE INSTALL NETBEANS IDE 7-3

---
JAVA SE: INSTALL NETBEANS IDE 7.3

STEPS

1) Install Java SDK

e.g jdk-7u25-windows-i586.exe
Check that java has been installed correctly by typing “java –version” in Command Window.

2) Download NetBeans 7.3

e.g. Download netbeans-7.3-javase-windows.exe

3) Install NetBeans 7.3)

3-1) Run the installer netbeans-7.3-javase-windows.exe
3-2) Welcome Screen.
3-3) Accept the terms.
3-4) Option to install JUnit.
3-5) Choose installation folder.
3-6) Option to check for update.
3-7) Wait for installation process to complete.
3-8) Installation done.

4) Running NetBeans for the first time.

4-1) Double-click the NetBeans IDE icon on the desktop.
4-2) NetBeans Main Application window appears on screen.
---

---