Datatyped and Operators
Datatyped and Operators
Java Versions
Simple Program
Comments
Identifiers
Data types
Variables
Operators
JAVA Versions Till now
• JDK Alpha and Beta (1995) • Java SE 8 (18th March, 2014)
• JDK 1.0 (23rd Jan, 1996) • Java SE 9(September 2017)
• JDK 1.1 (19th Feb, 1997) • Java SE 10 (March 2018)
• J2SE 1.2 (8th Dec, 1998) • Java SE 11 (September 2018)
• J2SE 1.3 (8th May, 2000) • Java SE 12 (March 2019)
• J2SE 1.4 (6th Feb, 2002) • Java SE 13 ( September 2019)
• J2SE 5.0 (30th Sep, 2004) • Java SE 14 ( March 2020)
• Java SE 6 (11th Dec, 2006) • Java SE 15 ( September 2020)
• Java SE 7 (28th July, 2011) • Java SE 16 (March 2021)
A First Simple Program
To Compile:
To Run:
Comments
Comments can be used to explain Java code, and
to make it more readable.
1. Single-line comments start with two forward
slashes (//).
2. Multi-line comments start with /* and ends
with */
3. Documentation Comment: To create Java
API(Application Programming Interface)
document. Start with /** end with */
Identifiers
Identifiers are used to name things, such as classes, variables,
and methods. An identifier may be any descriptive sequence
of uppercase and lowercase letters, numbers, or the
underscore.
• Java is case-sensitive, so VALUE is a different identifier than
Value. Some examples of valid identifiers are
class A{
int data=50;//instance variable
static int m=100;//static variable
void method(){
int n=90;//local variable
}
}//end of class
Scope and Life Time of Variables
• The scope of a variable defines the section of
the code in which the variable is visible.
• The lifetime of a variable refers to how long the
variable exists before it is destroyed.
Instance variables
The scope of instance variables is determined by
the access specifier that is applied to these variable.
The lifetime of these variables is the same as the
lifetime of the object to which it belongs
Argument variables
The scope of these variables is the method or
constructor in which they are defined.
The lifetime is limited to the time for which the
method keeps executing. Once the method finishes
execution, these variables are destroyed.
Local variables
The scope and lifetime are limited to the method itself.
Operators
An operator is a symbol that performs an
operation. An operator acts on variables called
operands.
a+b
here a, b are Operands
+ is Operator
Arithmetic operators: These operators are used to perform
fundamental operations like addition, subtraction, multiplication
etc
Operator Meaning Example Result
+ Addition 3+4 7
- Subtraction 5-7 -2
* Multiplication 5*5 25
!= Not equal x != 3
>> Right shift specified number of positions and also preserves the
sign bit
Shifts the bits of the number towards right a
>>> Zero fill right shift specified number of positions and it stores 0 (Zero)
in the sign bit
Gives the complement form of a given number by
~ Bitwise complement
changing 0‟s as 1‟s and vice versa
Ternary Operator or Conditional Operator (? :)
This operator is called ternary because it acts on
3 variables The syntax for this operator is:
• Variable = Expression1? Expression2: Expression3;
• First Expression1 is evaluated If it is true, then
Expression2 value is stored into variable
otherwise Expression3 value is stored into the
variable
• eg: max = (a>b) ? a: b;