OOP Using Java Unit 1
OOP Using Java Unit 1
OOP Using Java Unit 1
UNIT : I
PREPARED BY : P LAKSHMI
CONCEPTS:
• Introduction to Object Oriented Programming
• The History and Evolution of Java
• Introduction to Classes
• Objects, Methods
• Constructors, this keyword, Garbage Collection
• Data Types, Variables,
• Type Conversion and Casting , Arrays
• Operators, Control Statements,
• Method Overloading, Constructor Overloading
• Parameter Passing, Recursion,
• String Class and String handling methods.
Programming
Spoken
Languages
Languages
Java bytecode is the instruction set for the Java Virtual Machine.
Java byte code is the combination of object code and assembly code .
When we write a program in Java, firstly, the compiler compiles that program and a
bytecode (class file) is generated for that piece of code.
When we wish to run this .class file is executed by JVM and generate matching
code.
3.Portable
(they can be executed on any kind OS)
4.Object-Oriented
(it is complete object oriented programming)
5.Robust
(it is very strong with type checking
6.Multithreaded
( java support Multithreading)
Centre (Variables)
radius
circumference()
area()
int age; }
void barking() {
{ }
}
aCircle bCircle
bCircle = aCircle;
P Q P Q
ObjectName . VariableName
ObjectName .MethodName(parameter-list)
Radius=5.0 Area=78.5
Radius=5.0 Circumference =31.400000000000002
COURSE: OOPJ UNIT: 1 Pg. 20
CONSTRUCTOR
Constructor in java is a special type of method that is used to initialize the object.
Java constructor is invoked at the time of object creation. It constructs the values i.e.
provides data for the object that is why it is known as constructor.
RULES FOR CREATING JAVA CONSTRUCTOR:
There are basically two rules defined for the constructor.
1.Constructor name must be same as its class name
2.Constructor must have no explicit return type
TYPES OF JAVA CONSTRUCTORS
There are two types of constructors:
1. Default constructor (no-arg constructor)
2. Parameterized constructor
Output:
Bike is created
The main purpose of using this keyword is to differentiate the formal parameter and
data members of class.
whenever the formal parameter and data members of the class are similar then jvm
get ambiguity (no clarity between formal parameter and member of the class)
To differentiate between formal parameter and data member of the class, the data
member of the class must be preceded by "this".
GROUP OF OPERATORS:
Arithmetic Operators(+,-,*,/ ,%)
• Assignment Operator(=)
• Order of Precedence
• Increment/Decrement Operators(++,--)
Relational Operators(<,>,<=,>=,==,!=)
Logical Operators(&&,||,!)
Bitwise Operators(~,&,|,^)
Shift Operators(>>,>>>,>>)
Ternary Operator(?)
a 00000000000000000000000000000011 3
a >> 2 00000000000000000000000000000000 0
>>
Left
b 11111111111111111111111111111100 -4
b >> 2 11111111111111111111111111111111 -1
int a = 3; // ...00000011 = 3
int b = -4; // ...11111100 = -4
a 00000000000000000000000000000011 3
a >>> 2 00000000000000000000000000000000 0
>>>
Right 0
b 11111111111111111111111111111100 -4
b >>> 2 00111111111111111111111111111111 +big
Java includes a special ternary operator that can replace certain types of if – then -
else statements. This operator is ?.
The syntax is:
expression1?expression2:expression3;
Hear expression1 returns boolean value.
If expression1 returns true then expression2 is executed, if expression1 return
false then expression3 is exicuted.
EXAMPLE :
class CheckEvenNumber
{
public static void main( String args[] ) {
int number = 3;
String msg = (number % 2 == 0) ? " The number is even!" : " The number is odd!";
System. out. println(msg);
} }
In general, there are two ways that a computer language can pass an argument.
1. call-by-value(pass values).
2. call-by-reference(pass object).
Java also use above two ways to pass an argument.
When you pass a primitive type to a method, it is passed by value
When you pass an object to a method, it is call-by-reference
codePointAt() Returns the Unicode of the character at the specified index int
codePointBefore() Returns the Unicode of the character before the specified index int
codePointCount() Returns the Unicode in the specified text range of this String int
contentEquals() Checks whether a string contains the exact same sequence of boolean
characters of the specified CharSequence or StringBuffer
copyValueOf() Returns a String that represents the characters of the character array String
endsWith() Checks whether a string ends with the specified character(s) boolean
equals() Compares two strings. Returns true if the strings are equal, and false if boolean
not
COURSE: OOPJ UNIT: 1 Pg. 54
CONTENT BEYOND SYLLABUS
JAVA VERSIONS:
Version - Release date Version - Release date
• JDK Beta - 1995 • Java SE 8 - March 2014
• JDK 1.0 - January 1996 • Java SE 9 - September 2017
• JDK 1.1 - February 1997 • Java SE 10 - March 2018
• J2SE 1.2 - December 1998 • Java SE 11 - September 2018
• J2SE 1.3 - May 2000 • Java SE 12 - March 2019
• J2SE 1.4 - February 2002 • Java SE 13 - September 2019
• J2SE 5.0 - September 2004 • Java SE 14 - March 2020
• Java SE 6 - December 2006 • Java SE 15 - September 2020
• Java SE 7 - July 2011
Fig . 1.14
COURSE: OOPJ UNIT: 1 Pg. 56
UNIT OUTCOMES:
Student should be able to
Understand the syntax, semantics and features of Java Programming Language.
Learn object oriented features and understanding type conversion and casting.
Understand different types of string handling functions and its usage.