Professional Documents
Culture Documents
Introduction To JAVA
Object-Oriented Programming
Basic Concept of OOP
1. Objects
2. Classes
3. Data abstraction
4. Data Encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic binding
Objects
Objects are important runtime entities in
object oriented method.
Object: STUDENT
DATA
They may characterize Name
Address
a location, Marks
a bank account, and METHODS
a table of data or Total()
any entry that the program mustAverage()
handle
Classes
A class is a set of objects with similar properties (attributes),
common behaviour (operations), and common link to other
objects.
A class is a collection of objects of similar type.
Classes are user defined data types and work like the build in
type of the programming language.
Once the class has been defined, we can make any number of
objects belonging to that class.
Data Abstraction
Data abstraction refers to the act of representing important
description without including the background details or
explanations.
Syntax:
C:\ javac filename.java
2. Java (Java Interpreter)
C:\java filename
If my filename is abc.java then the syntax will be
C:\ java abc
How to compile and run the program
Steps.
1. Edit the program by the use of Notepad.
2. Save the program to the hard disk.
3. Compile the program with the javac command. (Java
compiler)
4. If there are syntax errors, go back to Notepad and edit the
program.
5. Run the program with the java command. (Java Interpreter)
6. If it does not run correctly, go back to Notepad and edit the
program.
7. When it shows result then stop.
Data Types
The data type defines the kind of data represented by a variable.
Java data types are case sensitive.
There are two types of data types
1.Primitive data types
1. Numeric
1. Integer
2. Floating Points
2. Non-numeric means
1. Character and
2. Boolean
2.In non-primitive types, there are three categories
1. Classes
2. Arrays
3. Interface
The classification of data types in Java
Data types in
Java
Primitiv Non-primitive
e
Numeri Non-
c numeric classe Arrays
s
integer
char Interface
Floating Boolea
point n
dataType variableName;
Numeric Constants
Integer constant constant int a=10;
• Decimal constant float pi=3.14;
• Octal
• Hexadecimal constant char c=‘a’;
Real constant constant String a=
Character Constants “Welcome”;
Character constant
String constant
Symbolic constants
There are many things which is requires repeatedly and if
we want to make changes then we have to make these
changes in whole program where this variable is used.
Java provides “final” keyword to declare the value of
variable as follows:
Syntax:
final type Symbolic_name=value;
For example: If I want to declare the value of ‘PI‘ then:
Constant Importance
‘\b‘ Back space
‘\t‘ Tab
‘\n‘ New line
‘\\‘ Backslash
‘\’’ Single quote
‘\”‘ Double quote
Type Casting
For storing value of one type into a variable of another type.
The Syntax is:
Type variable1 =(type) variable2;
Examples:
int m = 50;
Byte n = (byte) m;
long count= (long) m;
Four integer types can be cast to any other type except
boolean.
Casting into smaller type may result in loss of data.
comment
A note written in the source code by the programmer to make
the code easier to understand.
– Comments are not executed when your program runs.
– Most Java editors turn your comments a special color to
make it easier to identify them.
Comment, general syntax:
/* <comment text; may span multiple lines> */
or,
// <comment text, on one line>