SlideShare a Scribd company logo
Java Tokens: Keywords, Identifiers, Literals, Operators, and Seperators
A smallest individual unit in source code is known as Token
Java Tokens
Keywords Identifiers Literals Operators Seperators
Keywords are special tokens in the language which have reserved use in the language.
Keywords may not be used as identifiers in Java — you cannot declare a field whose name is a
keyword, for instance.
Java has 50 keywords among which 48 are in use but 2 (goto and const) are currently not in use
Here is a list of keywords in the Java programming language. You cannot use any of the
following as identifiers in your programs. The keywords const and goto are reserved, even
though they are not currently used. true, false, and null might seem like keywords, but they are
actually literals; you cannot use them as identifiers in your programs.
abstract continue for new switch
assert*** default goto* package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while
* not used
** added in
1.2
*** added in
1.4
**** added in
5.0
Identifiers are the names of variables, methods, classes, packages and interfaces.
• Don’t use a keyword
• Don’t use a space
• Don’t use a special symbol other than ( _ and $ )
• Cannot start with digit
• Any length
• If only a single word then use a lowercase
• If more than one word then start first word with lowercase and other words start with first
letter as Capital
For example:
int balance=500; //Single word
int bankBalance=500; //Multiple Words
• Use lowercase
For example:
package pack1;
package mypack1;
• Every word start with first letter as Capital
For example:
class Balance{}
class BankBalance{}
• Use Uppercase and Underscore for separating the words
For example:
int PI=3.14;
int MAX_VALUE=100;
Fixed value assigned to variables or used in expressions is known as Literals
• Integer Literals: for example: 1, -2, 8523, -2105 etc.
Data Type Size Range
byte 1 Byte -27 to 27 -1
short 2 Bytes -215 to 215 -1
int 4 Bytes -231 to 231 -1
long 8 Bytes -263 to 263 -1
• Floating Literals: for example: 1.02, -2.689, 8523.369, 2105 etc.
Data Type Size Range
float 4 Byte -3.4 * 1038 to 3.4 * 1038
double 8 Bytes -1.7 * 10308 to 1.7 * 10308
• Character Literals: for example: ‘A’, ‘B’, ‘@’, ‘&’ etc.
Data Type Size Range
char 2 Bytes All Unicode characters
• String Literals: for example: “Hello”, “Gurpreet Singh”, “ACET” etc.
Data Type Size Range
String 2 * No. of characters As much memory available
• Boolean Literals: true and false.
Data Type Size Range
boolean 1 Byte true or false
• Null Literals: null can be assigned to any reference type
Operators operates on operands. For example: In expression a+b , a & b are operands and +
is operator
• Arithmetic Operator: +, - , *, /, %. For example:
5+4 will result in 9 5-4 will result in 1 5*4 will result in 20 5/4 will result in 1
5%4 will result in 1 (remainder) -5%4 will result in -1 5%-4 will result in 1 -5%-4 will result in -1
Note: Sign of result in % operator depends on the sign of dividend(numerator)
• Relational Operator: <, >, <=, >=, ==, != Output will be either true or false
5>6 will result in false
5>=6 will result in false (either greater than or equal to)
5<6 will result in true
5<=6 will result in true (either less than or equal to)
5==6 will result in false (equal to)
5!=6 will result in true (not equal to)
• Assignment Operator: = Assign the value on left hand side to right hand side. For example:
A=10+5, will assign 15 to A
• Logical Operator: returns true or false
Logical AND (&&)
Logical OR (||)
Logical NOT (!)
A B A&&B A||B !A
true true true true false
true false false true false
false true false true true
false false false false true
• Increment/Decrement Operator: increases or decreases the value by 1
Pre-increment & Pre-decrement: ++a, --a
Post-increment & Post-decrement: a++, a--
• Bitwise Operator: Performs operations on bits
Bitwise AND(&)
Bitwise OR(|)
Bitwise XOR(^)
Bitwise Complement or Not (!)
A B A&B A|B A^B !A
0 0 0 0 1 1
0 1 0 1 0 1
1 0 0 1 0 0
1 1 1 1 1 0
• Shift Operator: shift the bits to left or right
Left Shift(<<): shifts the bits to left and fill the vacant spaces with 0
Unsigned Right Shift(>>>): shifts the bits to right and fill the vacant spaces with 0
Signed Right Shift(>>): shifts the bits to right and fill the vacant spaces with leftmost bit, i.e. if
leftmost bit is 0 then fill with 0, and if the leftmost bit is 1 then fill with 1
• Conditional(Ternary) Operator:
Syntax: condition(relational expression) ? Expression 1 : Expression 2
If condition evaluates to true then result will be Expression 1 otherwise Expression 2
{ } used to define block or to declare array with static elements
[ ] used to declare array variable
( ) used to define/call function or used in expressions
; used to terminate a statement
, used to separate variables in declaration
. used to access data members and member functions of an object or class

More Related Content

PPT
Java Basics
PPSX
Java Tutorial
PPT
Java Tutorial | My Heart
PPTX
Introduction to java Programming
PPT
Presentation to java
PPT
Java basic tutorial by sanjeevini india
PDF
Java Programming
Java Basics
Java Tutorial
Java Tutorial | My Heart
Introduction to java Programming
Presentation to java
Java basic tutorial by sanjeevini india
Java Programming

What's hot (19)

PPT
Java tutorial PPT
PPT
Java Tutorial
PPTX
Core Java Tutorials by Mahika Tutorials
PPT
PPT
Java Tut1
PPT
Javatut1
PPT
Java Basics
PPT
Core java
PPT
Java tut1
PPT
Tutorial java
PPTX
Java Notes
PPT
Introduction to-programming
PPTX
Core java complete ppt(note)
PPT
Java Tutorial
PPTX
Introduction to Java programming - Java tutorial for beginners to teach Java ...
PPT
Unit I Advanced Java Programming Course
PPT
Ch01 basic-java-programs
PPTX
Core java
Java tutorial PPT
Java Tutorial
Core Java Tutorials by Mahika Tutorials
Java Tut1
Javatut1
Java Basics
Core java
Java tut1
Tutorial java
Java Notes
Introduction to-programming
Core java complete ppt(note)
Java Tutorial
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Unit I Advanced Java Programming Course
Ch01 basic-java-programs
Core java
Ad

Viewers also liked (11)

PPTX
Block diagram by vasant
PPT
Computer Structure Slides
PPT
Block diagram of computer 02
PPT
Chapter 1 computer hardware and flow of information
PPSX
08. Central Processing Unit (CPU)
PPT
Fundamentals Of Computer
PPTX
Computer hardware presentation
PPTX
Block diagram of a computer
PPT
Block diagram of a computer
PPT
Computer hardware component. ppt
PPT
basics of computer system ppt
Block diagram by vasant
Computer Structure Slides
Block diagram of computer 02
Chapter 1 computer hardware and flow of information
08. Central Processing Unit (CPU)
Fundamentals Of Computer
Computer hardware presentation
Block diagram of a computer
Block diagram of a computer
Computer hardware component. ppt
basics of computer system ppt
Ad

Similar to Java ppt2 (20)

PPTX
unit1 python.pptx
PPTX
Grade XI - Computer science Data Handling in Python
PPTX
IOS Swift Language 3rd tutorial
PPTX
python_computer engineering_semester_computer_language.pptx
PPTX
C Session 2.pptx for engninering students
PPTX
python presentation.pptx
PPTX
L3 operators
PPTX
L3 operators
PPTX
L3 operators
PPTX
Operators in Python Arithmetic Operators
PPTX
POLITEKNIK MALAYSIA
PPT
Py-Slides-2 (1).ppt
PPT
Py-Slides-2.ppt
PPT
Py-Slides-2.ppt
PPT
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PPTX
Lecture 2 variables
PPTX
Lecture 1 .
PPTX
Operators and expressions in C++
PDF
Python - Lecture 2
unit1 python.pptx
Grade XI - Computer science Data Handling in Python
IOS Swift Language 3rd tutorial
python_computer engineering_semester_computer_language.pptx
C Session 2.pptx for engninering students
python presentation.pptx
L3 operators
L3 operators
L3 operators
Operators in Python Arithmetic Operators
POLITEKNIK MALAYSIA
Py-Slides-2 (1).ppt
Py-Slides-2.ppt
Py-Slides-2.ppt
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
Lecture 2 variables
Lecture 1 .
Operators and expressions in C++
Python - Lecture 2

More from nikhilsh66131 (8)

PDF
PDF
PDF
PDF
Introduction to css
PDF
Html beginners tutorial
PPT
Bubble and-merge-sort
PDF
Java ppt2
PDF
Java ppt1
Introduction to css
Html beginners tutorial
Bubble and-merge-sort
Java ppt2
Java ppt1

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Cell Types and Its function , kingdom of life
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Updated Idioms and Phrasal Verbs in English subject
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
master seminar digital applications in india
PDF
Microbial disease of the cardiovascular and lymphatic systems
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Weekly quiz Compilation Jan -July 25.pdf
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Supply Chain Operations Speaking Notes -ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Final Presentation General Medicine 03-08-2024.pptx
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Microbial diseases, their pathogenesis and prophylaxis
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Cell Types and Its function , kingdom of life
History, Philosophy and sociology of education (1).pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Updated Idioms and Phrasal Verbs in English subject
2.FourierTransform-ShortQuestionswithAnswers.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
master seminar digital applications in india
Microbial disease of the cardiovascular and lymphatic systems

Java ppt2

  • 1. Java Tokens: Keywords, Identifiers, Literals, Operators, and Seperators
  • 2. A smallest individual unit in source code is known as Token Java Tokens Keywords Identifiers Literals Operators Seperators
  • 3. Keywords are special tokens in the language which have reserved use in the language. Keywords may not be used as identifiers in Java — you cannot declare a field whose name is a keyword, for instance. Java has 50 keywords among which 48 are in use but 2 (goto and const) are currently not in use Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs. abstract continue for new switch assert*** default goto* package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum**** instanceof return transient catch extends int short try char final interface static void class finally long strictfp** volatile const* float native super while * not used ** added in 1.2 *** added in 1.4 **** added in 5.0
  • 4. Identifiers are the names of variables, methods, classes, packages and interfaces. • Don’t use a keyword • Don’t use a space • Don’t use a special symbol other than ( _ and $ ) • Cannot start with digit • Any length • If only a single word then use a lowercase • If more than one word then start first word with lowercase and other words start with first letter as Capital For example: int balance=500; //Single word int bankBalance=500; //Multiple Words
  • 5. • Use lowercase For example: package pack1; package mypack1; • Every word start with first letter as Capital For example: class Balance{} class BankBalance{} • Use Uppercase and Underscore for separating the words For example: int PI=3.14; int MAX_VALUE=100;
  • 6. Fixed value assigned to variables or used in expressions is known as Literals • Integer Literals: for example: 1, -2, 8523, -2105 etc. Data Type Size Range byte 1 Byte -27 to 27 -1 short 2 Bytes -215 to 215 -1 int 4 Bytes -231 to 231 -1 long 8 Bytes -263 to 263 -1 • Floating Literals: for example: 1.02, -2.689, 8523.369, 2105 etc. Data Type Size Range float 4 Byte -3.4 * 1038 to 3.4 * 1038 double 8 Bytes -1.7 * 10308 to 1.7 * 10308
  • 7. • Character Literals: for example: ‘A’, ‘B’, ‘@’, ‘&’ etc. Data Type Size Range char 2 Bytes All Unicode characters • String Literals: for example: “Hello”, “Gurpreet Singh”, “ACET” etc. Data Type Size Range String 2 * No. of characters As much memory available • Boolean Literals: true and false. Data Type Size Range boolean 1 Byte true or false • Null Literals: null can be assigned to any reference type
  • 8. Operators operates on operands. For example: In expression a+b , a & b are operands and + is operator • Arithmetic Operator: +, - , *, /, %. For example: 5+4 will result in 9 5-4 will result in 1 5*4 will result in 20 5/4 will result in 1 5%4 will result in 1 (remainder) -5%4 will result in -1 5%-4 will result in 1 -5%-4 will result in -1 Note: Sign of result in % operator depends on the sign of dividend(numerator) • Relational Operator: <, >, <=, >=, ==, != Output will be either true or false 5>6 will result in false 5>=6 will result in false (either greater than or equal to) 5<6 will result in true 5<=6 will result in true (either less than or equal to) 5==6 will result in false (equal to) 5!=6 will result in true (not equal to)
  • 9. • Assignment Operator: = Assign the value on left hand side to right hand side. For example: A=10+5, will assign 15 to A • Logical Operator: returns true or false Logical AND (&&) Logical OR (||) Logical NOT (!) A B A&&B A||B !A true true true true false true false false true false false true false true true false false false false true • Increment/Decrement Operator: increases or decreases the value by 1 Pre-increment & Pre-decrement: ++a, --a Post-increment & Post-decrement: a++, a--
  • 10. • Bitwise Operator: Performs operations on bits Bitwise AND(&) Bitwise OR(|) Bitwise XOR(^) Bitwise Complement or Not (!) A B A&B A|B A^B !A 0 0 0 0 1 1 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 1 1 0 • Shift Operator: shift the bits to left or right Left Shift(<<): shifts the bits to left and fill the vacant spaces with 0 Unsigned Right Shift(>>>): shifts the bits to right and fill the vacant spaces with 0 Signed Right Shift(>>): shifts the bits to right and fill the vacant spaces with leftmost bit, i.e. if leftmost bit is 0 then fill with 0, and if the leftmost bit is 1 then fill with 1 • Conditional(Ternary) Operator: Syntax: condition(relational expression) ? Expression 1 : Expression 2 If condition evaluates to true then result will be Expression 1 otherwise Expression 2
  • 11. { } used to define block or to declare array with static elements [ ] used to declare array variable ( ) used to define/call function or used in expressions ; used to terminate a statement , used to separate variables in declaration . used to access data members and member functions of an object or class