Unit-2 an Overview of Java
Unit-2 an Overview of Java
Java
Unit-2
Topics Covered
● Object-Oriented Programming
○ Two Paradigms
○ Abstraction
○ The Three OOP Principles
● Lexical Issues
○ Whitespace
○ Identifiers
○ Literals
○ Comments
○ Separators
○ The Java Keywords
Object Oriented Programming
Object Oriented programming (OOP) is a programming paradigm that relies
on the concept of classes and objects.
● Imperative
● Logical
● Functional
● Object-Oriented
Two Paradigms
All programs consist of two elements, namely code and data
● Object is a real world entity that have properties like car, dog, pen table etc.
● Whitespace
● Identifiers
● Literals
● Comments
● Operators
● Separators
● keywords
WhiteSpace
● Java is a free-form language
● For example, the program can be written all on one line or in any other
strange way you felt like typing it
● In Java, whitespace is a space, tab, or newline
Identifiers
A name in java program
It can be the method name, variable name, class name or label name.
Rules for defining java Identifier
● The only allowed characters in java identifiers are
○ a to z
○ A to Z
○ 0 to 9
○ $
○ _
● Note: If we use any other character, we will get compile time error.
Example:
total_number is valid.
total# is invalid.
Identifier can’t start with number/digits.
Example:
total123 is valid
123total is invalid
Identifier are case sensitive.
Example:
Class Test {
}
There is no limit to length for identifiers
Example:
All predefined java class names and interface name can be used as identifiers.
Example:
1. total_number
2. total#
3. 123total
4. total123
5. ca$h
6. _$_$_$_$_$_$_
7. all@hands
8. java2share
9. Integer
10.Int
11.int
Literals
A constant value which can be assigned to a variable is called a literal
A constant value in Java is created by using a literal representation of it. For example,
here
are some literals:
100 98.6 ‘X’ “This is a test”
Left to right, the first literal specifies an integer, the next is a floating-point value, the
third
Is a character constant, and the last is a string. (integer literal, floating point literal,
character
literal and string literal )
A literal can be used anywhere a value of its type is allowed.
Comments
There are three types of comments defined by Java.
They are:
● Single-line Comment: //
● Multiline Comment : /*……..*/
● Documentation Comment /**………….*/
The documentation comment begins with a /** and ends with a */.
Separator
A separator is a symbol that is used to separate a group of code from one
another is called as separators in java.