0% found this document useful (0 votes)
16 views50 pages

BSC MPCS Vth Sem Java Unit 1

The document provides an introduction to Java, covering its essentials, features, and the fundamentals of object-oriented programming (OOP). It discusses key concepts such as classes, objects, inheritance, polymorphism, and data encapsulation, along with the Java Virtual Machine and the Java Development Kit. Additionally, it outlines the structure of a Java program, including documentation, package, import statements, and the main method.

Uploaded by

MS Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views50 pages

BSC MPCS Vth Sem Java Unit 1

The document provides an introduction to Java, covering its essentials, features, and the fundamentals of object-oriented programming (OOP). It discusses key concepts such as classes, objects, inheritance, polymorphism, and data encapsulation, along with the Java Virtual Machine and the Java Development Kit. Additionally, it outlines the structure of a Java program, including documentation, package, import statements, and the main method.

Uploaded by

MS Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

1

Unit – I

Introduction: Java Essentials, JVM, Java Features, Creation and Execution of


Programs, Data Types, Type Conversion, Casting, Conditional Statements,
Loops, Branching Mechanism, Classes, Objects, Class Declaration, Creating
Objects, Method Declaration and Invocation, Method Overloading,
Constructors–Parameterized Constructors, Constructor Overloading, Cleaning-
up unused Objects, Class Variables & Methods-static Keyword, this Keyword,
One-Dimensional Arrays, Two-Dimensional Arrays, Command-Line Arguments,
Inner Class.
Inheritance: Introduction, Types of Inheritance, extends Keyword, Examples,
Method Overriding, super, final Keywords, Abstract classes, Interfaces,
Abstract Classes Verses Interfaces.

NDC KKT

MS bhanu
2
INTRODUCTION TO JAVA
Java is a high-level, third generation programming language, like C, FORTRAN, Smalltalk, Perl, and
many others. You can use Java to write computer applications that play games, store data or do any of the
thousands of other things computer software can do. Compared to other programming languages, Java is
most similar to C. However although Java shares much of C's syntax, it is not C. Knowing how to program
in C or, better yet, C++, will certainly help you to learn Java more quickly, but you don't need to know C to
learn Java. A Java compiler won't compile C code, and most large C programs need to be changed
substantially before they can become Java programs. What's most special about Java in relation to other
programming languages is that it lets you write special programs called applets that can be downloaded from
the Internet and played safely within a web browser. Java language is called as an Object-Oriented
Programming language and before begining for Java, we have to learn the concept of OOPs(Object-Oriented
Programming).
BASIC CONCEPT OF OOPS (OBJECT-ORIENTED PROGRAMMING):
There are some basic concepts of object oriented programming as follows:
1. Object
2. Class
3. Data abstraction
4. Data encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic binding
1. Object
Objects are important runtime entities in object oriented method. They may characterize a location, a
bank account, and a table of data or any entry that the program must handle.
For example:

2. Classes
A class is a set of objects with similar properties (attributes), common behaviour (operations), and
common link to other objects. The complete set of data and code of an object can be made a user defined
data type with the help of class.
The objects are variable of type class. 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

MS bhanu
been defined, we can make any number of objects belonging to that class. Each object is related with the
data of type class with which they are formed. 3

3. Data Abstraction
Data abstraction refers to the act of representing important description without including the
background details or explanations.
Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, cost
and functions operateon these attributes. They summarize all the important properties of the objects that are
to be created.
4. Data Encapsulation
Data Encapsulation means wrapping of data and functions into a single unit (i.e. class). It is most
useful feature of class. The data is not easy to get to the outside world and only those functions which are
enclosed in the class can access it.
These functions provide the boundary between Object‟s data and program. This insulation of data
from direct access by the program is called as Data hiding.

5. Inheritance
Inheritance is the process by which objects of one class can get the properties of objects of another class.
Inheritance means one class of objects inherits the data and behaviors from another class. Inheritance
maintains the hierarchical classification in which a class inherits from its parents.
Inheritance provides the important feature of OOP that is reusability. That means we can include
additional characteristics to an existing class without modification. This is possible deriving a new class
from existing one.

MS bhanu
4

6. Polymorphism
(Poly means “many” and morph means “form”).
Polymorphism means the ability to take more than one form. Polymorphism plays a main role in allocate
objects having different internal structures to share the same external interface. This means that a general
class of operations may be accessed in the same manner even though specific activities associated with each
operation may differ. Polymorphism is broadly used in implementing inheritance.

7. Dynamic Binding
Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic
binding means that the code related with a given procedure call is not known until the time of the call at run
time. Dynamic binding is associated polymorphism and inheritance.
JAVA HISTORY:
Java is a general-purpose, object-oriented programming language developed by Sun Microsystems of USA
in 1991.Originally called Oak by James Gosling (one of the inventor of the language). Java was invented for
the development of software for consumer electronic devices like TVs, tasters, etc. The main aim had to
make java simple, portable and reliable.
Following table shows the year and beginning of Java.

MS bhanu
5

JAVA FEATURES:
Java is an object oriented programming language developed by Sun Microsystems of USA in 1991. Java is
first programming language which is not attached with any particular hardware or operating system.
Program developed in Java can be executed anywhere and on any system. Features of Java are as follows:
1. Compiled and Interpreted
2. Platform Independent and portable
3. Object- oriented
MS bhanu
4. Robust and secure 6

5. Distributed
6. Familiar, simple and small
7. Multithreaded and Interactive
8. High performance
9. Dynamic and Extensible
1. Compiled and Interpreted
Basically a computer language is either compiled or interpreted. Java comes together both these
approach thus making Java a two-stage system.
Java compiler translates Java code to Byte code instructions and Java Interpreter generate machine
code that can be directly executed by machine that is running the Java program.
2. Platform Independent and portable
Java supports the feature portability. Java programs can be easily moved from one computer system
to another and anywhere. Changes and upgrades in operating systems, processors and system resources will
not force any alteration in Java programs. This is reason why Java has become a trendy language for
programming on Internet which interconnects different kind of systems worldwide. Java certifies portability
in two ways.
First way is, Java compiler generates the byte code and that can be executed on any machine. Second way is,
size of primitive data types are machine independent.
3. Object- oriented
Java is truly object-oriented language. In Java, almost everything is an Object. All program code and
data exist in objects and classes. Java comes with an extensive set of classes; organize in packages that can
be used in program by Inheritance. The object model in Java is trouble-free and easy to enlarge.
4. Robust and secure
Java is a most strong language which provides many securities to make certain reliable code. It is
design as garbage – collected language, which helps the programmers virtually from all memory
management problems. Java also includes the concept of exception handling, which detain serious errors and
reduces all kind of threat of crashing the system. Security is an important feature of Java and this is the
strong reason that programmer use this language for programming on Internet.
The absence of pointers in Java ensures that programs cannot get right of entry to memory location
without proper approval.
5. Distributed
Java is called as Distributed language for construct applications on networks which can contribute
both data and programs. Java applications can open and access remote objects on Internet easily. That means
multiple programmers at multiple remote locations to work together on single task.
6. Simple and small
Java is very small and simple language. Java does not use pointer and header files, goto statements,
etc. It eliminates operator overloading and multiple inheritance.
MS bhanu
7. Multithreaded and Interactive 7
Multithreaded means managing multiple tasks simultaneously. Java maintains multithreaded
programs. That means we need not wait for the application to complete one task before starting next task.
This feature is helpful for graphic applications.
8. High performance
Java performance is very extraordinary for an interpreted language, majorly due to the use of
intermediate bytecode. Java architecture is also designed to reduce overheads during runtime.
The incorporation of multithreading improves the execution speed of program.
9. Dynamic and Extensible
Java is also dynamic language. Java is capable of dynamically linking in new class, libraries,
methods and objects. Java can also establish the type of class through the query building it possible to either
dynamically link or abort the program, depending on the reply. Java program is support functions written in
other language such as C and C++, known as native methods.
COMPARISON IN JAVA AND C++

MS bhanu
8

JAVA VIRTUAL MACHINE:


All programming language compilers convert the source code to machine code. Same job done by Java
Compiler to run a Java program, but the difference is that Java compiler convert the source code into
Intermediate code is called as byte code. This machine is called the Java Virtual machine and it exits only inside
the computer memory.
Following figure shows the process of compilation.

The Virtual machine code is not machine specific. The machine specific code is generated. By Java
interpreter by acting as an intermediary between the virtual machine and real machines shown
Below

Java Object Framework act as the intermediary between the user programs and the virtual machine which
in turn act as the intermediary between the operating system and the Java Object Framework.
MS bhanu
9

Java Environment:
Java environment includes a large no. of development tools, and hundreds of Classes, And methods. (Flow
functions of streams). Java development tools are part of the system known as java development kit and the
classes and methods are part of java standard library (JSL). (or) Application program interface (API).
Java development kit:
The JDK comes with collection of tools that are used for developing and running java programs. They
include
 Applet viewer (for viewing java applets)
 Java c (java compiler)
 Java (java interpreter)
 Java p (java dis assembler)
 Java h (for c header files)
 Java doc(for creating HTML documents)
 Job (java de bugger)
Flowchart representation for Java Program:

Text editor

Java source code Java doc HTML files

Java c

Java class file Java h Header files

Java Jdb

Java program out put

MS bhanu
Evolution of java 10

Java program structure:


Java is a general purpose object oriented programming language it has many classes and methods. Classes
contain data members and methods. Java program may contain one or more sections. Every section has its
own definition and importance. The total java program will be divided into six sections. In those sections
some are optional and some are compulsory. Those 6 sections are
DOCUMENTATION SECTION
PACKAGE SECTION
IMPORT STATEMENTS
INTERFACE STATEMENTS
CLASS DEFINITION
main method class
{
main method definition
}

Documentation section;-
The documentation section is collection of comment lines giving the name of the program. Comments must
explain while, how, program executes, statements used. In java there are two types of comment lines.
1) Single line comment.
2) Multiple line comment.
//this is fixed program-single.
/*------------
------------*/ multiple.
Package section:
The first statement allowed in java file is package. This statement declares a package name and informs the
compiler that the classes defined here belong to this package. This section is optional it requires when
defines a package in the program.
Package package name.
Import statement:
This statement is use to import the methods or library files. It is similar to #include statement in “C”. This
statement should start with import keyword followed by class name. Method name import class name.
Method name;
Ex: import student text;

MS bhanu
11
Interface:
An interface is like a class but includes groups of method declarations. This is also an optional section and
is used only when user with to implement multiple inheritance.
Class definition
A java program may contain multiple class definitions. Classes are primary and essential elements of java
program. A simple java program may contain class definition. These classes are used to map the objects of
real world programs. The no. of classes used depends on the complexity of the program.
Main method class:
Since every java standalone program requires main method as its starting point. This is the essential part of
java program. Every program must contain this statement main is the heart of the java program.

Implementing java program;


Implementing of java application program involves a series of steps those are
1) creating the program
2) compiling the program
3) running the program
Creating the program:
We can create a program using any text editor. We must save the program in a file name with the extension
dot java. This file called as source file. Java source file must have the extension dot java.
Compiling the program:
To compile the program we must run java compiler java c. with the name of the source file on command
line.
Ex: C:\>javac filename.java
C:\>java filename
The java c compiler crates a byte code program with the extension class.
Ex:cno.class
Compiler automatically creates the names of byte code files.
Diagram Source code

Java compiler

Byte code

Windows ABC
ABC
interprete
interprete interprete
d
r d
Machine Machine
code Machine
code
code

Windows computer Machine code


ABC Computer

MS bhanu
12
Running the program
We need to use java interpreter to run a stand alone program. To run the program used the java interpreter
file java along with file name with or without extension.
Ex C:\>javac cno.java
Cno.class
C:\>java cno
Running

Constants, variables and Data type:


Constants:
Constant in java refer to feed values that don‟t change during the program execution. Java supports different
types of constants. There are mainly two types of java constants.
Those are.
1) numeric constants
2) character constant
Numeric constant:
The constant which refers with digits (or) numbers known as numeric constants there are 2 types of numeric
constants. There are
1) integer constant
2) character constant
1. Integer Constant:
An integer constant refers to a sequence of digit there are 3 types of integer constants.
1) Decimal integer Ex: 123,321,0….
2) Octal integer Ex: 23.345,45.56
3) Hexa-decimal integer. Ex: 0x2,0x9F.
Real constants:
Integer number are in adequate to represent quantities, distance, height, weights and etc. these all these
quantities must be accompanied with a fractional part. A constant with the combination of integer &
fractional part known as real constant. The real constants also known as floating points are floating
constants.
Character constants:
The constants which interacts with alphabets. Numbers and special characters known as character constants
there are two types of character constants.
1) Single character constant
2) String constant
Single character constant
A single character constant contains a single character enclosed with in a pair of single quote marks

MS bhanu
Ex: „A‟ 13

„O‟
„,‟
„q‟
String constants:
The string constants contain a single character (or0 group of characters enclosed in pair of double quotation
mark.
Ex “gayathri”
“ 932 ”
“ CNU ”
“ A ”, “ + “
Back slash character constant:
The constants that are non-printable, i.e. they are not displayed on the screen or in a
printer are called as escape sequences. They are also known as backslash character constants and are used in
output functions. Some commonly used escape sequences are listed below.
Escape sequences character escape sequences character
\o null \r carriage return
\a alarm (bell) \” quotation mark (“)
\b blank space \‟ apostrophe (\)
\t horizontal tab \? Question mark (?)
\n new line \\ back slash (\)
\v vertical tab \ooo octal number
\f form feed \xhh hexadecimal number

Variables:
A variable is an identifier that denotes a storage location used to store the data value. It is
an identifier which may vary during the program execution. A variable name can be chosen by the
programmer is a meaningful way so that it is good to understand the program.
Rules for naming variable:
1) Variable name may consist of alphabets, digits, and underscore and dollar character.
2) They must no begin with digit.
3) It should not be a key word.
4) It should not allow any spaces and special characters.
5) Variable names can be of any length.
6) Upper cases and lower cases are distinct. (Difference)

MS bhanu
14
Data types:
Every variable in java has a data type. Data types specify the size and type of values that
can be stored. Java language is rich in its data types. Those are
1) Primitive data types/ built in data types.
2) Non-primitive data types/ derived data types.

Java data types

Primitive/built-in intrinsic data Non-primitive/derived


types (ADTS) data types

Numeric Non-numeric Classes Interface Arrays

Integer Floating Character Boolean

Integer:
Integer type can hold whole numbers without having without having fractional part. Java does not support
unsigned types of integers. But here in java the integer can be represented in different ways. They are
1) Byte
2) Short
3) Int
4) Long.
These data types have different qualities sizes and ranges. Those are

Integer

Byte Short Int Long

Type size minimum maximum

byte 1 -128 127

short 2 -32,768 32,767

int 4 -2,147,483,648 2,147,483,647

long 8 -9,22,3,372,036,884,778808 9,223,372,036,884,778,807

MS bhanu
Floating type: 15

Integer type can hold only whole numbers but some times there are numbers containing with
fractional parts such as quantity, height, weight and etc. these fractional parts known as floating type data
type. There are two types of floating point storages in java. There are
1) Float and Double.
These floating point data types have different sizes, range of floating numbers. Those are.
Type size minimum maximum

Float 4 3.4e-038 3.4e+0.38

Double 8 1.7e-308 1.7e+308

Character type:
In order to store character constants in memory java provides a character data type called “Char”.
The char type assumes size of 2bytes. But basically it can hold a single character.
Boolean:
Boolean type is used when we want to test a particular condition during the execution of the
program. The Boolean returns only one result either true or false. Boolean type is denoted by the key word
Boolean. And it uses only one bit of storage.
Read statement (or) input statement:
In java the variable values can be interactively read through the keyboard using, read line ( ) method.
Reads the input from the keyboard as a string which is then converted to corresponding data type using a
data type wrapper class.
Syntax
Variable name = wrapper class (in. read line ( ));
Output statement:
A computer program is written to manipulate given set of data and display (or) print the result java
supports two output methods that can be used to send the result screen. Those are
1) Print ( ) : it will print output & wait for the next line.

2) Println ( ) : it will print line of text and moves to next line.

These output methods must be used along with its own base class.
Syntax:
System. Out. Print (“welcome to java”);
System. Out. Println (“welcome to gayathri”);

MS bhanu
Following program shows the use of data types. 16
Program:
import java.io.DataInputStream;
class cc2
{
public static void main(String args[]) throws Exception
{
DataInputStream s1=new DataInputStream(System.in);
byte rollno;
int marks1,marks2,marks3;
float avg;
System.out.println("Enter roll number:");
rollno=Byte.parseByte(s1.readLine());
System.out.println("Enter marks m1, m2,m3:");
marks1=Integer.parseInt(s1.readLine());
marks2=Integer.parseInt(s1.readLine());
marks3=Integer.parseInt(s1.readLine());
avg = (marks1+marks2+marks3)/3;
System.out.println("Roll number is="+rollno);
System.out.println("Average is="+avg);
}
}
Output:
Enter roll number:
07
Enter marks m1, m2,m3:
66
77
88
Roll number is=7
Average is=77.0
Type casting:
Type casting is the process of storing the one type of value in another type of variable. In such
situation we must cast the value to be stored by proceeding with its type name with in parenthesis.
Syntax:
type vaiable1=(type) variable2;
Ex: int x; a=10;
byte y; y=(int)x;

MS bhanu
17
byte y = (int) x;
There are some data types can be casted (converted) into smaller type may result in loss of data. Similarly
float and double can be cast to any other type except Boolean.
From To
Byte short, char, int, long, float, double
Short int, long, float, double
Char int, long, float, double
Int long, float, double
Long double
Float double

Automatic conversion:
It is possible to assign a value of one type to a variable of different type without cast. Java does the
conversion of the assigned values automatically. This is known as automatic type conversion.
Ex: int x;
byte y;
x=y;
x=(byte)y;
Symbolic Constants:
These constants may appear repeatedly in a no. of places in the program. Representing the values of
the mathematical constant by a special symbol is known as symbolic constants. Generally a user faces two
problems in subsequent use of symbolic constants. Those are
1. Problem in modification of the program.
2. Problem in understanding the program.
Ex: p=35;
If(m1>=35 && m2>=35 && m3>=35)
If(m1>=p && m2>=p && m3>=35)

Operators:
Java supports a rich set of operators. An operator is a symbol that tells the computer to perform certain
mathematical or logical manipulation. Operators are used in programs to manipulate data and variables.
They usually form a part of mathematical or logical expressions.
Java operators can be classified into 8 categories.
Those are
1) Arithmetic operators
2) Relational operators
3) Logical operators
4) Assignment operators

MS bhanu
5) Increment/ decrement operators 18
6) Conditional operators
7) Bitwise operators
8) Special operators.
Arithmetic operators:
Java has all the basic arithmetic operators. The various arithmetic operators are shown below.
Operator Meaning
+ Addition
- Substraction
* Multiplication
/ Division
% modular
Now the following programs show the use of arithmetic operators.
import java.io.DatainputStream.*;
Class arts
{
Public static void main(String args[])
{
DatainputStream in=new DatainputStream(System.in);
int a,b,sum,sub,rem,mul;
float div;
System.out.println(“enter a, b values”);
a=Integer.parseInt(in.readLine());
b=Integer.parseInt(in.readLine());
sum=a+b;
sub=a-b;
mul=a*b;
div=a/b;
rem=a%b;
System.out.println(“sum value is”+sum);
System.out.println(“sub value is”+sub);
System.out.println(“mul value is”+mul);
System.out.println(“div value is”+div);
System.out.println(“rem value is”+rem);
}
}

MS bhanu
Relational operators: 19

Relational operators are symbols that are used to test the relationship between two variables or between a
variable and a constant.
Operator Meaning
> Greater than
< Less than
>= Greater than or equal

<= Less than or equal

== Comapare
Example Program:
import java.io.DatainputStream.*;
Class Rel
{
Public static void main(String args[])
{
DatainputStream in=new DatainputStream(System.in);
int a,b;
System.out.println(“enter a, b values”);
a=Integer.parseInt(in.readLine());
b=Integer.parseInt(in.readLine());
System.out.println(a<b);
System.out.println(a>b);
System.out.println(a<=b);
System.out.println(a>=b);
System.out.println(a==b);
System.out.println(a!=b);
}
}
Output:
0 1 0101
Logical operator:
This operator that is used to combine two or more relational expressions is called logical operator. These
operators are used to test more than one condition at a time.
Operator Meaning
&& AND
|| OR
! NOT

MS bhanu
P Q P && Q P Q P || Q !P !Q 20
T T T T T T F F
T F F T F T F T
F T F F T T T F
F F F F F F T T
Assignment operator:
Assignment operators are used to assign the results of an expression to a variable. The most commonly used
assignment operator is “=”. It may be written in the form;
Variable_name binary_operator = expression
Following table show the use of assignment operators.

.
import java.io.*;
class Assoptr
{
public static void main (String args[])
{
int a = 10;
int b = 30;
int c = 30;
a+=1;
b-=3;
c*=7;
System.out.println("a = " +a);
System.out.println("b = "+b);
System.out.println("c = "+c);
}
}
Output:
a = 11
b = 18
c = 310
Increment/decrement operator;-
The increment operator ++ adds 1 to a variable. Usually the variable is an integer type, but it can be a
floating point type. The two plus signs must not be split by any character. Usually they are written
immediately next to the variable.
Following table shows the use of operators.

MS bhanu
Expression Process Example end result 21
Add 1 to a variable int A=10,B; A=11
A+ +
after use. B=A++; B=10
Add 1 to a variable int A=10,B; A=11
+ +A
before use. B=++A; B=11
Subtract 1 from a int A=10,B; A=9
A- -
variable after use B=A--; B=10
Subtract 1 from a int A=10,B; A=9
--A
variable before use. B=--A; B=9
import java.io.*;
class IncDecOp
{
public static void main(String args[])
{
int x=1;
int y=3;
int u;
int z;
u=++y;
z=x++;
System.out.println(x);
System.out.println(y);
System.out.println(u);
System.out.println(z);
}
}
Output:
3441
Conditional operator;- Simple conditional operations can be carried out with the conditional operator (? ;).
An expression that uses conditional operator is called as conditional expression.
Expression 1? Expression 2; expression 3; when evaluating a conditional expression, expression1 is
evaluated first. If expression 1 is true then expression 2 is evaluated. If expression 1 is false then expression
3 is evaluated. The main advantage of conditional operator is ;
 It is short form of if-else statement.
 It is not necessary that only arithmetic statements should follow the conditional operator.
For example:
A=3;
B=4;
C=(A<B)?A:B;
C=(3<4)?3:4;
C=3

MS bhanu
22
Example Program:
import java.io.DatainputStream.*;
Class conditional
{
Public static void main(String args[])
{
DatainputStream in=new DatainputStream(System.in);
int a,b,c;
System.out.println(“enter a, b values”);
a=Integer.parseInt(in.readLine());
b=Integer.parseInt(in.readLine());
c=a>b?40:50;
System.out.println(“C value is”+c);
}
}
OUTPUT:
Enter a , b values
20 30
C Value in 50
Bitwise operator:
Java has certain operators known as bitwise operators that are used for manipulation of
data at bit level. They are used to test the bits (or), shift them from right (or) left. These operators can
operate only on integers and characters but not on floats and doubles. These operators are explicit system
dependent.

Operator Meaning

~ One‟s complement

<< Left shift

>> Right shift

& Bitwise And

| Bitwise Or

! Bitwise Not

^ Exclusive OR

Special operators:
Java supports some special operators of interest such as, instance of and
(.) operator

MS bhanu
23
Instance of:
The instance of is an object reference operator and return true value if the objects on left hand side is an
instance of the class given on R.H.S this operator allows us to determine weather the object belongs to a
particular class or not
Ex: person instance of student
True
X instance of student;
False
Dot operator:
The dot operator is used to access the instance variables and methods of the class. It is also used to access
classes and sub packages from the package
Scope Resolution operator: (: :)
This operator is known as scope resolution operator. this is use to reference between the
class name and methods.
Ex:
class name class name scope resolution operator method name.

Control structures
Java is too must able to perform different sets of actions depending on the circumstances. Many times, we
want a set of instructions to be executed is one situation, and an entirely different set of instructions to be
executing in one situation, and an entirely different set of instructions to be executing in another situation.
This kind of situation is dealt in java-programs using a control instruction can be implemented in java using:

1) Sequential (or) decision making & branching statements (if, if else, if else if, switch case, continue)
2) Iteration/Repetition statements (while, do while, for)
1.If
This is a one way conditional statement. It is used to execute a set of statements only when the condition is
TRUE or satisfied.

Syntax:
if (condition)
{
Statements;
}
Ex:- public class Test
{
public static void main(String args[])
{
int x = 10;
if( x < 20 )
{
System.out.print("This is if statement");
}
}
}
OUTPUT: This is if statement

MS bhanu
2.If else 24
It is used to execute a set of statements only when the condition is TRUE. When the condition is FALSE, it
displays statements else part.

Syntax: start
If (condition)
{
Statements; yes cond
no
}
else
{ Statements
Statements
Statements;
} STOP

For example: write a program to check whether the number is divisible by 2 or not.
import java.io.*;
class divisorDemo
{
public static void main(String[ ] args)
{
int a =11;
if(a%2==0)
{
System.out.println(a +" is divisible by 2");
}
else
{
System.out.println(a+" is not divisible by 2");
}
}
}
Output:
11 is not divisible by 2
3.If else If (Nested If else)
In this we may have to use more than if else statement is called if else if.

Syntax:
if(condition-1)
{
Statements;
}
else if(condition-2)
{
Statements;
}

MS bhanu
else if(condition-n) 25
{
Statements;
}

Nested if/Ladder If:


The if statement with in another if is called Nested if/Ladder if Here a condition with in another
condition will be checked till it satisfies the condition.
Syntax:
If(expression)
{
if(expression)
{
---
}

else
{
---
---
}
}
else
{
If(expression)
{
----
----
Else
{
----
----
}
}
For example: Write a program to find out greatest number from three numbers.
import java.io.*;
class greatest
{
public static void main (String args[ ])
{
int a=10;
int b=20;
int c=3;
if(a>b)
{
if(a>c)
{
System.out.println("a is greater number");
}

MS bhanu
else 26

{
System.out.println("c is greater number");
}
}
else
{
if(c>b)
{
System.out.println("c is greater number");
}
else
{
System.out.println("b is greater number");
}
}
}
}
Output:
b is greater number
Switch case

Java has built in multi way decision statement known as switch case. Mainly it is used to built menu driven
programs
Switch:
The switch statement tests the value a given variable (expression) against a list of case values.
Case:
The value it gives is then matched a block of statement associated with that case is executed. Every case
statement is terminated by (:) colon.
Break:
It is used to terminate or come out the switch statement when the expression matches with any one of the
cases.
Default
If the choice is out of range the statements will be defined in default block.

Syntax
Switch (expression)
{
Case <option-1>:
Statements;
break;
Case <option-2>:
Statements;
break;

MS bhanu
------------------ ------------ 27

Case <option-n>:
Statements;
break;
default:
Statements;
}
For example: Write a program for Switch Case.
import java.io.DatainputStream;
class swcase
{
public static void main(String args[])
{
int n;
DatainputStream in=new DatainputStream(System.in);
System.out.println(“Enter the N value”);
n=Integer.parseInt(in.Readline());
switch(n)
{
case 1:
System.out.println(“ Monday”);
break;
case 2:
System.out.println(“ Tuseday”);
break;
case 3:
System.out.println(“ Wed.day”);
break;
case 4:
System.out.println(“ Turseday”);
break;
case 5:
System.out.println(“ Friday”);
break;
case 6:
System.out.println(“ Saturday”);
break;
case 7:
System.out.println(“ Monday”);
break;
default:
System.out.println(“ Wrong Enter Value”);
}
}
}
Loops
Loop is nothing but a group of statements it is used to execute a set of statements repeatedly or until a
particular condition is being satisfied.

There are 3 methods by way of which we can repeat a part of a program


1) While
2) Do while
3) For
4)
MS bhanu
1.While 28
It is a conditional entry loop. It is used execute a set of statements repeatedly when the condition is TRUE,
when the condition becomes FALSE it comes out of the loop.
Syntax:
while(condition)
{
statement-1;
statement-2;
statement-n;
}
Ex:
int n=1;
while(n<=10)
{
System.out.print(n);
n++;
}
For example: Write a program to display 1 to 10 numbers using while loop.
import java.io.*;
class number
{
public static void main(String args[]) throws Exception
{
int i=1;
System.out.println("list of 1 to 10 numbers");
while(i<=10)
{
System.out.println(i);
i++;
}
}
}
Output:
C:\MCA>javac number.java
C:\MCA>java number
list of 1 to 10 numbers
1 2 3 4 5 6 7 8 9 10
2.do while
In do-while loop, first attempt of loop should be execute then it check the condition. The benefit of
do-while loop/statement is that we get entry in loop and then condition will check for very first time. In
while loop, condition will check first and if condition will not satisfied then the loop will not execute.

MS bhanu
Syntax: 29
do
{
Statements;
}
While (condition);
Difference between while & do while loop

While Do while
1. In this loop the condition is checked 1. In this loop the condition is checked
before the statements after the statements
2. The minimum no of execution of 2. The minimum no. of execution of
statements in while loop is zero statements in do while loop is one.
3.For loop
It is a easiest loop in this loop we can define initial value, condition, increment or decrement in a single
statement, divide with semi colon

Syntax:
for (initial value ; condition ; increment/decrement)
{
Statements;
}

2. for(;condition;)
Ex
int i;
for (i=1; i<10; i++)
{
System.out.print(i);
}
For example:
import java.io.*;
class number
{
public static void main(String args[]) throws Exception
{
int i;
System.out.println("list of 1 to 10 numbers");
for(i=1;i<=10;i++)
{
System.out.println(i);
}
}
}

MS bhanu
Output: 30
C:\MCA>javac number.java
C:\MCA>java number
list of 1 to 10 numbers
1 2 3 4 5 6 7 8 9 10
Nested loops: A loop with in another loop is called nested loop. Java supports all looping statements have
nested loops when the outer loop condition becomes true. It enters to the inner loop. When inner loop
executed for every termination of inner loop the condition will be checked.

Class:
A class is a user defined data type with template that serves to define its properties. Class is collection of key
fields and methods. Class is collection of members. The members are either fields (or) methods. Class is an
abstract data type. The concept of creating class is to encapsulate the members into a single unit for multiple
usage class is a abstract data type.
Syntax:
Class classname
{
Field declaration;
Method declaration;
}
Note: the data which is included in square brackets is optional. Extend keyword is use to create inheritance
between the base class & derived class. (or) sub class & super class.
Class class name class class name{ }
{

}
The class which is not having fields & methods (or) no class body is called empty class.
Field declaration:
Data is encapsulated in a class by placing the fields in class body. These fields are called class member
variables (or) instance variables (or) variables. Because they are created when ever an object of the class is
instantiated.
The general syntax of field declaration is similar to ordinary variable declaration.
Syntax:
Data type field name;
Data type field name1, field name2,……….;
Ex; int x;
Int x,y,z;

MS bhanu
Note: When fields are declared those must be separated by comma operator. 31
Method declaration; Methods are set of statements or collection of executable statements to perform a
specific task. In java to perform a specific task the methods will be created. Without methods there is no life
for the class.
The method declaration is as similar as function declaration. The general syntax is,
return type method name (parameter-list)
{
method body;
}
Generally method declaration has 4 parts in java. Those are
1) return type
2) method name
3) parameters list
4) method body.
Return type;
There are different types of data types will be returned after end of the method. Those return types
are 1) int, char, float . if a method is not returning any value (or) if it is returning null value then void is
used.
Method name: It is a valid identifier in java. The method name is used to execute the group of statements
encorporated in method.
Parameters list: If the method type is method with parameter then parameters list must be written in
parenthesis. The parameters along with its own data type. Must be given in parenthesis.
When multiple parameters will be given those must be separated by comma.
Method body: The statements in between opening & closing braces are called method body. The method
body statements will be includes input (output statements, executable statements, control flows and return
type. If it is a return type method.
Return type; The statement return is used to return the value to the calling part of the program. Thesyntax
is, return variable name;
Ex: return x;
Method over loading: In java it is possible to create methods that have the same name but different
parameters list and different definitions. This is called method over loading. This is the concept of
polymorphism.
In method over loading the compiler will identify and execute the methods based on following 3
conditions. Those conditions are
1) based on no. of arguments
2) based on type of arguments
3) based on sequence of arguments

MS bhanu
Ex: 32
class stud
{
int a, b;
float x, y;
a=10;
b=20;
a=2.5;
y=3.0
System.out.println(sum(a,b));
System.out.println (sum(x,y));
System.out.println (sum(a,x));
void sum (in a, int b)
{
System.out.println (a+b);
}
void sum (int a, float x);
{
System.out.println(a+x);
}
void sum (float x, floaty);
{
system.out.println(x+y);
}
}
Object: objects are the instances of classes. In java objects are created using new operator. The new
operator creates objects of the specified class and returns a reference to that object. An object in java
essentially a block of memory that contains space to store the instance of variable.
It is important to understand that each object has its own copy of instance variable of its class. It
means a class may refer any no. of objects. The syntax is
Class name object name;
Ex; nesting n;
Nesting n=new nesting (10,11);
class marks
{
int m1, m2, m3 tot, arg;

MS bhanu
marks(intx, inty intz) 33
{
m1=x;
m2=y;
m3=z;
}
Void calc( )
{
tot = m1+m2+m3;
avg=tot/3;
}
Void disp( )
{
System.out.println (“total marks are=” +tot);
System.out.println (“avg marks are=” +avg);
if (m1 > =35 && m2>=35 && m3>=35)
System.out.println(“pass”);
else
system.out.println(“fail”);
}
}
Class test
{
Public static void main (string args [ ])
{
Marks m=new marks(40,35,47);
m.calc( );
m.disp( );
}
}
Method Overriding method:
When we want to an object respond to the same method but have different behavior when that method is
called. That means we should override the method defined in super class.
This is possible by defining a method in that super class that has same name same arguments and
same return type as a method in super class.When that method is called the method in the sub class invoked
and executed instead of super class these process is known as method over riding.

MS bhanu
class A 34
{
int x;
A (int x) //constructor
{
This.x=x;
}
void display ( )
{
System.out.println(“A of x=”+x);
}
}
class B extends A
{
int y;
B(int x,int y)
{
Super(x);
This.y=y;
}
void display( )
{
System.out.println(“A of x=”+x);
System.out.print(“B of y=”+y);
}
}
class ovtest
{
public static void main(String args[ ])
{
B ob=new B (10,100);
Ob.display ( );
}
}

MS bhanu
35
ARRAYS
Array:
Array is collection of homogeneous elements that can share common name. The ability to use a
single name to initialization (or) declare multiple variables.
Array is a variable name to store multiple values in continuous memory locations. Java supports the
arrays concepts with the following advantages.
Advantages:
1) multiple variable declarations will be avoided
2) data can stored in sequence order so it is very easy to access
3) Arrays individual elements are identified by subscript (or) index values.
4) Program complexity will be reduced.
5) The program efficiency will be increased.
Disadvantages:
1) it is a homogeneous set of elements so that it will not allow other data type elements
2) once array size is declared it can‟t be increased & decreased
3) the predetermination of the size of the array will waste the memory (un used spaces)
4) while inserting (or) deleting element user need to travel the array from the beginning and disturb the
existing elements
Syntax:
data type array name[ size];
data type array name [size] = {values….};
Ex: int x[j];
int x[j] ={1,2,3,4,5};
Types of arrays;
Java supports two types of arrays those are
1) Single Dimensional Array
2) Double Dimensional Array
Single Dimensional Array:
A list of items can be given one variable name using only one subscript & variables is called 1D
array. (or) single subscripted array. The elements are stored either inform of row (or) column. So this is also
called row array (or) column array
Subscript
Subscript is an identifier to identify the individual elements in an array. Generally subscript values starts
from zero and it is a +ve integer.
Creating an array;
Like any other variable array must be declared in the computer memory before they are used. Creation of an
array involves 3 steps. Those are

MS bhanu
1) Declaring the array 36
2) Creating memory location
3) Putting values into the memory locations
Declaration of array:
Arrays in java may be declared in two forms. Those are
Form1: Data type array name [ ];
Form2: Data type [ ] array name;
Ex:
int x [ ] ;
float y [ ];
Ex:
int [ ]p;
float q[ ];
In java don‟t mention the size of array at the time of declaration
Creating memory locations:
After declaring array user need to create it into the memory. Java allows us to create arrays using new
operator only.
Syntax:
Array name=new type [size];
Ex:
x=new int[s];
y=new float[10];
In java the values of array name (or) the size of the array name must be initialized by using new
operator irrespective of data type the size created with the help of new operator.
Putting values into the memory locations:
The final step is to put the values into the array created this process is known as initialization. This is done
using the array subscripts. The subscript value must be the +ve integer.
Syntax: Array name [subscript value] = value;
X[0]=10;
X[1]=20;
X[2]=30;
X[3]=40;
X[4]=50;
Note;
1) The java creates arrays starting with the subscript with “0” & ends with value one less than the size
specified

MS bhanu
2) Java protects array form over runs & under runs. Trying to access an array bound its boundaries will
generate an error message. 37
We can also initialize the arrays automatically in the same way as the ordinary variables when they
are declared, the list of values must be specified separated by comma &
Double Dimensional-Array:
The array which is used to store the values in a tabular form. It means in 2D array. The values are stored in
both row & columns(in a matrix form). In 2D array there will be two subscript values one is used to identify
row and another is used to identify column. This is also known as double subscripted array.
Syntax
1) declaration type array name [][];
Type[][] array name;
Ex; intx[][];
Int[][]x;
2)execution array name= new tye[][]
Ex; int x= new int[2][2];
3) initialization array name [rs][cs]={valesi,ii…};
Ex; x[0][0]=10;
X[0]1]=20;
X [1][1]=30;
X [1][1]=40;

1) w.a.p to display the values from 2D array.


Class array 2D
{
public static void main string args[])
{
int x[][]={2,4,6,8};
int i,j;
For (i=0; i<2; I + +)
{
For (j=0; j<2; j + +)
{
System. Out. print (x[i][i]);
}
System. Out. println (“ ”);
}
}
}
MS bhanu
Note: 38
In java the multi-dimensional concept is known as arrays of arrays. It is possible to declare but at the
time of execution the threads will be created.
Command line arguments
The arguments which are passed from command line to the application program at the
time of invoking it for execution. The java programs can be written with (or) without command line
arguments. Java supports up to three arguments in the main function. The command line arguments are
declared as an array of string args [ ]. Any arguments provided in the command line are passed to the array
args [ ] as its elements. The individual element of an array are accessed by using an index ( or ) subscript
like args [i]. the value of “ i “ denotes the position of the element inside the array. Generally the subscript
value begins with “ 0 “ (or) “1”
A simple program in Java:
class Sample
{
public static void main (string args [])
{
System.out.print (“welcome to java”);
}
}
Java is general purpose object oriented programming language we can develop two types
of java program
1) Stand alone programs (or) applications
2) Web applets.
1) The stand alone programs can read and write files and perform certain operations.
2) An applet can only used in web browser.
Applets are used for uploading & downloading the information through the web.
Inner classes
Inner classes are classes that are declared within other classes. They are also knows as nested classes
and provide additional clarity to the program. The scope of the inner class is limited to the class that
encloses it. The object of the inner class can access the members of the outer class. While the outer class can
access the members of the inner class through an object of the inner class.
Syntax:
class
{
class
{
}
//other attributes and methods
}

MS bhanu
INHERITANCE 39

The process of reusing the methods and fields by extending the class to another is called inheritance.
Java supports inheritance concepts. Java classes can be reused in several ways this is basically done by
creating new classes by reusing the properties of existing class.
The mechanism of deriving new class from an old one is called inheritance. The old class is known
as base class (or) parent class (or) super class. The new class known as derived class (or) child class (or) sub
class.
The inheritance allows sub classes to inherit all the variables and methods of their parent class (or)
super class.
Note:
The derived class (or) sub class may contain its own properties & derived properties but base class
contains its own properties.
Java supports different forms of inheritances. Those are
1. Single inheritance (only one super class)
2. Multiple inheritance (several super class)
3. Hierarchical inheritance (one super class ,many sub classes)
4. Multilevel inheritance (derived from another derived class)
Note:
Java does not directly support multiple inheritances however this concept is implemented using
secondary inheritance path in form of interfaces.
Base class: The class which will give the properties to the other classes known as base class (or) parent
class.
Derived class: The class which is getting the property from other class known as derived class (or) child
class. The derived may contain the properties of both base class properties and its own properties.
Intermediate base class: The class which is acting like a derived class for one base class and base class
for another derived class in known as intermediate base class.
1. Single Inheritance: The process of inheriting the properties from one base class to one derived
class is called as single inheritance. In single inheritance only one base class is used and one derived
class is derived class is derive.
Super class

Sub class
Syntax:
Class Base class
{
Member variables/fields;
Member functions/methods;
}
Class derived class name extends Base class name
{
Member variables/fields;
Member functions/methods;
}

MS bhanu
Ex: 40
class abc
{
int a,b,c;
void input( )
{
a=10;
b=20;
c=a+b;
}
}
class xyz extends abc
{
int p;
void output( )
{
p=a+b;
System.out.print(p);
}
}
class main( )
{
public static void main(String args[ ])
{
xyz k=new xyz( );
}
}
Extends key word is use to create the inter relationship between (or) among the classes.

2. Multiple inheritance:
In multiple inheritance the process of creating one single derived class from two (or) more base classes.
In this inheritance the derived class may contain the properties of base classes and its own properties.

Base class-1 Base class-2

Derived class

MS bhanu
Syntax: 41
class base class-1
{
member variables/fields;
member variables/methods;
}
class base class-2
{
member variables/fields;
member functions/methods;
}
class derived class extends base class-1 extends base class-2
{
member variables/fields;
member functions/methods;
}
3. Multi level Inheritance:
The process of deriving a class from a base class & deriving another class by using derived class
properties. In this inheritance the I class is called base class and the last class is called derived class and in
between classes are called intermediate base class.

Base class

IBC

IBC

Derived class
Syntax:
class BC
{
----
}
class IBC extends BC
{
----
}
class DC extends IBC
{
----
}

MS bhanu
4. Hierarcal Inheritance: 42
The process of inheriting more number of classes by using a single base class is called hierarchical
inheritance.
Syntax:
class BC
{
---
}
class DC1 extends BC
{
---
}
class DC2 extends BC
{
---
}

Base class

Derived Derived Derived Derived


class-1 class-1 class-1 class-1

Account

Savings Fixed deposit Current

Short medium Long

Ex:
class AAA
{
int a=10,b=20;
}
class BBB extends AAA
{

MS bhanu
void setdata( ); 43
{
System.out.print(a+b);
}
}
class CCC extends AAA
{
void showdata( )
{
System.out.print(a-b);
}
}
class DDD extends AAA
{
void getdata( )
{
System.out.print(a*b);
}
}
class main( )
{
public static void main(String args[ ] )
{
BBB b1=new BBB( );
b1.setdata( );
CCC c1=new CCC( );
c1.showdata( );
DDD d1=new DDD( );
D1.getdata ( );
}
}
INTERFACES; MULTIPLE INHERITANCES
INTERFACE:
In large no. of real-life applications require the use of multiple inheritance .That is why we have to
inherit the properties & methods from several distinct classes. Java provides an alternative approach known
as interface.
Interface supports the concept of multiple inheritances. A java class cannot be a sub class of more
than one super class. It can implement more than one interface.
MS bhanu
44
An interface is basically a kind of class. An interface consists of set of method declaration & member
variable. Interface don‟t specify any code to implement there methods. There fore its definition will be given
in the other class. The member variables are final.
The variables must be constant type they must be initialized The general syntax of interface
definition is
interface <interface name>
{
variable declaration;
method declaration;
}
Here interface is a keyword and interface is a valid java variable name.
In generally the variables can be declared as follows,
Static final type variable name=value;
Ex:
Static final int x=10;
Static final string y=”India”;
Static final char[ ]=”Interface”;
Method declaration will contain only a list of method declaration without any body (or) statements.
That is also known as method signature. A method can be declared as follows.
Return type method name (argument list);
General syntax of interface is a sfollows.
interface interface name>
{
static final type variable name=value;
return type methodname(argument list);
}
Ex:
interface xyz
{
static final int x=10;
static final int y=20;
int pqr(int x,int y);
}
implementation of interface:
Interface s are used as super classes. Whose properties area inherited by other class, it is necessary to
create a class that inherits the given interface. An interface can be implemented by using the keyword
implement. Where as in inheritance must be used the keyword extends.

MS bhanu
Syntax:
45
1) class class name implements interface name
{
body of the class;
}
2) class <classname> extends superclass name
{
body of the subclass;
}
Ex:
interface xyz
{
---
}
class pqr implements xyz
{
----
}
class klm extends pqr
{
body of klm class
}
Various forms of interface implementation:
Interfaces can be used to declare a set of constants that can be used in different classed. This is similar to
creating different forms of inheritances in c++. Those are
interface Area
{
final static float pi=3.14;
float compute(float x,float y);
}
class rectangle implements area
{
public float compute (float x,float y);
{
return (x*y);
}
}

MS bhanu
class circle implements area 46

{
public float compute (float x ,float y)
{
return (pi*x*x);
}
}
class test extends rectangle extends circle
{
public static void main (String args[ ])
{
Rectangle r=new Rectangle();
Cirlce c= new circle();
Area a;
A=r;
S.o.p(a.compute (10,20);
A=c;
s.o.p(a.compute(10,0);
}
}
Multiple inheritance
Class stud
{ int rno;
void getno(int n)
{
rno=n;
}
void putno()
{
s.o.p(rno);
}
class Test extends student
{
float p1,p2;
void getmarks (float m1,float m2)
{
p1=m1;

MS bhanu
p2=m2; 47
}
}
void putmarks()
{
s.o.p(p1);
s.o.p(m2);
}
interface sports
{
float sw=6.0F;
void putsw();
}
class Result extends Test implements sports
{
float total;
public void putsw()
{
s.o.p(sw):
}
void display( )
{
total =m1+m2+m3;
putno();
putmarks();
putsw();
s.o.p. (total);
}
}
class hybrid
{
public static void main(String args[ ])
{
result s1=new Result( );
s1.getno(10);
s1.getmarks(35.6,45.6);
s1.display();
}

MS bhanu
Abstract Classes 48
Definition: An abstract class is a class that is declared as abstract. It may or may not include abstract
methods. Abstract classes cannot be instantiated, but they can be subclass.
An abstract method is a method that is declared without an implementation (without braces, and
followed by a semicolon), like this:
abstract void studtest(int rollno, double testfees);
If a class includes abstract methods, the class itself must be declared abstract, as in:
public abstract class GraphicObject
{
// declare fields
// declare non-abstract methods
abstract void draw();
}
When an abstract class is subclass, the subclass usually provides implementations for all of the
abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract.
For example:
Abstract class A
{
abstract void method1();
void method2()
{
System.out.println("this is real method");
}
}
class B extends A
{
void method1()
{
System.out.println("B is execution of method1");
}
}
class demo
{
public static void main(String arg[])
{
B b=new B();
b.method1();
b.method2();
}

MS bhanu
Extending the class: (Extends Keyword) 49
Inheritance allows to subclass or child class to access all methods and variables of parent class.
Syntax:
class subclassname extends superclassname
{
Varables;
Methods;
…..
}
For example: calculate area and volume by using Inhertance.
class data
{
int l;
int b;
data(int c, int d)
{
l=c;
b=d;
}
int area( )
{
return(l*b);
}
}
class data2 extends data
{
int h;
data2(int c,int d, int a)
{
super(c,d);
h=a;
}
int volume()
{
return(l*b*h);
}
}

MS bhanu
class dataDemo 50
{
public static void main(String args[])
{
data2 d1=new data2(10,20,30);
int area1=d1.area(); //superclass method
int volume1=d1.volume( );// subclass method
System.out.println("Area="+area1);
System.out.println("Volume="+volume1);
}
}
Output:
C:\cc>javac dataDemo.java
C:\cc>java dataDemo
Area=200
Volume=6000
INTERFACES AND ABSTRACT CLASSES
Interfaces are similar to abstract classes. The differences are as follows:
1. All methods in an interface are abstract. Which means all methods must be empty; no code implemented.
2. In abstract class, the methods can have code/implementation within it. Atleast one method must be
abstract.
3. All properties (data fields) in an interface are static final. Properties in an abstract class need not be static
final.
4. Interfaces are implemented(implements keyword); Abstract classes are extended(extends keyword)
5. Class can extend only one abstract class; whereas a class can implement multiple interfaces (multiple
inheritance)
6. Contractual obligation: When a class specifies that it implements an interface, it must define all methods
of that interface. A class can implement many different interfaces. If a class doesn't define all methods of the
interfaces it agreed to define (by the implements clause), the compiler gives an error message, which
typically says something like "This class must be declared abstract". An abstract class is one that doesn't
implement all methods it said it would. The solution to this is almost always to implement the missing
methods of the interface. A misspelled method name or incorrect parameter list is the usual cause, not that it
should have been abstract!

MS bhanu

You might also like