Programming in Java ****** 18CS653
MODULE 1
An Overview of Java:
Object Oriented Programming
A First Simple Program
A Second Short Program
Two Control statements
Using Blocks of code
Lexical Issues
The Java Class Libraries
Data Types, Variables and Arrays:
Java is a Strongly typed Language
The Primitive types.
Integers
Floating-Point types
Characters
Booleans
A Closer look at Literals
Variables
Type conversion and casting
Automatic Type promotion in Expressions
Arrays
A few words about strings
Mrs.Mamatha A, Assistant Professor, ISE Department 1
,Programming in Java ****** 18CS653
Object Oriented Programming:
Object oriented programming (OOP) is the core of Java programming.
Java is a general purpose, object- oriented programming language developed by Sun
Microsystems. It was invented by James Gosling and his team and was initially called
as Oak.
The most important feature that made Java very popular was the ―Platform-
Independent‖ approach.
It was the first programming language that did not tie-up with any particular operating
system( or hardware) rather Java programs can be executed anywhere and on any
system.
Java was designed for the development of the software for consumer electronic
devices like TVs, VCRs, etc.
Two Paradigms:
Every program contains 2 components code and data.
Two approaches are there to solve the problem and in program writing: Procesure
oriented and object oriented.
Procedure Oriented:
Procedure oriented programs are written based on ―whats happening‖ around, where
the code acts on data. Ex: C etc
Problems increases in procedure oriented as the program grows larger and more
complex.
Object Oriented:
Object oriented programs are written based on ―Who is being affected‖ around,
which manages the increasing complexity.
It organises program around data and well defined interfaces of that data.
Characterised as data controlling access to code. Ex: C++, JAVA, Small Talk etc
The Three OOP:
The three important features of OOP are:
Encapsulation
Inheritence
Polymorphism
Mrs.Mamatha A, Assistant Professor, ISE Department 2
,Programming in Java ****** 18CS653
Encapsulation:
Encapsulation is the mechanism that binds together code and data it manipulates,
and keeps both safe from outside interference and misuse.
In Java the basis of encapsulation is the class. A class defines the state and behavior(
data & code) that will be shared by set of objects.
Each object contains the structure and behavior defined by the class. The data
defined by the class are called instance variables(member variables), the code that
operates on that data are called methods(member functions).
Inheritence:
Inheritence is the process by which one object acquires the properties of another
object. This is important as it supports the concept of hierarchical classification.
By the use of inheritence, a class has to define only those qualities that make it
unique. The general qualities can ber derived from the parent class or base class.
Ex: A child inheriting properties from parents.
Polymorphism
Polymorphism (meaning many forms) is a feature that allows one interface to be
used for a general class of actions. The specific action determined by the exact
nature of the situation. This concept is often expressed as ― one interface, multiple
methods‖.
Ex: ―+‖ can be used for addition of 2 numbers and also concatenation of 2 strings.
System.out.println(2+4); // outputs 6 as answer
System.out.println(―Hello‖ + ―Gautham‖); // outputs Hello Gautham as answer
Apart from this the additional features include:
Object:
An object can be any real world entity.
Ex: an animal, bank, human, box, fan etc
An object is a software bundle of related state and behavior.
An object is an instance of class.
Mrs.Mamatha A, Assistant Professor, ISE Department 3
, Programming in Java ****** 18CS653
Class:
A class is a blueprint or prototype from which objects are created.
Its just a template for an object, which describes an object.
Ex: a class describes how an animal looks like.
A class is a user defined data type.
Abstraction:
Data abstraction refers to providing only essential information to the outside world
and hiding their background details i.e., to represent the needed informatin in
program without presenting the details.
Ex: a database system hides certain details of how data is stored and created and
maintained.
Polymorphism, Encapsulation and Inheritence work Together
The 3 principles of OOP Polymorphism, Encapsulation and Inheritence combines
together to make the programming robust and scalable.
Encapsulation allows to migrate the implementation without disturbing the code that
depends on class.
Polymorphism allows to create clean, sensible, readable, resilient code.
Inheritence mainly deals with the code reusability.
A First Simple Program
class Example
{
public static void main(String args[])
{
System.out.println(―Welcome to Programming in Java‖);
}
}
1. Open the notepad and type the above program
Mrs.Mamatha A, Assistant Professor, ISE Department 4
MODULE 1
An Overview of Java:
Object Oriented Programming
A First Simple Program
A Second Short Program
Two Control statements
Using Blocks of code
Lexical Issues
The Java Class Libraries
Data Types, Variables and Arrays:
Java is a Strongly typed Language
The Primitive types.
Integers
Floating-Point types
Characters
Booleans
A Closer look at Literals
Variables
Type conversion and casting
Automatic Type promotion in Expressions
Arrays
A few words about strings
Mrs.Mamatha A, Assistant Professor, ISE Department 1
,Programming in Java ****** 18CS653
Object Oriented Programming:
Object oriented programming (OOP) is the core of Java programming.
Java is a general purpose, object- oriented programming language developed by Sun
Microsystems. It was invented by James Gosling and his team and was initially called
as Oak.
The most important feature that made Java very popular was the ―Platform-
Independent‖ approach.
It was the first programming language that did not tie-up with any particular operating
system( or hardware) rather Java programs can be executed anywhere and on any
system.
Java was designed for the development of the software for consumer electronic
devices like TVs, VCRs, etc.
Two Paradigms:
Every program contains 2 components code and data.
Two approaches are there to solve the problem and in program writing: Procesure
oriented and object oriented.
Procedure Oriented:
Procedure oriented programs are written based on ―whats happening‖ around, where
the code acts on data. Ex: C etc
Problems increases in procedure oriented as the program grows larger and more
complex.
Object Oriented:
Object oriented programs are written based on ―Who is being affected‖ around,
which manages the increasing complexity.
It organises program around data and well defined interfaces of that data.
Characterised as data controlling access to code. Ex: C++, JAVA, Small Talk etc
The Three OOP:
The three important features of OOP are:
Encapsulation
Inheritence
Polymorphism
Mrs.Mamatha A, Assistant Professor, ISE Department 2
,Programming in Java ****** 18CS653
Encapsulation:
Encapsulation is the mechanism that binds together code and data it manipulates,
and keeps both safe from outside interference and misuse.
In Java the basis of encapsulation is the class. A class defines the state and behavior(
data & code) that will be shared by set of objects.
Each object contains the structure and behavior defined by the class. The data
defined by the class are called instance variables(member variables), the code that
operates on that data are called methods(member functions).
Inheritence:
Inheritence is the process by which one object acquires the properties of another
object. This is important as it supports the concept of hierarchical classification.
By the use of inheritence, a class has to define only those qualities that make it
unique. The general qualities can ber derived from the parent class or base class.
Ex: A child inheriting properties from parents.
Polymorphism
Polymorphism (meaning many forms) is a feature that allows one interface to be
used for a general class of actions. The specific action determined by the exact
nature of the situation. This concept is often expressed as ― one interface, multiple
methods‖.
Ex: ―+‖ can be used for addition of 2 numbers and also concatenation of 2 strings.
System.out.println(2+4); // outputs 6 as answer
System.out.println(―Hello‖ + ―Gautham‖); // outputs Hello Gautham as answer
Apart from this the additional features include:
Object:
An object can be any real world entity.
Ex: an animal, bank, human, box, fan etc
An object is a software bundle of related state and behavior.
An object is an instance of class.
Mrs.Mamatha A, Assistant Professor, ISE Department 3
, Programming in Java ****** 18CS653
Class:
A class is a blueprint or prototype from which objects are created.
Its just a template for an object, which describes an object.
Ex: a class describes how an animal looks like.
A class is a user defined data type.
Abstraction:
Data abstraction refers to providing only essential information to the outside world
and hiding their background details i.e., to represent the needed informatin in
program without presenting the details.
Ex: a database system hides certain details of how data is stored and created and
maintained.
Polymorphism, Encapsulation and Inheritence work Together
The 3 principles of OOP Polymorphism, Encapsulation and Inheritence combines
together to make the programming robust and scalable.
Encapsulation allows to migrate the implementation without disturbing the code that
depends on class.
Polymorphism allows to create clean, sensible, readable, resilient code.
Inheritence mainly deals with the code reusability.
A First Simple Program
class Example
{
public static void main(String args[])
{
System.out.println(―Welcome to Programming in Java‖);
}
}
1. Open the notepad and type the above program
Mrs.Mamatha A, Assistant Professor, ISE Department 4