SlideShare a Scribd company logo
Presented by
E.RAJKUMAR M.E
(Asst.proff/CSE)
1
UNIT-I INTRODUCTION TO
OOP AND JAVA FUNDAMENTALS
OBJECT ORIENTED PROGRAMMING
BASICS
• LANGUAGE
• PROGRAMMING LANGUAGE
• TYPES OF PROGRAMMING LANGUAGE
• PROGAM TRANSLATORS
LANGUAGE
3
• Language is often used to communicate with
others
PROGRAMMING LANGUAGE
4
• A Programming language is the main medium of communicating
between the Computer systems
PROGRAMMING LANGUAGE
5
• A Programming language is computer language which contains
set of instructions (programs or commands) for instructing
computer to perform specific task
• Programming languages tells computers what to do in order to
work.
• Programming languages are used to make all the computer
programs and computer software.
PROGRAMMING LANGUAGE
6
TYPES OF PROGRAMMING LANGUAGE
• Machine Language
• Assembly Language
• High-level computer languages
PROGRAMMING LANGUAGE
7
Machine Language : (‘0’s and ‘1’ s )
A machine language consists of the numeric codes for the operations that a particular
computer can execute directly. The codes are strings of 0 s and 1s, or binary digits (“bits”)
Example: 0110 1100
Assembly Language (microprocessor language)
Assembly language is one level above machine language. It uses short mnemonic codes for
instructions and allows the programmer to introduce names for blocks of memory that hold
data.
Example: MOV, LOAD, ADD, MUL
PROGRAMMING LANGUAGE
8
High level languages (C++, JAVA)
• High-level computer languages use formats that are similar to English. The purpose of
developing high-level languages was to enable people to write programs easily, in their own
native language environment (English).
• Each instruction in the high-level language is translated into many machine language
instructions that the computer can understand.
• BASIC (Beginners All Purpose Symbolic Instruction Code)
• FORTRAN (Formula Translation)
• C++
• Java
• Visual Basic … etc
PROGRAMMING LANGUAGE
9
• As we know a Computer only understands binary numbers that is 0 and 1. So Each
instruction in the high-level language & assembly language is translated into many
machine language instructions by program translators so that the computer can understand.
HOW DO WE LEARN PROGRAMMING
LANGUAGE?
1
• .
LANGUAGE PROGRAMMING LANGUAGE
Listening
Speaking
Reading
writing
Listening
Reading
Writing
Practicing
OBJECT ORIENTED PROGRAMMING
1
• Object-oriented programming (OOP) is a programming based on the concept of "objects“.
Object means a real word entity such as pen, chair, table , mobile phone etc.
• It is used program structure into simple, reusable pieces of code
Object-oriented programming has several advantages over procedural programming:
• OOP is faster and easier to execute
• OOP provides a clear structure for the programs
• OOP helps to keep code DRY "Don't Repeat Yourself", and makes the code easier to
maintain, modify and debug
• OOP makes it possible to create full reusable applications with less code and shorter
development time
OBJECT ORIENTED PROGRAMMING
1
• Some of the object oriented programming language are
C++, JAVAC#, Python, PHP, Visual Basic.NET, JavaScript, Ruby, Perl etc
Features of OOP
Classes
Objects
Data Abstraction
Encapsulation
Inheritance
Polymorphism
JAVA PROGRAMMING
1
 JAVA INTRODUCTION
 KEY ADVANTAGES OF JAVA
 HISTROY OF JAVA
 VERSIONS OF JAVA
 JAVA DEVELOPMENT KIT (JDK)
 JAVA DOWNLOAD & INSTALLION
Java - An Introduction
1
Java is a high-level object oriented programming language.
Java originally developed by Sun Microsystems and released in 1995
Java runs on a variety of platforms, such as Windows, Mac OS, and the
various versions of UNIX. So it is called Platform independent
It is used to develop
• Mobile applications (specially Android apps)
• Desktop applications
• Web applications
• Games
• Embedded systems
key advantages of learning Java
Programming
1
It is open-source and free
It is easy to learn and simple to use
It is secure, fast and Robust
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.).
Platform independent language.
Java applications are called WORA (Write Once Run Anywhere). This
means a programmer can develop Java code on one system and can expect it
to run on any other Java-enabled system without any adjustment.
Java is an object oriented language which gives a clear structure to programs
and allows code to be reused
HISTROY OF JAVA
1
Java was started as a project called "Oak" by James Gosling in
June 1991
In 1995, Oak was renamed as "Java“ and released by Sun
Microsystems (which is now a subsidiary of Oracle Corporation)
JAVA VERSIONS
1
First version of java JDK 1.0 released in(January 23, 1996).
JDK Alpha and Beta (1995)
JDK 1.0 (23rd Jan 1996)
JDK 1.1 (19th Feb 1997)
J2SE 1.2 (8th Dec 1998)
J2SE 1.3 (8th May 2000)
J2SE 1.4 (6th Feb 2002)
J2SE 5.0 (30th Sep 2004)
Java SE 6 (11th Dec 2006)
Java SE 7 (28th July 2011)
Java SE 8 (18th Mar 2014)
Java SE 9 (21st Sep 2017)
Java SE 10 (20th Mar 2018)
Java SE 11(September 25, 2018 )
Java SE 12(March 19, 2019)
Java SE 13(September 17, 2019)
Java SE 14(March 17, 2020)
JAVA ENVIRONMENT
1
JDK (JAVA DEVELOPMENT KIT)
1
The Java Development Kit (JDK) is a software development environment
which is used to develop java applications. It physically exists. It contains
JRE + development tools (packages) , a compiler (javac) & Interpreter.
The JDK allows developers to create Java programs that can be executed and
run by the JVM and JRE
8
Java Development Kit
 javac - The Java
Compiler
 java
-
The Java Interpreter
 appletviewer -Tool to run the
applets
save- sample.java
appletviewer sample.java
JRE (JAVA RUNTIME ENVIRONMENT)
2
JRE (Java Runtime Environment) is a software package that provides Java
class libraries, Java Virtual Machine (JVM), and other components that are
required to run Java applications.
JRE (JAVA VIRTUAL MACHINE)
2
JVM (Java Virtual Machine) is an abstract machine that enables your
computer to run a Java program.
When you run the Java program, Java compiler first compiles your Java code
to bytecode.
Then, the JVM translates bytecode into native machine code (set of
instructions that a computer's CPU executes directly).
7
(c) venkates
h
Java
Bytecodes
move locally
or through
network
Java
Source
(.java)
Java
Compiler
Java
Bytecode
(.class )
Java
Interpreter
Just in
Time
Compiler
Runtime System
Class
Loader
Bytecode
Verifier
Java
Class
Libraries
Operating System
Hardware
Java
Virtual
machine
Runtime
Environment
Compile-time
Environment
Java Environment/
Life Cycle of Java
Code
Total Platform Independence
6
windows
Macintosh Solaris Windows NT
JAVA DOWNLOAD & INSTALLATION
2
Java SE is freely available from the link https://www.oracle.com/java/ You can
download a version based on your operating system.
run the .exe to install Java on your machine. Once you installed Java on your
machine you will need to set path
SYSTEM REQUIREMENTS
2
 you will need a Pentium 200-MHz computer with a minimum of 64 MB of
RAM (128 MB of RAM recommended).
You will also need the following softwares −
Linux 7.1 or Windows xp/7/8 operating system
Java JDK (any version)
Microsoft Notepad or any other text editor
Two Types of JavaApplications
 Different ways to write/run a Java codes are:
Application- A stand-alone program that can be invoked
from command line . A program that has a “main”
method
Applet- A program embedded in a web page , to be run
when the page is browsed . A program that contains no
“main” method
 Application -Java interpreter
 Applets- Java enabled web browser (Linked to HTML via
<APPLET> tag. in html file)
17
Java programs
28
Two kinds
– Applications
• have main()
• run from the OS
prompt
– Applets
• have init(), start(),
stop(), paint(),
update(), repaint(),
destroy()
• run from within a web
page
JAVA PROGRAMMING
29
 REQUIREMENT FOR JAVA PROGRAMMING
 A SIMPLE JAVA PROGRAM
 COMPILATION & EXECUTION
 SETTING THE PATH (JAVA PATH TO OUR FOLDER)
REQUIREMENT FOR JAVA
PROGRAMMING
30
For executing any java program,
 Download & Install the JDK https://www.oracle.com/java/
 Create the java program (using notepad in any folder)
 Set path of the jdk
 Compile and run the java program
A SIMPLE JAVA PROGRAM
import java.io.*;
class hello
{
public static void main(String args[])
{
System.out.println(“Hello Internet”);
}
}
31
Access
Permission
Main function
keyword
Argument
keyword
Class name
A SIMPLE JAVA PROGRAM
32
class keyword is used to declare a class in java.
public keyword is an access modifier which represents visibility. It means it
is visible to all.
static is a keyword. If we declare any method as static, it is known as the
static method. The core advantage of the static method is that there is no need
to create an object to invoke the static method. The main method is executed
by the JVM, so it doesn't require to create an object to invoke the main
method. So it saves memory.
A SIMPLE JAVA PROGRAM
33
void is the return type of the method. It means it doesn't return any value.
main represents the starting point of the program.
String[] args is used for command line argument. We will learn it later
.
System.out.println() is used to print statement. Here, System is a class,
out is the object of PrintStream class, println() is the method of PrintStream
class.
A SIMPLE JAVA PROGRAM
34
A SIMPLE JAVA PROGRAM
35
Save the program file as .java (Ex: hello.java)
SETTING PATH (method 1)
36
Open a command prompt (cmd)
 Go to the program folder(example E:java)
Set the path using below command
Path=%path%; “C:Program Files (x86)Javajdk1.7.0bin”
SETTING PATH
37
SETTING PATH (method 2)
38
Setting Up the Path for Windows
Assuming you have installed Java in c:Program Filesjava
jdk directory −
Right-click on 'My Computer' and select 'Properties'.
Click the 'Environment variables' button under the 'Advanced' tab.
Now, alter the 'Path' variable so that it also contains the path to the
Java executable. Example, if the path is currently set to 'C:WINDOWS
SYSTEM32', then change your path to read 'C:WINDOWS
SYSTEM32;c:Program Filesjavajdkbin'.
COMPILTATION & RUN
39
Compile using javac (example: javac hello.java)
Run using java(example: java hello)
COMPILATION & RUN
40
COMPILTATION & RUN
41
To write your Java programs, you will need a text editor. There are even
more sophisticated IDEs available in the market. But for now, you can
consider one of the following −
Notepad − On Windows machine, you can use any simple text editor like
Notepad (Recommended for this tutorial), TextPad.
Netbeans − A Java IDE that is open-source and free which can be
downloaded from https://www.netbeans.org/index.html.
Eclipse − A Java IDE developed by the eclipse open-source community and
can be downloaded from https://www.eclipse.org/
OBJECT ORIENTED PROGRAMMING
42
OBJECT ORIENTED PROGRAMMING
43
Why to create different classes in java ?
44
In java we can create different class with different names & write the
programs(coding) under each class. Ie, separating group of statements
and naming them
This is used for identification & execution
For example: if we are creating student mark storing application
We need to create login page, signup page, section/dept/subject/sem
selection page.
Why to create different classes in java ?
45
Instead of writing all the codes in a single function, we can separate the
programs using classes and write under it.
Student mark store:
Register page
Login page
Subject/sem/section selection
Mark entry
Why to create different classes in java ?
46
Why to create different classes in java ?
47
Why to create different classes in java ?
48
Why to create different classes in java ?
49
OOPS CONCEPT or OOPS FEATURES
50
OOPS CONCEPT (or) OOPS FEATURES
51
CLASS
Class is a collection of data members (variables) and methods(functions)
A class can also be defined as a blueprint from which you can create an
individual object. Collection of objects is called class
The primary purpose of a class is to hold data/information.
Class is a user defined data type. Class is declared with class name used as
identifier.
OOPS CONCEPT or OOPS FEATURES
52
OOPS CONCEPT or OOPS FEATURES
53
OOPS CONCEPT (or) OOPS FEATURES
54
OBJECT
An Object can be defined as an instance of a class. An object contains an
address and takes up some space in memory.
Object invokes the members of the class
OOPS CONCEPT or OOPS FEATURES
55
OOPS CONCEPT (or) OOPS FEATURES
56
OBJECT
In general, objects are real world entities For example, a chair, pen, table,
keyboard, bike, etc.
Each has its own state and behavior.
EX:
A dog is an object because it has states like color, name, etc.
as well as behaviors like wagging the tail, barking, eating, etc.
OOPS CONCEPT (or) OOPS FEATURES
57
INHERITANCE (Code reusability)
It provides code reusability.
Inheritance can be defined as the procedure or mechanism of acquiring all
the properties and behavior of one class to another, i.e., acquiring the
properties and behavior of child class from the parent class.
Creating new class from existing class.
Existing class is called parent class (super-class or base class)
New class is called child class(subclass or derived
OOPS CONCEPT or OOPS FEATURES
58
OOPS CONCEPT or OOPS FEATURES
59
OOPS CONCEPT (or) OOPS FEATURES
60
ENCAPSULATION (data hiding) (data secure)
 It is also known as data hiding.
Encapsulation is a process of wrapping code and data together into a single
unit(ie,class)
In encapsulation, the variables of a class will be hidden from other classes,
and can be accessed only through the methods of their current class.
OOPS CONCEPT or OOPS FEATURES
61
OOPS CONCEPT or OOPS FEATURES
62
OOPS CONCEPT (or) OOPS FEATURES
63
ABSTRACTION
Abstraction is a process of hiding the implementation details and showing
only functionality to the user
OOPS CONCEPT or OOPS FEATURES
64
OOPS CONCEPT or OOPS FEATURES
65
OBJECT ORIENTED PROGRAMMING
66
VARIABLES
TYPES OF VARIABLES
DATA TYPES
VARIABLES
67
A variable is a container which holds (or) stores the value
Variable is a name of memory location.
A variable is assigned with a datatype
Example:
int a = 20;
int b = 10;
RULES FOR DECLARING VARIABLES
68
Start with alphabet
Special characters not allowed (@,$.{,},[,],. &..Etc)
but underscore_ allowed
Java keywords not allowed
RULES FOR DECLARING VARIABLES
69
RULES FOR DECLARING VARIABLES
70
RULES FOR DECLARING VARIABLES
71
TYPES OF VARIABLES
72
There are three types of variables in Java:
local variable
instance variable (global variable)
static variable
LOCAL VARIABLES
73
1) Local Variable
A variable declared inside the body of the method is called local variable. You
can use this variable only within that method and the other methods in the
class aren't even aware that the variable exists.
class A{
public static void main(String args[])
{
int n = 90; //local variable
}
}
LOCAL VARIABLES
74
}
LOCAL VARIABLES
75
}
LOCAL VARIABLES
76
}
INSTANCE VARIABLE
77
2)Instance Variable (global variable)
A variable declared inside the class but outside the body of the method, is called
instance variable
class A{
int n = 90; //Instance variable
public static void main(String args[])
{
int a = 10 ; //Local variable
}
}
INSTANCE VARIABLE
78
STATIC VARIABLE
79
Static variable
A variable which is declared as static is called static variable. It cannot be local.
class A{
static int n = 90 ; // static variable
public static void main(String args[])
{
int a = 10 ; //Local variable
}
}
STATIC VARIABLE
80
class A{
static int n = 90 ;
public static void main(String args[])
{
int n = 10 ;
System.out.println(n);
System.out.println(n);
System.out.println(n);
}
} Output 90 10 10
TYPES OF VARIABLE
81
class A
{
static int n = 90 ; // static variable
int n = 90; //Instance variable
public static void main(String args[])
{
int a = 10 ; //Local variable
}
}
DATATYPES
82
 Data types are the types of data used in the program
 When computer programs store data in variables, each
variable must be assigned a specific data type. Some
common data types include integers, floating point
numbers, characters, strings,
• Integer (int): 1, 2, 10,20,-1,-2(generally called numbers)
• Float (float): 10.8, 12.02 (generally called decimal)
• Character(char): a, b, c ( generally alphabets)
• String (string): “raj”, “siva”, “vishnu” etc
• double: 34674574, 7847584
DATA TYPES IN JAVA
83
Data types represent the different values to be stored in the variable.
In java, there are two types of data types:
Primitive data types
Non-primitive data types
DATA TYPES IN JAVA
84
PRIMITIVE DATA TYPES
85
Integer : byte, short, int and long data types are used for storing
whole numbers.
Floating point : float and double are used for fractional numbers.
Character: char is used for storing characters(letters).
boolean data type is used for variables that holds either true or
false.
INTEGER DATA TYPE
86
Integer data type are used for storing whole numbers.
•Byte: The byte data type can store whole numbers from -128 to 127
Ex: byte a = 100;
•Shot: Its value-range lies between -32,768 to 32,767 (inclusive). Its minimum value is -32,768
and maximum value is 32,767. Its default value is 0.
Ex: short a = 5000;
INTEGER DATA TYPE
87
• int: The int data type can store whole numbers from -2147483648 to 2147483647. In
general, the int data type is the preferred data type when we create variables with a
numeric value.
EX: int b = 100000;
• Long data type can store whole numbers from -9223372036854775808 to
9223372036854775807. This is used when int is not large enough to store the value
Ex: long b = 15000000000L;
FLOATING POINT DATA TYPE
88
Floating point data types are used for fractional numbers
The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you
should end the value with an "f":
Ex: float a = 5.75f;
The double data type can store fractional numbers from 1.7e−308 to 1.7e+308. Note that you
should end the value with a "d":
double a = 19.99d;
FLOATING POINT DATA TYPE
89
Floating point data types are used for fractional numbers
The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you
should end the value with an "f":
Ex: float a = 5.75f;
The double data type can store fractional numbers from 1.7e−308 to 1.7e+308. Note that you
should end the value with a "d":
double a = 19.99d;
CHARACTER DATA TYPE
90
The char data type is used to store a single character. The character must be
surrounded by single quotes, like 'A' or 'c':
Example:
char b = 'B';
BOOLEAN DATA TYPE
91
A boolean data type is declared with the boolean keyword and can only take the
values true or false:
Example:
boolean a = true;
boolean b = false;
BOOLEAN DATA TYPE
92
A boolean data type is declared with the boolean keyword and can only take the
values true or false:
Example:
boolean a = true;
boolean b = false;
NON-PRIMITIVE DATA TYPES
93
STRING
A string is a sequence of characters separated by double quotes.
String a = “Rajkumar";
CLASSES
A class in Java is a blueprint which includes all your data. A class contains fields
(variables) and methods to describe the behavior of an object
NON-PRIMITIVE DATA TYPES
94
ARRAYS
an array is a collection of similar elements(values) of the same data type
int[] a = {1,2,3,4,5}
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
OPERATORS
95
 Operator is a symbol which is used to perform operations. For example: +, -, *, / etc..
 Operators are used to perform operations on variables and values.
In the example below, we use the + operator to add together two values:
int x = 100 + 50; (+ is operator 100, 50 are values or operands)
int z = x + y; (x, y are operands)
OPERATORS
96
 Arithmetic Operators
 Assignment operators
 Relational Operators or comparison operators
 Logical Operators
 Conditional operator
 Increment & decrement operator
ARITHMETIC OPERATORS
97
 Arithmatic operators are used to perform addition, subtraction, multiplication, and
division. They act as basic mathematical operations.
Operator Description Example Result
+ Addition x=5+2 x=7
- Subtraction x=5-2 x=3
* Multiplication x=5*2 x=10
/ Division x=5/2 x=2.5
%
Modulus (division
remainder)
x=5%2 x=1
ARITHMETIC OPERATORS
98
class arithmetic{
public static void main(String args[]){
int a=10;
int b=5;
System.out.println(a+b); //15
System.out.println(a-b); //5
System.out.println(a*b); //50
System.out.println(a/b); //2
System.out.println(a%b); //0
}}
Assignment Operators
99
 Assignment operators are used to assign values to JavaScript variables.
 “=” is the assignment operator. the table below explains the assignment operators:
Operator Example Same As Result
= x=y x=5
+= x+=y x=x+y x=15
-= x-=y x=x-y x=5
*= x*=y x=x*y x=50
/= x/=y x=x/y x=2
%= x%=y x=x%y x=0
ASSIGNMENT OPERATORS
100
Comparison Operator (or) relational operators
101
 Relational operators (or) Comparison operators are used to compare two values.
Assume x=5
Operator Description Example
> is greater than x>8 is false
< is less than x<8 is true
>=
is greater than or equal
to
x>=8 is false
<= is less than or equal to x<=8 is true
== is equal to x==8 is false
===
is exactly equal to
(value and type)
x===5 is true
x==="5" is false
!= is not equal x!=8 is true
Comparison Operator (or) relational operators
102
Logical operators
103
 Logical operators are used to find out the relationship between two or more relational
expressions or statements. Assume X=8 Y=5
Operator Meaning Example
&& AND (x < 10 && y > 1) is true
|| OR (x=5 || y=5) is false
! NOT !(x==y) is true
Logical operators
104
Logical operators
105
 Logical operators are used to find out the relationship between two or more relational
expressions or statements. Assume X=8 Y=5
Operator Meaning Example
&& AND (x < 10 && y > 1) is true
|| OR (x>5 || y>10) is true
! NOT !(x==y) is true
Logical operators
106
INCREMENT & DECREMENT OPERATOR
Increment operator used to increment the value by one. “++” is the increment operator.
• Decrement operator is used to decrement the value by one. - - is decrement
operator
operator meaning Example Result
++ Increment x=++5 x=6
operator meaning Example Result
-- decrement x=--5 x=4
TERNARY (OR) CONDITIONAL OPERATOR
 The ternary operator (?) is also known as the conditional operator. This operator
consists of three operands and is used to evaluate expressions. The goal of the
operator is to decide, which value should be assigned to the variable.
Example:
a=15, b=20;
X = (a>b) ? a : b;
The value of X will be 20
if(a>b)
X=a;
else
X=b;
JAVA COMMENT LINES (// & /* */)
 Comments can be used to explain Java code, and to make it more readable.
 Any text between // and the end of the line is ignored by Java (will not be
executed).
 It can also be used to prevent execution when testing alternative code.
 Single-line comments (//)
 Multi-line Comments ( /* */)
JAVA COMMENT LINES (// & /* */)
SINGLE –LINE COMMENTS
• Single-line comments start with two forward slashes (//).
• Any text between // and the end of the line is ignored by Java (will not be
executed).
Example:
System.out.println("Hello World"); // This is a output statement
JAVA COMMENT LINES (// & /* */)
JAVA COMMENT LINES (// & /* */)
MULTIPLE COMMENT LINES
• Multi-line comments start with /* and ends with */.
• Any text between /* and */ will be ignored by Java.
JAVA COMMENT LINES (// & /* */)
CONSTRUCTORS
CONSTRUCTORS
CONSTRUCTORS
CONSTRUCTORS
CONSTRUCTORS
CONSTRUCTORS
CONSTRUCTORS
CONSTRUCTOR
121
It is a special type of method (function) called automatically when we create an object of
class. We can’t call explicitly.
Constructor name must be the same as its class name
It is a special type of method which is used to initialize(set up value) the object.
It is called constructor because it constructs the values at the time of object creation
a constructor is a block of codes similar to the method(function).
CONSTRUCTOR TYPES
122
There are two types of constructors in Java:
Default constructor (no-arg constructor)
Parameterized constructor
CONSTRUCTOR TYPES
123
Default constructor
A constructor is called "Default Constructor" when it doesn't have any
parameter.
class Bike1
{
Bike1()
{
System.out.println("Bike is created");
}
public static void main(String args[])
{
Bike1 b = new Bike1();
}
}
CONSTRUCTOR TYPES
124
Parameterized constructor
A constructor which has a specific number of parameters is called a
parameterized constructor.
CONSTRUCTOR TYPES
125
class Student4
{
int id;
String name;
Student4 (int i, String n)
{
id = i;
name = n;
System.out.println(id+" "+name);
}
public static void main(String args[])
{
Student4 s1 = new Student4(111,"Karan");
}
}
PACKAGES
126
A package in java is a collection of classes (or) group of classes
Using package it becomes easier to locate the related classes and it also
provides a good structure for projects with hundreds of classes and other files.
import package.name.class;
import package.name.*;
import java.io.*; (display inuput/output)
import java.util.*; (time , date, calender)
PACKAGES
127
Types of Packages
Built-in Package: Existing Java package for example java.applet, java.util ,
java.awt etc.
User-defined-package: Java package created by user to categorize their
project's classes and interface
PACKAGES
128
PACKAGES
129
130
UNIT-II
INHERITANCE &
INTERFACE
INHERITANCE
131
INHERITANCE (Code reusability)
It provides code reusability.
Inheritance can be defined as the procedure or mechanism of acquiring all the
properties and behavior of one class to another, i.e., acquiring the properties
and behavior of child class from the parent class.
Creating new class from existing class.
Existing class is called parent class (super-class or base class)
New class is called child class(subclass or derived
INHERITANCE
132
INHERITANCE
133
INHERITANCE
134
INHERITANCE (Code reusability)
Inheritance is one of the key features of Object Oriented Programming.
Inheritance provided mechanism that allowed a class to inherit property of another class.
When a Class extends another class it inherits all non-private members including fields
and methods.
 Inheritance in Java can be best understood in terms of Parent and Child relationship, also
known as Super class(Parent) and Sub class(child) in Java language.
extends is a keyword are used to describe inheritance in Java.
INHERITANCE
135
Terms used in inheritance
Super Class/Parent Class: Superclass is the class from where a subclass inherits the
features. It is also called a base class or a parent class.
Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a
derived class, extended class, or child class.
Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse
the fields and methods of the existing class when you create a new class. You can use the
same fields and methods already defined in previous class.
Extends: It is a keyword used in inheritance
TYPES OF INHERITANCE IN JAVA
136
SINGLE INHERITANCE
MULTILEVEL INHERITANCE
HEIRARCHICAL INHERITANCE
137
Thank you

More Related Content

PDF
Download Free Java Notes PDF for Easy Learning
PPTX
UNIT 1.pptx
PPTX
Introduction to java
PPTX
Iintroduction to java , Java Coding , basics of java.pptx
PPTX
Java session2
Download Free Java Notes PDF for Easy Learning
UNIT 1.pptx
Introduction to java
Iintroduction to java , Java Coding , basics of java.pptx
Java session2

Similar to Servlets and JavaServer Pages (JSP) from the B.Sc. Computer Science and Information Technology (CSIT) 7th Semester Syllabus (20)

PPTX
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
PPTX
JRE , JDK and platform independent nature of JAVA
PPTX
Presentation on Java Basic
PPTX
01_Java_Programming_Lecture-01_FCIT.pptx
PPTX
1_Introduction to Java.pptx java programming
PPSX
JAVA.ppsx java code java edv java development
PPTX
Java Programming Tutorials Basic to Advanced 1
PPT
J2ee strutswithhibernate-140121221332-phpapp01
PPS
Introduction to Java
PPTX
Java ms harsha
PDF
Core Java-1 (1).pdf
PPT
Java2020 programming basics and fundamentals
PPTX
JAVA PROGRAMMING-Unit I - Final PPT.pptx
PPT
Introduction to Java Programming, Basic Structure, variables Data type, input...
PPTX
What is Java, JDK, JVM, Introduction to Java.pptx
PPT
Java & J2EE Struts with Hibernate Framework
PPTX
Java lab zero lecture
PPTX
Java programming Introduction | Java basic architecture
DOCX
Java 3 rd sem. 2012 aug.ASSIGNMENT
PPTX
JAVAPart1_BasicIntroduction.pptx
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
JRE , JDK and platform independent nature of JAVA
Presentation on Java Basic
01_Java_Programming_Lecture-01_FCIT.pptx
1_Introduction to Java.pptx java programming
JAVA.ppsx java code java edv java development
Java Programming Tutorials Basic to Advanced 1
J2ee strutswithhibernate-140121221332-phpapp01
Introduction to Java
Java ms harsha
Core Java-1 (1).pdf
Java2020 programming basics and fundamentals
JAVA PROGRAMMING-Unit I - Final PPT.pptx
Introduction to Java Programming, Basic Structure, variables Data type, input...
What is Java, JDK, JVM, Introduction to Java.pptx
Java & J2EE Struts with Hibernate Framework
Java lab zero lecture
Java programming Introduction | Java basic architecture
Java 3 rd sem. 2012 aug.ASSIGNMENT
JAVAPart1_BasicIntroduction.pptx
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
DevOps & Developer Experience Summer BBQ
PDF
Modernizing your data center with Dell and AMD
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Omni-Path Integration Expertise Offered by Nor-Tech
PDF
Advanced IT Governance
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
REPORT: Heating appliances market in Poland 2024
PDF
Electronic commerce courselecture one. Pdf
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
KodekX | Application Modernization Development
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
DevOps & Developer Experience Summer BBQ
Modernizing your data center with Dell and AMD
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Omni-Path Integration Expertise Offered by Nor-Tech
Advanced IT Governance
NewMind AI Monthly Chronicles - July 2025
20250228 LYD VKU AI Blended-Learning.pptx
REPORT: Heating appliances market in Poland 2024
Electronic commerce courselecture one. Pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
KodekX | Application Modernization Development
madgavkar20181017ppt McKinsey Presentation.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
Understanding_Digital_Forensics_Presentation.pptx
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Ad

Servlets and JavaServer Pages (JSP) from the B.Sc. Computer Science and Information Technology (CSIT) 7th Semester Syllabus

  • 1. Presented by E.RAJKUMAR M.E (Asst.proff/CSE) 1 UNIT-I INTRODUCTION TO OOP AND JAVA FUNDAMENTALS OBJECT ORIENTED PROGRAMMING
  • 2. BASICS • LANGUAGE • PROGRAMMING LANGUAGE • TYPES OF PROGRAMMING LANGUAGE • PROGAM TRANSLATORS
  • 3. LANGUAGE 3 • Language is often used to communicate with others
  • 4. PROGRAMMING LANGUAGE 4 • A Programming language is the main medium of communicating between the Computer systems
  • 5. PROGRAMMING LANGUAGE 5 • A Programming language is computer language which contains set of instructions (programs or commands) for instructing computer to perform specific task • Programming languages tells computers what to do in order to work. • Programming languages are used to make all the computer programs and computer software.
  • 6. PROGRAMMING LANGUAGE 6 TYPES OF PROGRAMMING LANGUAGE • Machine Language • Assembly Language • High-level computer languages
  • 7. PROGRAMMING LANGUAGE 7 Machine Language : (‘0’s and ‘1’ s ) A machine language consists of the numeric codes for the operations that a particular computer can execute directly. The codes are strings of 0 s and 1s, or binary digits (“bits”) Example: 0110 1100 Assembly Language (microprocessor language) Assembly language is one level above machine language. It uses short mnemonic codes for instructions and allows the programmer to introduce names for blocks of memory that hold data. Example: MOV, LOAD, ADD, MUL
  • 8. PROGRAMMING LANGUAGE 8 High level languages (C++, JAVA) • High-level computer languages use formats that are similar to English. The purpose of developing high-level languages was to enable people to write programs easily, in their own native language environment (English). • Each instruction in the high-level language is translated into many machine language instructions that the computer can understand. • BASIC (Beginners All Purpose Symbolic Instruction Code) • FORTRAN (Formula Translation) • C++ • Java • Visual Basic … etc
  • 9. PROGRAMMING LANGUAGE 9 • As we know a Computer only understands binary numbers that is 0 and 1. So Each instruction in the high-level language & assembly language is translated into many machine language instructions by program translators so that the computer can understand.
  • 10. HOW DO WE LEARN PROGRAMMING LANGUAGE? 1 • . LANGUAGE PROGRAMMING LANGUAGE Listening Speaking Reading writing Listening Reading Writing Practicing
  • 11. OBJECT ORIENTED PROGRAMMING 1 • Object-oriented programming (OOP) is a programming based on the concept of "objects“. Object means a real word entity such as pen, chair, table , mobile phone etc. • It is used program structure into simple, reusable pieces of code Object-oriented programming has several advantages over procedural programming: • OOP is faster and easier to execute • OOP provides a clear structure for the programs • OOP helps to keep code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug • OOP makes it possible to create full reusable applications with less code and shorter development time
  • 12. OBJECT ORIENTED PROGRAMMING 1 • Some of the object oriented programming language are C++, JAVAC#, Python, PHP, Visual Basic.NET, JavaScript, Ruby, Perl etc Features of OOP Classes Objects Data Abstraction Encapsulation Inheritance Polymorphism
  • 13. JAVA PROGRAMMING 1  JAVA INTRODUCTION  KEY ADVANTAGES OF JAVA  HISTROY OF JAVA  VERSIONS OF JAVA  JAVA DEVELOPMENT KIT (JDK)  JAVA DOWNLOAD & INSTALLION
  • 14. Java - An Introduction 1 Java is a high-level object oriented programming language. Java originally developed by Sun Microsystems and released in 1995 Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. So it is called Platform independent It is used to develop • Mobile applications (specially Android apps) • Desktop applications • Web applications • Games • Embedded systems
  • 15. key advantages of learning Java Programming 1 It is open-source and free It is easy to learn and simple to use It is secure, fast and Robust Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.). Platform independent language. Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java-enabled system without any adjustment. Java is an object oriented language which gives a clear structure to programs and allows code to be reused
  • 16. HISTROY OF JAVA 1 Java was started as a project called "Oak" by James Gosling in June 1991 In 1995, Oak was renamed as "Java“ and released by Sun Microsystems (which is now a subsidiary of Oracle Corporation)
  • 17. JAVA VERSIONS 1 First version of java JDK 1.0 released in(January 23, 1996). JDK Alpha and Beta (1995) JDK 1.0 (23rd Jan 1996) JDK 1.1 (19th Feb 1997) J2SE 1.2 (8th Dec 1998) J2SE 1.3 (8th May 2000) J2SE 1.4 (6th Feb 2002) J2SE 5.0 (30th Sep 2004) Java SE 6 (11th Dec 2006) Java SE 7 (28th July 2011) Java SE 8 (18th Mar 2014) Java SE 9 (21st Sep 2017) Java SE 10 (20th Mar 2018) Java SE 11(September 25, 2018 ) Java SE 12(March 19, 2019) Java SE 13(September 17, 2019) Java SE 14(March 17, 2020)
  • 19. JDK (JAVA DEVELOPMENT KIT) 1 The Java Development Kit (JDK) is a software development environment which is used to develop java applications. It physically exists. It contains JRE + development tools (packages) , a compiler (javac) & Interpreter. The JDK allows developers to create Java programs that can be executed and run by the JVM and JRE
  • 20. 8 Java Development Kit  javac - The Java Compiler  java - The Java Interpreter  appletviewer -Tool to run the applets save- sample.java appletviewer sample.java
  • 21. JRE (JAVA RUNTIME ENVIRONMENT) 2 JRE (Java Runtime Environment) is a software package that provides Java class libraries, Java Virtual Machine (JVM), and other components that are required to run Java applications.
  • 22. JRE (JAVA VIRTUAL MACHINE) 2 JVM (Java Virtual Machine) is an abstract machine that enables your computer to run a Java program. When you run the Java program, Java compiler first compiles your Java code to bytecode. Then, the JVM translates bytecode into native machine code (set of instructions that a computer's CPU executes directly).
  • 23. 7 (c) venkates h Java Bytecodes move locally or through network Java Source (.java) Java Compiler Java Bytecode (.class ) Java Interpreter Just in Time Compiler Runtime System Class Loader Bytecode Verifier Java Class Libraries Operating System Hardware Java Virtual machine Runtime Environment Compile-time Environment Java Environment/ Life Cycle of Java Code
  • 25. JAVA DOWNLOAD & INSTALLATION 2 Java SE is freely available from the link https://www.oracle.com/java/ You can download a version based on your operating system. run the .exe to install Java on your machine. Once you installed Java on your machine you will need to set path
  • 26. SYSTEM REQUIREMENTS 2  you will need a Pentium 200-MHz computer with a minimum of 64 MB of RAM (128 MB of RAM recommended). You will also need the following softwares − Linux 7.1 or Windows xp/7/8 operating system Java JDK (any version) Microsoft Notepad or any other text editor
  • 27. Two Types of JavaApplications  Different ways to write/run a Java codes are: Application- A stand-alone program that can be invoked from command line . A program that has a “main” method Applet- A program embedded in a web page , to be run when the page is browsed . A program that contains no “main” method  Application -Java interpreter  Applets- Java enabled web browser (Linked to HTML via <APPLET> tag. in html file) 17
  • 28. Java programs 28 Two kinds – Applications • have main() • run from the OS prompt – Applets • have init(), start(), stop(), paint(), update(), repaint(), destroy() • run from within a web page
  • 29. JAVA PROGRAMMING 29  REQUIREMENT FOR JAVA PROGRAMMING  A SIMPLE JAVA PROGRAM  COMPILATION & EXECUTION  SETTING THE PATH (JAVA PATH TO OUR FOLDER)
  • 30. REQUIREMENT FOR JAVA PROGRAMMING 30 For executing any java program,  Download & Install the JDK https://www.oracle.com/java/  Create the java program (using notepad in any folder)  Set path of the jdk  Compile and run the java program
  • 31. A SIMPLE JAVA PROGRAM import java.io.*; class hello { public static void main(String args[]) { System.out.println(“Hello Internet”); } } 31 Access Permission Main function keyword Argument keyword Class name
  • 32. A SIMPLE JAVA PROGRAM 32 class keyword is used to declare a class in java. public keyword is an access modifier which represents visibility. It means it is visible to all. static is a keyword. If we declare any method as static, it is known as the static method. The core advantage of the static method is that there is no need to create an object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create an object to invoke the main method. So it saves memory.
  • 33. A SIMPLE JAVA PROGRAM 33 void is the return type of the method. It means it doesn't return any value. main represents the starting point of the program. String[] args is used for command line argument. We will learn it later . System.out.println() is used to print statement. Here, System is a class, out is the object of PrintStream class, println() is the method of PrintStream class.
  • 34. A SIMPLE JAVA PROGRAM 34
  • 35. A SIMPLE JAVA PROGRAM 35 Save the program file as .java (Ex: hello.java)
  • 36. SETTING PATH (method 1) 36 Open a command prompt (cmd)  Go to the program folder(example E:java) Set the path using below command Path=%path%; “C:Program Files (x86)Javajdk1.7.0bin”
  • 38. SETTING PATH (method 2) 38 Setting Up the Path for Windows Assuming you have installed Java in c:Program Filesjava jdk directory − Right-click on 'My Computer' and select 'Properties'. Click the 'Environment variables' button under the 'Advanced' tab. Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:WINDOWS SYSTEM32', then change your path to read 'C:WINDOWS SYSTEM32;c:Program Filesjavajdkbin'.
  • 39. COMPILTATION & RUN 39 Compile using javac (example: javac hello.java) Run using java(example: java hello)
  • 41. COMPILTATION & RUN 41 To write your Java programs, you will need a text editor. There are even more sophisticated IDEs available in the market. But for now, you can consider one of the following − Notepad − On Windows machine, you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad. Netbeans − A Java IDE that is open-source and free which can be downloaded from https://www.netbeans.org/index.html. Eclipse − A Java IDE developed by the eclipse open-source community and can be downloaded from https://www.eclipse.org/
  • 44. Why to create different classes in java ? 44 In java we can create different class with different names & write the programs(coding) under each class. Ie, separating group of statements and naming them This is used for identification & execution For example: if we are creating student mark storing application We need to create login page, signup page, section/dept/subject/sem selection page.
  • 45. Why to create different classes in java ? 45 Instead of writing all the codes in a single function, we can separate the programs using classes and write under it. Student mark store: Register page Login page Subject/sem/section selection Mark entry
  • 46. Why to create different classes in java ? 46
  • 47. Why to create different classes in java ? 47
  • 48. Why to create different classes in java ? 48
  • 49. Why to create different classes in java ? 49
  • 50. OOPS CONCEPT or OOPS FEATURES 50
  • 51. OOPS CONCEPT (or) OOPS FEATURES 51 CLASS Class is a collection of data members (variables) and methods(functions) A class can also be defined as a blueprint from which you can create an individual object. Collection of objects is called class The primary purpose of a class is to hold data/information. Class is a user defined data type. Class is declared with class name used as identifier.
  • 52. OOPS CONCEPT or OOPS FEATURES 52
  • 53. OOPS CONCEPT or OOPS FEATURES 53
  • 54. OOPS CONCEPT (or) OOPS FEATURES 54 OBJECT An Object can be defined as an instance of a class. An object contains an address and takes up some space in memory. Object invokes the members of the class
  • 55. OOPS CONCEPT or OOPS FEATURES 55
  • 56. OOPS CONCEPT (or) OOPS FEATURES 56 OBJECT In general, objects are real world entities For example, a chair, pen, table, keyboard, bike, etc. Each has its own state and behavior. EX: A dog is an object because it has states like color, name, etc. as well as behaviors like wagging the tail, barking, eating, etc.
  • 57. OOPS CONCEPT (or) OOPS FEATURES 57 INHERITANCE (Code reusability) It provides code reusability. Inheritance can be defined as the procedure or mechanism of acquiring all the properties and behavior of one class to another, i.e., acquiring the properties and behavior of child class from the parent class. Creating new class from existing class. Existing class is called parent class (super-class or base class) New class is called child class(subclass or derived
  • 58. OOPS CONCEPT or OOPS FEATURES 58
  • 59. OOPS CONCEPT or OOPS FEATURES 59
  • 60. OOPS CONCEPT (or) OOPS FEATURES 60 ENCAPSULATION (data hiding) (data secure)  It is also known as data hiding. Encapsulation is a process of wrapping code and data together into a single unit(ie,class) In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class.
  • 61. OOPS CONCEPT or OOPS FEATURES 61
  • 62. OOPS CONCEPT or OOPS FEATURES 62
  • 63. OOPS CONCEPT (or) OOPS FEATURES 63 ABSTRACTION Abstraction is a process of hiding the implementation details and showing only functionality to the user
  • 64. OOPS CONCEPT or OOPS FEATURES 64
  • 65. OOPS CONCEPT or OOPS FEATURES 65
  • 67. VARIABLES 67 A variable is a container which holds (or) stores the value Variable is a name of memory location. A variable is assigned with a datatype Example: int a = 20; int b = 10;
  • 68. RULES FOR DECLARING VARIABLES 68 Start with alphabet Special characters not allowed (@,$.{,},[,],. &..Etc) but underscore_ allowed Java keywords not allowed
  • 69. RULES FOR DECLARING VARIABLES 69
  • 70. RULES FOR DECLARING VARIABLES 70
  • 71. RULES FOR DECLARING VARIABLES 71
  • 72. TYPES OF VARIABLES 72 There are three types of variables in Java: local variable instance variable (global variable) static variable
  • 73. LOCAL VARIABLES 73 1) Local Variable A variable declared inside the body of the method is called local variable. You can use this variable only within that method and the other methods in the class aren't even aware that the variable exists. class A{ public static void main(String args[]) { int n = 90; //local variable } }
  • 77. INSTANCE VARIABLE 77 2)Instance Variable (global variable) A variable declared inside the class but outside the body of the method, is called instance variable class A{ int n = 90; //Instance variable public static void main(String args[]) { int a = 10 ; //Local variable } }
  • 79. STATIC VARIABLE 79 Static variable A variable which is declared as static is called static variable. It cannot be local. class A{ static int n = 90 ; // static variable public static void main(String args[]) { int a = 10 ; //Local variable } }
  • 80. STATIC VARIABLE 80 class A{ static int n = 90 ; public static void main(String args[]) { int n = 10 ; System.out.println(n); System.out.println(n); System.out.println(n); } } Output 90 10 10
  • 81. TYPES OF VARIABLE 81 class A { static int n = 90 ; // static variable int n = 90; //Instance variable public static void main(String args[]) { int a = 10 ; //Local variable } }
  • 82. DATATYPES 82  Data types are the types of data used in the program  When computer programs store data in variables, each variable must be assigned a specific data type. Some common data types include integers, floating point numbers, characters, strings, • Integer (int): 1, 2, 10,20,-1,-2(generally called numbers) • Float (float): 10.8, 12.02 (generally called decimal) • Character(char): a, b, c ( generally alphabets) • String (string): “raj”, “siva”, “vishnu” etc • double: 34674574, 7847584
  • 83. DATA TYPES IN JAVA 83 Data types represent the different values to be stored in the variable. In java, there are two types of data types: Primitive data types Non-primitive data types
  • 84. DATA TYPES IN JAVA 84
  • 85. PRIMITIVE DATA TYPES 85 Integer : byte, short, int and long data types are used for storing whole numbers. Floating point : float and double are used for fractional numbers. Character: char is used for storing characters(letters). boolean data type is used for variables that holds either true or false.
  • 86. INTEGER DATA TYPE 86 Integer data type are used for storing whole numbers. •Byte: The byte data type can store whole numbers from -128 to 127 Ex: byte a = 100; •Shot: Its value-range lies between -32,768 to 32,767 (inclusive). Its minimum value is -32,768 and maximum value is 32,767. Its default value is 0. Ex: short a = 5000;
  • 87. INTEGER DATA TYPE 87 • int: The int data type can store whole numbers from -2147483648 to 2147483647. In general, the int data type is the preferred data type when we create variables with a numeric value. EX: int b = 100000; • Long data type can store whole numbers from -9223372036854775808 to 9223372036854775807. This is used when int is not large enough to store the value Ex: long b = 15000000000L;
  • 88. FLOATING POINT DATA TYPE 88 Floating point data types are used for fractional numbers The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you should end the value with an "f": Ex: float a = 5.75f; The double data type can store fractional numbers from 1.7e−308 to 1.7e+308. Note that you should end the value with a "d": double a = 19.99d;
  • 89. FLOATING POINT DATA TYPE 89 Floating point data types are used for fractional numbers The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you should end the value with an "f": Ex: float a = 5.75f; The double data type can store fractional numbers from 1.7e−308 to 1.7e+308. Note that you should end the value with a "d": double a = 19.99d;
  • 90. CHARACTER DATA TYPE 90 The char data type is used to store a single character. The character must be surrounded by single quotes, like 'A' or 'c': Example: char b = 'B';
  • 91. BOOLEAN DATA TYPE 91 A boolean data type is declared with the boolean keyword and can only take the values true or false: Example: boolean a = true; boolean b = false;
  • 92. BOOLEAN DATA TYPE 92 A boolean data type is declared with the boolean keyword and can only take the values true or false: Example: boolean a = true; boolean b = false;
  • 93. NON-PRIMITIVE DATA TYPES 93 STRING A string is a sequence of characters separated by double quotes. String a = “Rajkumar"; CLASSES A class in Java is a blueprint which includes all your data. A class contains fields (variables) and methods to describe the behavior of an object
  • 94. NON-PRIMITIVE DATA TYPES 94 ARRAYS an array is a collection of similar elements(values) of the same data type int[] a = {1,2,3,4,5} String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
  • 95. OPERATORS 95  Operator is a symbol which is used to perform operations. For example: +, -, *, / etc..  Operators are used to perform operations on variables and values. In the example below, we use the + operator to add together two values: int x = 100 + 50; (+ is operator 100, 50 are values or operands) int z = x + y; (x, y are operands)
  • 96. OPERATORS 96  Arithmetic Operators  Assignment operators  Relational Operators or comparison operators  Logical Operators  Conditional operator  Increment & decrement operator
  • 97. ARITHMETIC OPERATORS 97  Arithmatic operators are used to perform addition, subtraction, multiplication, and division. They act as basic mathematical operations. Operator Description Example Result + Addition x=5+2 x=7 - Subtraction x=5-2 x=3 * Multiplication x=5*2 x=10 / Division x=5/2 x=2.5 % Modulus (division remainder) x=5%2 x=1
  • 98. ARITHMETIC OPERATORS 98 class arithmetic{ public static void main(String args[]){ int a=10; int b=5; System.out.println(a+b); //15 System.out.println(a-b); //5 System.out.println(a*b); //50 System.out.println(a/b); //2 System.out.println(a%b); //0 }}
  • 99. Assignment Operators 99  Assignment operators are used to assign values to JavaScript variables.  “=” is the assignment operator. the table below explains the assignment operators: Operator Example Same As Result = x=y x=5 += x+=y x=x+y x=15 -= x-=y x=x-y x=5 *= x*=y x=x*y x=50 /= x/=y x=x/y x=2 %= x%=y x=x%y x=0
  • 101. Comparison Operator (or) relational operators 101  Relational operators (or) Comparison operators are used to compare two values. Assume x=5 Operator Description Example > is greater than x>8 is false < is less than x<8 is true >= is greater than or equal to x>=8 is false <= is less than or equal to x<=8 is true == is equal to x==8 is false === is exactly equal to (value and type) x===5 is true x==="5" is false != is not equal x!=8 is true
  • 102. Comparison Operator (or) relational operators 102
  • 103. Logical operators 103  Logical operators are used to find out the relationship between two or more relational expressions or statements. Assume X=8 Y=5 Operator Meaning Example && AND (x < 10 && y > 1) is true || OR (x=5 || y=5) is false ! NOT !(x==y) is true
  • 105. Logical operators 105  Logical operators are used to find out the relationship between two or more relational expressions or statements. Assume X=8 Y=5 Operator Meaning Example && AND (x < 10 && y > 1) is true || OR (x>5 || y>10) is true ! NOT !(x==y) is true
  • 107. INCREMENT & DECREMENT OPERATOR Increment operator used to increment the value by one. “++” is the increment operator. • Decrement operator is used to decrement the value by one. - - is decrement operator operator meaning Example Result ++ Increment x=++5 x=6 operator meaning Example Result -- decrement x=--5 x=4
  • 108. TERNARY (OR) CONDITIONAL OPERATOR  The ternary operator (?) is also known as the conditional operator. This operator consists of three operands and is used to evaluate expressions. The goal of the operator is to decide, which value should be assigned to the variable. Example: a=15, b=20; X = (a>b) ? a : b; The value of X will be 20 if(a>b) X=a; else X=b;
  • 109. JAVA COMMENT LINES (// & /* */)  Comments can be used to explain Java code, and to make it more readable.  Any text between // and the end of the line is ignored by Java (will not be executed).  It can also be used to prevent execution when testing alternative code.  Single-line comments (//)  Multi-line Comments ( /* */)
  • 110. JAVA COMMENT LINES (// & /* */) SINGLE –LINE COMMENTS • Single-line comments start with two forward slashes (//). • Any text between // and the end of the line is ignored by Java (will not be executed). Example: System.out.println("Hello World"); // This is a output statement
  • 111. JAVA COMMENT LINES (// & /* */)
  • 112. JAVA COMMENT LINES (// & /* */) MULTIPLE COMMENT LINES • Multi-line comments start with /* and ends with */. • Any text between /* and */ will be ignored by Java.
  • 113. JAVA COMMENT LINES (// & /* */)
  • 121. CONSTRUCTOR 121 It is a special type of method (function) called automatically when we create an object of class. We can’t call explicitly. Constructor name must be the same as its class name It is a special type of method which is used to initialize(set up value) the object. It is called constructor because it constructs the values at the time of object creation a constructor is a block of codes similar to the method(function).
  • 122. CONSTRUCTOR TYPES 122 There are two types of constructors in Java: Default constructor (no-arg constructor) Parameterized constructor
  • 123. CONSTRUCTOR TYPES 123 Default constructor A constructor is called "Default Constructor" when it doesn't have any parameter. class Bike1 { Bike1() { System.out.println("Bike is created"); } public static void main(String args[]) { Bike1 b = new Bike1(); } }
  • 124. CONSTRUCTOR TYPES 124 Parameterized constructor A constructor which has a specific number of parameters is called a parameterized constructor.
  • 125. CONSTRUCTOR TYPES 125 class Student4 { int id; String name; Student4 (int i, String n) { id = i; name = n; System.out.println(id+" "+name); } public static void main(String args[]) { Student4 s1 = new Student4(111,"Karan"); } }
  • 126. PACKAGES 126 A package in java is a collection of classes (or) group of classes Using package it becomes easier to locate the related classes and it also provides a good structure for projects with hundreds of classes and other files. import package.name.class; import package.name.*; import java.io.*; (display inuput/output) import java.util.*; (time , date, calender)
  • 127. PACKAGES 127 Types of Packages Built-in Package: Existing Java package for example java.applet, java.util , java.awt etc. User-defined-package: Java package created by user to categorize their project's classes and interface
  • 131. INHERITANCE 131 INHERITANCE (Code reusability) It provides code reusability. Inheritance can be defined as the procedure or mechanism of acquiring all the properties and behavior of one class to another, i.e., acquiring the properties and behavior of child class from the parent class. Creating new class from existing class. Existing class is called parent class (super-class or base class) New class is called child class(subclass or derived
  • 134. INHERITANCE 134 INHERITANCE (Code reusability) Inheritance is one of the key features of Object Oriented Programming. Inheritance provided mechanism that allowed a class to inherit property of another class. When a Class extends another class it inherits all non-private members including fields and methods.  Inheritance in Java can be best understood in terms of Parent and Child relationship, also known as Super class(Parent) and Sub class(child) in Java language. extends is a keyword are used to describe inheritance in Java.
  • 135. INHERITANCE 135 Terms used in inheritance Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class. Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class. Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in previous class. Extends: It is a keyword used in inheritance
  • 136. TYPES OF INHERITANCE IN JAVA 136 SINGLE INHERITANCE MULTILEVEL INHERITANCE HEIRARCHICAL INHERITANCE