Java JDK and Intro
Java JDK and Intro
Java JDK and Intro
https://www.oracle.com/br/java/technologies/javase-downloads.html
Follow the steps(MAC or Windows) to install your java JDK.
Java is a programming language.
Java Tutorial Java is used to develop mobile apps, web apps,
desktop apps, games and much more.
Java Quickstart
In Java, every application begins with a class name, and that class must match the filename.
Let's create our first Java file, called P1_Hello.java, which can be done in any text editor (like
Notepad).
The file should contain a "Hello World" message, which is written with the following code:
Note: Java is
case-
sensitive:
"MyClass"
and
"myclass"
has different
meaning.
Java Identifiers
All Java variables must be identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive names (age, sum,
totalVolume).
Note: It is recommended to use descriptive names in order to create understandable
and maintainable code:
Integer Types
Byte
The byte data type can store whole numbers from -128 to 127. This can be used instead of int or other integer
types to save memory when you are certain that the value will be within -128 and 127:
Example
byte myNum = 100;
System.out.println(myNum);
Short
The short data type can store whole numbers from -32768 to 32767:
Example
short myNum = 5000;
System.out.println(myNum);
Int
The int data type can store whole numbers from -2147483648 to 2147483647. In general, and in our
tutorial, the int data type is the preferred data type when we create variables with a numeric value.
Example
int myNum = 100000;
System.out.println(myNum);
Long
The long data type can store whole numbers from -9223372036854775808 to
9223372036854775807. This is used when int is not large enough to store the value. Note that
you should end the value with an "L":
Example
long myNum = 15000000000L;
System.out.println(myNum);
Float
The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you
should end the value with an "f":
Example
float myNum = 5.75f;
System.out.println(myNum);
The double data type can store fractional numbers from 1.7e−308 to 1.7e+308. Note
that you should end the value with a "d":
Example
double myNum = 19.99d;
System.out.println(myNum);
Booleans
A boolean data type is declared with the boolean keyword and can
only take the values true or false:
Example
boolean isJavaFun = true;
boolean isFishTasty = false;
System.out.println(isJavaFun); // Outputs true
System.out.println(isFishTasty); // Outputs false
Use the else statement to specify a block of code to be executed if the condition is false.
The else if Statement
Use the else if statement to specify a new condition if the first condition is false.
Java Switch Statements
Use the switch statement to select one of many code blocks to be executed.
Loops
Loops can execute a block of code as long as a specified condition is reached.
Loops are handy because they save time, reduce errors, and they make code more readable.
} }
End