Java Tutorial: System Requirements
Java Tutorial: System Requirements
System Requirements
Install the following:
1. DOWNLOAD JAVA SE DEVELOPMENT A INSTALL JAVA JRE
2. SELECT AN IDE
For Eclipse user, if error Unbound classpath container appeared
after creating the Project, pls configure the project properties:
Right click on the project
Open Properties
Select Java Build Path
Select the JRE System Library under the Libraries tab.
Click on Edit.
Click on Alternate JRE.
If Alternate JRE present, then Select it and hit Finish.
If not present, then click on Installed JREs which opens a
pop up.
Click on Add.
Select Standard VM and Click Next.
Select the JRE Home, navigate to JDK root and select that.
Click on Finish.
Select that in installed JREs.
Hello World
To start with, right click on the created project, then hover to
New, select Class. Name the class with a unique name, and then
check the method “public static void main (String[] args)”, then
hit Finish.
public class Main //this is the "main" class
{
{
System.out.println("Hello World");
System.out.println("Good Morning Philippines!");
}
}
RESULT:
The same “println” result may obtain also by adding “\n” at the
end of the string statement, like this:
System.out.print("Hello World\n");
System.out.print("Good Morning Philippines!");
RESULT:
System.out.println("Hello World\n");
System.out.println("Good Morning Philippines!");
RESULT:
Tab
To put a tab before the string result, we can add “\t” before the
string, like this:
System.out.println("\tHello World");
System.out.println("Good Morning Philippines!");
RESULT:
Quotation Mark
To add quotation mark in an output, we can place “\ before and
after the sentence, like this:
System.out.println("\t \"Hello World\"");
System.out.println("Good Morning Philippines!");
RESULT:
Adding Backslash
To add a backslash (\) into the string result, you can just add
two backslashes (\\) before the strings, like this:
System.out.println("\\ Hello World");
RESULT:
Adding Comments
Comments are characters or statements that could be ignored by
the compiler. This is in case you want to put something in the
program that you don’t want the compiler to display on the
console, like this:
System.out.println("\\ Hello World");
// This is a comment
RESULT:
You will notice that the compiler ignored the comment line and
didn’t display it on the console. This will happen if we added
two backslashes (\\) in a new or empty space in the program.
However, if we want to have a multiple comments, we can use
forward slash and asterisk (/*), like this:
{
System.out.println("\\ Hello World");
/* Pls do not
* make any
* changes in this program
*/
}
RESULT:
Variables
Variables are being described by its data type. There are at
least 9 primitive data types that can be used in Java.
Boolean = true /false
Byte = -128 to 127
Short = 32,768 - 32,767
Int = -2 billion to 2 billion
Long = -9 quintillion to 9 quintillion
Float = fractional number up to 6-7 digits ex. 3.141592f
Double = fractional number up 15 digits ex. 3.141592653589793
Char = single characted/letter/ASCII value
ex. 'f'
String = a sequence of characters ex. "Hello World"
int age;
int sum;
sum = 167 + 18;
age = 19;
float x = 12.15f;
double z = 12.15;
char sign = '&';
boolean z1 = false;
Result:
My name is Jerome Macarilao I am 19 years old.
204
12.15
12.15
&
False
Scanner
Scanner is a command that allows us to input a data and interact
with the program, just like the cin in C++. Before we use this
command, we have to include the following line into our package:
import java.util.Scanner;
Example:
import java.util.Scanner;