1 Java Introduction
1 Java Introduction
Java Introduction
History of Java
Features of Java Programming
Java Hello World
Setting up the environment in Java
Java JVM, JRE and JDK
Java Data Types
Java Operators
Java Input and Output
Java Expressions & Blocks
Java Comment
1/5/2022 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 2
History of Java
1995 1998 2000 2002 2004 2006 2011 2014 2017 2018 2018 2019
Simple
Object-
Dynamic
Oriented
Architecture
Secured
neutral
Features
Robust
of Java Platform
independent
High
Distributed
Performance
Multithreaded
1. Install the JDK if you don't have installed it, download the JDK and install it.
2. Set path of the jdk/bin directory.
3. Install IntelliJ IDEA Community Edition, download and install it.
4. Create the java program
5. Compile and run the java program
Notes
The compiler executes
the codes starting from
the main function
There are few things which must be clear before setting up the
environment
JVM: JVM
(Java
Virtual
Machine)
JRE(Java
Runtime
Environm
ent)
JDK(Java
Development
Kit)
Step 4) Now, you have to alter the “Path” variable under System variables
so that it also contains the path to the Java environment. Select the “Path”
variable and click on Edit button as highlighted below.
Step 6) Click on OK, Save the settings and you are done !! Now to check
whether installation is done correctly, open command prompt and type javac
-version. You will see that java is running on your machine.
Java Variables
A variable is a location in memory (storage area) to hold data.
To indicate the storage area, each variable should be given a unique name
(identifier).
How to declare variables in Java?
Instance Variables
(Non-Static Fields)
Class Variables
Parameters
(Static Fields)
Local Variables
Boolean
Char Byte
Java
Float
Primitive Short
Data
Types
Double Int
Long
boolean
The boolean data type has two possible values, either true or false.
Default value: false.
They are usually used for true/false conditions.
byte
The byte data type can have values from -128 to 127 (8-bit signed two's
complement integer).
It's used instead of int or other integer data types to save memory if it's
certain that the value of a variable will be within [-128, 127].
Default value: 0
short
The short data type can have values from -32768 to 32767 (16-bit signed
two's complement integer).
It's used instead of other integer data types to save memory if it's certain
that the value of the variable will be within [-32768, 32767].
Default value: 0
int
The int data type can have values from -231 to 231-1 (32-bit signed two's
complement integer).
If you are using Java 8 or later, you can use unsigned 32-bit integer with
a minimum value of 0 and a maximum value of 232-1.
Default value: 0
long
The long data type can have values from -263 to 263-1 (64-bit signed
two's complement integer).
If you are using Java 8 or later, you can use unsigned 64-bit integer with
a minimum value of 0 and a maximum value of 264-1.
Default value: 0
double
The double data type is a double-precision 64-bit floating-point.
It should never be used for precise values such as currency.
Default value: 0.0 (0.0d)
float
The float data type is a single-precision 32-bit floating-point.
It should never be used for precise values such as currency.
Default value: 0.0 (0.0f)
char
It's a 16-bit Unicode character.
The minimum value of the char data type is '\u0000' (0). The maximum
value of the char data type is '\uffff'.
Default value: '\u0000'
Assignment Operator
Assignment operators are used in Java to assign values to variables. For
example,
The assignment operator assigns the value on its right to the variable on its
left. Here, 5 is assigned to the variable age using = operator.
Assignment Operator
Arithmetic Operators
Arithmetic operators are used to perform mathematical operations like
addition, subtraction, multiplication, etc.
Operator Meaning
+ Addition (also used for string concatenation)
- Subtraction Operator
* Multiplication Operator
/ Division Operator
% Remainder Operator
Arithmetic Operators
Arithmetic Operators
Unary Operators
The unary operator performs operations on only one operand.
Operator Meaning
+ Unary plus (not necessary to use since numbers are
positive without using it)
- Unary minus: inverts the sign of an expression
++ Increment operator: increments value by 1
-- decrement operator: decrements value by 1
! Logical complement operator: inverts the value of a
boolean
1/5/2022 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 40
Java Operators
Unary Operators
Unary Operators
You can also use ++ and -- operator as both prefix and postfix in Java.
The ++ operator increases value by 1 and -- operator decreases the value
by 1.
int myInt = 5;
++myInt // myInt becomes 6
myInt++ // myInt becomes 7
--myInt // myInt becomes 6
myInt-- // myInt becomes 5
instanceof Operator
In addition to relational operators, there is also a type comparison operator
instanceof which compares an object to a specified type.
Logical Operators
The logical operators || (conditional-OR) and && (conditional-AND) operate
on boolean expressions.
Logical Operators
Ternary Operator
The conditional operator or ternary operator ?: is shorthand for the if-then-else
statement. The syntax of the conditional operator is:
Ternary Operator
Java Output
System.out.println(); or
System.out.print(); or
System.out.printf();
Java Input
Java Input
Java Input
Java Expressions
A Java expression consists of variables, operators, literals, and method
calls.
Java Statements
In Java, each statement is a complete unit of execution.
Java Statements
In Java, each statement is a complete unit of execution.
Expression statements
We can convert an expression into a statement by terminating the
expression with a ;
// expression
number = 10
// statement
number = 10;
Java Blocks
A block is a group of statements (zero or more) that is enclosed in curly
braces { }
Java Blocks
However, a block may not have any statements.
class Main {
public static void main(String[] args) {
} // end of block
}
}
single-
multi-line
line
A single-line comment starts and ends in the same line. To write a single-
line comment, we can use the // symbol.
When we want to write comments in multiple lines, we can use the multi-
line comment. To write multi-line comments, we can use the /*....*/ symbol.
1/5/2022 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 63
Java Comment