UNIT I Java Basics
UNIT I Java Basics
Encapsulation Polymorphism
Wrapping up of ability to assume
Abstraction data (variables) Inheritance several different
and methods forms
into single unit Acquiring the
essential properties from one
features without class to another
its inner details class or producing
or hiding new class from
internal already existing class
implementation
State
Address
Color
Area
Behaviour
Open door
Close door
Water Fill
Platform Independent
Secure
Portable Interpreted
Robust Distributed
Multi-threaded Dynamic
Architectural Neutral
MLR INSTITUTE OF TECHNOLOGY
31-Oct-23
18
18
Simple
✓ Java is a small and simple language.
✓ Java does not use pointers, pre-processor header
files, goto statement and many other.
✓ It also eliminates operator overloading and
multiple inheritance.
✓ Java inherits the C/C++ syntax and many of the
object oriented features of C++.
Loads
Code
Verifies
Code Execute
Code
Provides Run
Time
Environment
Variables Types
Local
Instance
Static
Collection of
Elements
1 2 3 4 5 6 Integer
A B C D E F String
Create array of
strings
new
✓ Type[] arrayName;
✓ Data type can be primitive types like int,
char, float,..(or) class type.
✓ Array name can be any valid identifier.
✓ Ex: int a[];
✓ String s[];
✓ Student student[];
Create an array
without specifying
any name
0 1 2 3 4 5
A B C D E F
Output: MG
a) 3 and 5 b) 5 and 3
c) 2 and 4 d) 4 and 2
Syntax:
for(type variable : arrayname)
{
….
}
If Statement
if
If-else
If-else-if Nested if
if(condition)
{
//code to be executed if true
}
else
{
//code to be executed if false
}
JAVA Looping
for
while
Do while foreach
✓ PHP for loop can be used to traverse set of code for the
specified number of times.
for(initialization; condition; increment/decrement)
{
//code to be executed
}
StringBuffer Methods
append reverse
insert delete
replace
Type Casting
Narrowing
Widening
MLR INSTITUTE OF TECHNOLOGY
31-Oct-23
128
128
Widening Type Casting
✓ Converting a lower data type into a higher one is
called widening type casting.
✓ It is also known as implicit conversion or casting
down.
✓ byte -> short -> char -> int -> long -> float -
> double
Example:
class Hacker{
Hacker(){ } Constructor
}
How it
works? Object
Constructor
Default
Parameterized
Example: Example: