1_Java Introduction
1_Java Introduction
Instructor: DieuNT1
Introduction to Java
01. 04. Java Data Types
Introduction to Java
• A complete java development kit that includes JRE (Java Runtime Environment),
compilers and various tools like JavaDoc, Java debugger etc.
• In order to create, compile and run Java program you would need JDK installed
on your computer.
Primary
Memory
Phase 4 Bytecode Verifier Bytecode verifier confirms that
all bytecodes are valid and do
not violate[vi phạm] Java’s security
restrictions[giới hạn].
. ..
. .
.
Primary
Memory Interpreter reads bytecodes
Phase 5 Interpreter and translates them into a
language that the computer
can understand, possibly
storing data values as the
program executes.
. ..
. .
.
The java compiler creates a file called 'First.class' that contains the byte codes
To actually run the program, a java interpreter called java is required to execute the code.
// Single line
/**
* Special comment for Javadocs
*/
* not used
** added in 1.2
*** added in 1.4
**** added in 5.0
true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.
09e-BM/DT/FSOFT - @FPT SOFTWARE - FPT Software Academy - Internal Use 25
Standard Java Output
▪ System.out is standard out in Java
▪ System.err is error out in Java
▪ Ex:
public class Output {
public static void main(String[] args) {
System.out.print("Print, no new line!");
System.out.println("Print, add platforms new line at end.");
System.out.flush();
System.err.println("Standard error output");
}
}
• The short data type is a 16-bit signed two's complement integer. It has a minimum value of -
short 32,768 and a maximum value of 32,767 (inclusive)
• The int data type is a 32-bit signed two's complement integer. It has a minimum value of -
Int 2,147,483,648 and a maximum value of 2,147,483,647 (inclusive).
• The long data type is a 64-bit signed two's complement integer. It has a minimum value of -
Long 9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive)
• The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of
double values is from 1.7E-324 to 1.7976931348623157E308
• The boolean data type has only two possible values: true and false. Use this data type for
simple flags that track true/false conditions. This data type represents one bit of information,
boolean but its "size" isn't something that's precisely defined.
• The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000'
char (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
Operators
Output:
number1 + number2 = 16.0
Output:
+number = 5.2
-number = -5.2
number = 6.2
number = 5.2
!flag = true
"Leap year";
System.out.println(result);
}
}
Leap year
true false
Output:
+number = 5.2
-number = -5.2
number = 6.2
number = 5.2
!flag = true
• char->int
• byte->short->int->long->float->double
✔ Data type
✔ Name
▪ Syntax
datatype identifier [=value][, identifier[=value]...];
▪ Example:
int foo = 42;
double d1 = 3.14, d2 = 2 * 3.14;
boolean isFun = true;
▪ Syntax
static final datatype CONSTNAME = value;
▪ Example:
1 ▪ block.
The block begins with an opening curly brace and ends with a closing curly brace.
▪ A block defines a scope.
▪ A new scope is created every time a new block is created.
02
Scope specifies what objects are visible to other parts
of the program.