Sunteți pe pagina 1din 27

What is Java?

The term Java actual refers to more than just a particular language like C or Pascal. Java
encompasses several parts, including :
1 A high level language ? the Java language is a high level one that at a glance
looks very similar to C and C++ but offers many unique features of its own.

2 Java bytecode - a compiler, such as Sun's javac, transforms the Java language
source code to bytecode that runs in the JVM.

3 Java Virtual Machine (JVM) ? a program, such as Sun's java, that runs on a
given platform and takes the bytecode programs as input and interprets them just
as if it were a physical processor executing machine code.
Sun provides a set of programming tools such as javac, java and others in a bundle that
it calls a Java Software Development Kit for each version of the language and for
different platforms such as Windows, Linux, etc.. Sun also provides a runtime bundle
with just the JVM when the programming tools are not needed.
Note that because of the open nature of Java (see below), any or all of these parts can be
replaced by non-Sun components. For example, just as many different languages can
create machine code for a given processor, compilers of other languages have been
created that output bytecode to run in the JVM. Similarly, many JVMs have been written
by groups outside of Sun.
In this book and web course, when we use the term Java we are referring to the the high
level language unless noted otherwise. Also, those packages that come with the SDK for
a given version will be referred to as comprising the core language for that version, as
distinguished from optional or third party packages

History of Java
Around 1990 James Gosling , Bill Joy and others at Sun Microsystems began developing
a language called Oak. The wanted it primarily to control microprocessors embedded in
consumer items such as cable set-top boxes,VCR's, toasters, and also for personal data
assistants (PDA).
To serve these goals, Oak needed to be:
4 Platform independent (since multiple manufacturers involved)
5 Extremely reliable
6 Compact.
However, as of 1993, interactive TV and PDA markets had failed to take off. Then the
Internet and Web explosion began, so Sun shifted the target market to Internet
applications and changed the name of the project to Java.
By 1994 Sun's HotJava browser appeared. Written in Java in only a few months, it
illustrated the power of applets, programs that run within a browser, and also the
capabilities of Java for speeding program development.
Riding along with the explosion of interest and publicity in the Internet, Java quickly
received widespread recognition and expectations grew for it to become the dominant
software for browser and consumer applications.
However, the early versions of Java did not possess the breadth and depth of capabilities
needed for client (i.e. consumer) applications. For example, the graphics in Java 1.0
seemed crude and clumsy compared to mature software developed with C and other
languages.
Applets became popular and remain common but don't dominate interactive or
multimedia displays on web pages. Many other "plug-in" types of programs also run
within the browser environment.
So Java has not succeeded at development of consumer applications. However, Java's
capabilities grew with the release of new and expanded versions (see below) and it
became a very popular language for development of enterprise, or middleware,
applications such as on line web stores, transactions processing, database interfaces, and
so forth.
Java has also become quite common on small platforms such as cell phones and PDAs.
Java is now used in several hundred cell phone models. Over 600 million JavaCards,
smart cards with additional features provided by Java, have been sold as of the summer of
2004.

Features
Here we list the basic features that make Java a powerful and popular programming
language:
7 Platform Independence
8 The Write-Once-Run-Anywhere ideal has not been achieved (tuning for
different platforms usually required), but closer than with other languages.
9 Object Oriented
10 Object oriented throughout - no coding outside of class definitions,
including main().

11 An extensive class library available in the core language packages.

12 Compiler/Interpreter Combo
13 Code is compiled to bytecodes that are interpreted by a Java virtual
machines (JVM) .
14 This provides portability to any machine for which a virtual machine has
been written.
15 The two steps of compilation and interpretation allow for extensive code
checking and improved security.

16 Robust
17 Exception handling built-in, strong type checking (that is, all data must be
declared an explicit type), local variables must be initialized.

18 Several dangerous features of C & C++ eliminated:


19 No memory pointers
20 No preprocessor
21 Array index limit checking
22 Automatic Memory Management
23 Automatic garbage collection - memory management handled by JVM.

24 Security
25 No memory pointers
26 Programs runs inside the virtual machine sandbox.
27 Array index limit checking
28 Code pathologies reduced by
29 bytecode verifier - checks classes after loading
30 class loader - confines objects to unique namespaces. Prevents
loading a hacked "java.lang.SecurityManager" class, for
example.
31 security manager - determines what resources a class can access
such as reading and writing to the local disk.

32 Dynamic Binding
33 The linking of data and methods to where they are located, is done at run-
time.
34 New classes can be loaded while a program is running. Linking is done on
the fly.
35 Even if libraries are recompiled, there is no need to recompile code that
uses classes in those libraries.

This differs from C++, which uses static binding. This can result in fragile
classes for cases where linked code is changed and memory pointers then
point to the wrong addresses.

36 Good Performance
37 Interpretation of bytecodes slowed performance in early versions, but
advanced virtual machines with adaptive and just-in-time compilation and
other techniques now typically provide performance up to 50% to 100%
the speed of C++ programs.

38 Threading
39 Lightweight processes, called threads, can easily be spun off to perform
multiprocessing.
40 Can take advantage of multiprocessors where available
41 Great for multimedia displays.

42 Built-in Networking
43 Java was designed with networking in mind and comes with many classes
to develop sophisticated Internet communications.
Features such as eliminating memory pointers and by checking array limits greatly help
to remove program bugs. The garbage collector relieves programmers of the big job of
memory management. These and the other features can lead to a big speedup in program
development compared to C/C++ programming.

Java Version
Since its introduction, Sun has released a new version of the Java language every two
years or so. These new versions brought enhancements, new capabilities and fixes to
bugs. Below is a timeline of the different versions of the basic, or Standard Edition (SE),
of Java along with some of the new features that each one introduced. This edition
contains the core language packages (the name for code libraries in Java) and is aimed for
desktop programming.
44 1995: Version 1.0 of the Java Development Kit (JDK) was released for free by
Sun.
45 8 packages with 212 classes
46 Netscape 2.0-4.0 included Java 1.0.
47 Microsoft and other companies licensed Java.

48 1997: Version 1.1:


49 23 packages - 504 classes
50 Improvements include better event handling, inner classes, improved
JVM.
51 Microsoft developed its own 1.1. compatible Java Virtual Machine for the
Internet Explorer.
52 Many browsers in use are still compatible only with 1.1.
53 Swing packages of greatly improved graphics became available during this
time but not included with the core language.

54 1999: Version 1.2, also called the Java 2 Platform


55 59 packages - 1520 classes
56 Code and tools distributed as The Software Development Kit (SDK)
57 Java Foundation Classes (JFC), based on Swing, for improved graphics
and user interfaces, now included with the core language.
58 Collections API included support for various lists, sets, and hash maps.

59 2000: Version 1.3:


60 76 packages - 1842 classes
61 Performance enhancements including the Hotspot virtual machine.

62 2002: Version 1.4:


63 135 packages - 2991 classes
64 Improved IO, XML support, etc.

65 2004: Version 5.0 (previously numbered 1.5):


66 165 packages, over 3000 classes
67 Faster startup and smaller memory footprint
68 Metadata
69 Formatted output
70 Generics
71 Improved multithreading features
We discuss Java 5.0 further in this chapter and examine individual features in later
chapters like those listed above. See the Code Compatiblity page for a discussion of
issues related to dealing with codes, compilers, and JVMs from different versions.
Other Editions of Java
In the late 1990s, Sun split off two other more specialized branches, or editions, of Java.
One is aimed at small, embedded applications and the other for large scale middleware
applications:
Micro Java
Embedded systems such as cell phones and device controllers typically offer
reduced resources as compared to desktop PCs. This means substantially less disk
space or no disk at all, and less of other types of nonvolatile memory. It also
usually means a smaller display or perhaps no display at all.
For such systems Sun offers slimmed down versions of Java.
72 JavaCard - extremely limited Java for systems with only 16kb
nonvolatile memory and 512 bytes volatile

73 EmbeddedJava - based on Java 1.1 for 32 bit system with about 512kb
each for ROM and RAM. Individual packages, classes and even methods
in the core language can be thrown out to make room.
74 PersonalJava - based on Java 1.1.8 for larger systems with 2MB ROM
and more than 1MB RAM.

75 Java 2 Platform, Micro Edition (J2ME) - based on the Java 2 Platform,


J2ME replaces the Java 1.1 based systems (EmbeddedJava and
PersonalJava but not JavaCard). The developer will choose from different
configurations to suit the capacity of a given system.
J2EE - Java 2 Platform, Enterprise Edition
With the Java 2 Platform came a separate version with enhanced resources
targeted at enterprise applications. The Java 2 Enterprise Edition now provides a
wide array of tools for building middleware software such as for database access
applications, online storefronts, and other services.
Naming Conventions
All of these editions and version numbers can be a bit confusing for newcomers. Also,
terms change such as Java Development Kit becoming Software Development Kit. For
this course, however, you can just use the latest version - Java 5.0 - and not worry about
all these historical issues.
Note that we use the terms Java 1.x, SDK 1.x, and J2SE 1.x interchangeably and
similarly, for Java 5.0, SDK 5.0, and J2SE 5.0. This course was originally developed with
Java 1.4.2 but we have now converted the codes to Java 5.0.
We also will occasionally refer simply to the "platform" to indicate the whole Java
programming environment provided by the compiler, JVM, and the various other tools
available for working with the language

Creating Your First Application


Your first application, HelloWorldApp, will simply display the greeting "Hello
world!". To create this program, you will:
76 Create a source file
A source file contains code, written in the Java programming language,
that you and other programmers can understand. You can use any text
editor to create and edit source files.
77 Compile the source file into a .class file
The Java programming language compiler (javac) takes your source file
and translates its text into instructions that the Java virtual machine can
understand. The instructions contained within this file are known as
bytecodes.
78 Run the program
The Java application launcher tool (java) uses the Java virtual machine to
run your application.

A Closer Look at the "Hello World!" Application


Now that you've seen the "Hello World!" application (and perhaps even compiled
and run it), you might be wondering how it works. Here again is its code:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the
string.
}
}

Source Code Comments


The following bold text defines the comments of the "Hello World!" application:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the
string.
}
}
Comments are ignored by the compiler but are useful to other programmers. The
Java programming language supports three kinds of comments:
/* text */

The compiler ignores everything from /* to */.


/** documentation */

This indicates a documentation comment (doc comment, for short).


The compiler ignores this kind of comment, just like it ignores
comments that use /* and */. The javadoc tool uses doc comments
when preparing automatically generated documentation. For more
information on javadoc, see the JavadocTM tool documentation .
// text

The compiler ignores everything from // to the end of the line.

The HelloWorldApp Class Definition


The following bold text begins the class definition block for the "Hello World!"
application:
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the
string.
}
}
As shown above, the most basic form of a class definition is:
class name {
. . .
}
The keyword class begins the class definition for a class named name, and the
code for each class appears between the opening and closing curly braces marked
in bold above. Chapter 2 provides an overview of classes in general, and Chapter
4 discusses classes in detail. For now it is enough to know that every application
begins with a class definition.
The main Method
The following bold text begins the definition of the main method:
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the
string.
}
}
In the Java programming language, every application must contain a main method
whose signature is:
public static void main(String[] args)
The modifiers public and static can be written in either order (public static
or static public), but the convention is to use public static as shown above.
You can name the argument anything you want, but most programmers choose
"args" or "argv".
The main method is similar to the main function in C and C++; it's the entry point
for your application and will subsequently invoke all the other methods required
by your program.
The main method accepts a single argument: an array of elements of type String.
public static void main(String[] args)
This array is the mechanism through which the runtime system passes information
to your application. Each string in the array is called a command-line argument.
Command-line arguments let users affect the operation of the application without
recompiling it. For example, a sorting program might allow the user to specify
that the data be sorted in descending order with this command-line argument:
-descending
The "Hello World!" application ignores its command-line arguments, but you
should be aware of the fact that such arguments do exist.
Finally, the line:
System.out.println("Hello World!");
uses the System class from the core library to print the "Hello World!" message to
standard output. Portions of this library (also known as the "Application
Programming Interface", or "API") will be discussed throughout the remainder of
the tutorial.
Create a Source File

First, start your editor. You can launch the Notepad editor from the Start menu by
selecting Programs > Accessories > Notepad. In a new document, type in the following
code:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}

Save the code in a file with the name HelloWorldApp.java. To do this in Notepad, first
choose the File > Save As menu item. Then, in the Save As dialog box:
Using the Save in combo box, specify the folder (directory) where you'll save your
file. In this example, the directory is java on the C drive.

In the File name text field, type "HelloWorldApp.java", including the quotation
marks.
From the Save as type combo box, choose Text Documents (*.txt).
In the Encoding combo box, leave the encoding as ANSI

Compile the Source File into a .class File


Bring up a shell, or "command," window. You can do this from the Start menu
by choosing Command Prompt (Windows XP), or by choosing Run... and then
entering cmd

At the prompt, type the following command and press Enter.


javac HelloWorldApp.java

Run the Program


In the same directory, enter the following command at the prompt:
java HelloWorldApp
Java DataTypes

Java defines eight simple types of data: byte, short, int, long,
char, float, double, and Boolean .These can be put in four groups

Integer:

This groups include byte,short,int, and long which are for whole
valued signed numbers.

Floating:

This group includes float and double,which represents nuumbers


with fractinal precesion.

Characters:

This group includes char,which represents sysmbols in a character


set ,like letters and numbers.

Boolean:

This group includes boolean,which is a special type for


representing true/false values.

Variables
The variable is the basic unit of starage in a java program.A
variable is defined by the combination of an identifier, a type ,
and an optional initilizer.

Declaring Variables

In java all varables must be declred before they can be used.

Syntax

Datatype identifier1=value,identifier2=value,………;

Eg:

int a,b,c;
double pi=3.14159;
Operators
Java provides a rich operator environment.Most of the operators
can be divided into the foolowing four groups
arithmetic,bitwise,relational, and logical.Java also defines some
additional operators that handle certain special sitautions

Arithmetic Operators

Arithmetic Operators are used in mathematical expression.

Operator Result

+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
+= Addition assignment
-= Subtration assigment
*= Multiplication assigment
/= Division assignment
%= Modulus assignment
-- Decrement

Bitwise Operators

These operators act upon the individual bits of their operands.

Relational Operators

The relational operators determine the relasionship that one


operand has to the other.

Operator Result

== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equl to

Logical Operators

The logical operators shown here operate only on boolean operands


Operator Result

& Logical AND


| Logical OR
^ Logical XOR
|| Short –circuit OR
&& Short –circuit AND
! Logical NOT

Assignment Opreator

The assigment operator is the single equal sign “=”.The


assignment operator works in java like other computer language.

Syntax

Variable=value/expression;

Eg

int a,b,c;
a=10;
b=20;
c=a+b;

Control Statements
A programming language uses control statements to cause the flow
of execution and branch based on changes to the state of a
program.They are

1. Conditional control statements


2. Looping statements
3. Break and Continue statements

1. Conditional control statements

Control the flow of execution according to condtion.java supports


different types of conditional control statements

a. if
if statement control the flow of execution according
to a condition

Syntax

if(condition)
{
Statement block;

}
b.if …….. else

if…else is a bidirectional conditional control statement.It execute a conditions true or


false section

Syntax

If(Condition)
{
true block statement;
}
else
{
false block statement;
}

c. switch statement

switch statement is a multidirectional conditinal control statement

Syntax

Switch(expression/value)

{
Case value1:

Statement block1;
Case value2:

Statement block2;
.
.
.
.
.

Case valuen:
Statement blockn;

}
2. Looping Statements

The looping statements repeats the statement block until the condtion become false
Java supports three types of looping satements they are.

a. while loop
The while loop repeats a statement or block while its controlling expression is true.

Syntax
While (condition)
{

Statement block;

While loop is called entry control loop statement

b. do…while

The do….while loop executes its body at least once , because its conditional
expression is at the buttom of the loop.So do….while loop is called exit control
statement.

Syntax

do
{
Statement block;
} while(condition);

c. for
The for loop is also called entry controlled loop statement

Syntax

for(initilization;condition;iteration)
{
Statement block;
}
For loop execute its statement block until the condtion become false.

Array
An array is a group of values that have a common variable name and identified each value by a
number called array
Subscript or array index.Arrays of any type can be created and may have one or more
dimensions.

One Dimensional array


A one dimesional array is essentially, a list of like – typed variables.To create an array you first
must create an array variable
Of the desired type

Syntax

Datatype varibale name[]=new datatype[array size];

eg

int a[]=new int[20];

Multidimensional array

In Java, multidimensional arrays are actually arrays of arrays.To declare a multidimensional array
variable,specify each additional index using another set of square brackets

Syntax

Datatype variable name[][]=new datatype[row size][column size];

Eg

int a[][]=new int[3][2];

String Handling
Strings as built in objects allows java to provide a full complement of features that make string
handling convenient.For example java has methods to compare two strings ,search for a
substring ,concatenate two strings ,and change the case of letters with in a string. When you
create a string object , you are creating a string that cannot be cahnged.That is once a string
object has been created , you cannot change the characters that comprise that string

Character Extraction

The String class provides a number of ways in which characters can be extracted from a String
object.

charAt()

To extract a single character from a String, you can refer directly to an individual character via the
charAt() method

Syntax

charAt(int where)

where is the index of the character that you want to obtain

eg
char ch;
ch=”abc”.charAt(1)

assigns the value “b” to ch

String Comparison

The string class includes several methods that compare strings or substrings with in strings.

Equals and equalsIgnoreCase()

To compare two strings for equality, use equals()

Syntax

Boolean equals(Object str)

Here, str is the String object being compared with the invoking String object.It returns true if the
strings conatin the same characters in the same order, and false otherwise.The comparision is
case sensitive

To perform a comparioson that ignores case differences , call equalsIgnoreCase().


When it compares two strings,it coniders A-Z to be the same as a-z.

Syntax

Boolean equalsIgnoreCase(String str)

Here , str is the String object beign compared with the invoking String object.

CompareTo()

For sorting applications, you need to know is less than, equal to , or greater than the next.A string
is less than another if it comes before the other in dictionary order. A string is greater than
another if it comes after the other in dictionary order.The string method comareTo() servers this
purpose.

Syntax

Int compareTo(String str)

Here, str is the String being compared with the invoking String.

Value Meaning

Less than zero The invoking string is less than str.

Greater than zero The invoking string is greater than str.

Zero The two strings are equal.


Changing Case of Characters

The method toLowerCase() converts all the characters in a string from uppercase to
lowercase.The toUpperCase() method converts all the characters in a string from lowercase to
uppercase.

Syntax

String toLowerCase()
String toUpperCase()

Reverse

You can reverse the characters within a string buffer object using reverse()

StringBuffer reverse()

This method returns the reversed object on which it was called.

Exception Handling

A java exception is an object that describes an exceptional condition that has occurred in a piece
of code
When an execeptional condition arises , an object representing that exception is created and
thrown in the method that caused the error.Java exception handling is managed via five keywords
try,catch,throw,throws and finally.Program statements that you want to moniter for exceptions are
conatined within a try block.If an exception occurs within the try block, it is thrown.Your code can
catch this exception using catch and handle it in some ratinonal manner.System generated
exceptions are automatically thrown by the java run time system.To manually throw an
exception , use the keyword throw.Any exception that is thrown out of a method must be specified
as such by a throws clause.

Syntax

try
{

//block of code to monitor for errors

catch(Exception Type1 exob)

//exception handler for Exception Type1

catch(Exception Type2 exob)


{

//exception handler for Exception Type2

.
.
.
.
.

finally
{

//block of code to be executed before try block ends

Sometimes, a program may compile successfully creating the .class file but may not run properly.
Such programs may produce wrong results due to wrong logic or may terminate due to errors such as
stack overflow. Most common run-time errors are: » Dividing an integer by zero
* Accessing an element that is out of the bounds of an array » Trying to store a
value into an array of an incompatible class or type
* Trying to cast an instance of a class to one of its subclasses
* Passing a parameter that is not in a valid range or value for a method
* Trying to illegally change the state of a thread
* Attempting to use a negative size for an array
* Using a null object reference as a legitimate object reference to access a method or a variable
* Converting invalid string to a number
* Accessing a character that is out of bounds of a string
* And many more

Common Java Exceptions

Exception Type Cause of Exception

ArithmeticException Causedby math errors such as division by zero


ArraylndexOutOf BoundsException Caused by bad array indexes
ArrayStoreException Caused when a program tries to store the wrong
type of data in an array
FileNotFoundException Caused by an attempt to access a nonexistent
file

Thread

Java language provides buit in support for multithreaded programming . A multithreaded program
contains two or more parts that contains two or more parts that can run concerrently.Each part of
such a program is called thread, and each thread defines a seprate path of execution.So
mutithreading is a specilized form of multitasking.

When a java program starts up , one thread begings running immediately.This is usally called the
main main thread of your program, because it is the one that is executed when your program
begins

The thread class defines several methods that help manage threads. They are

1. getName -- Obtain a thread’s name


2. getPriority -- Obtain a thread’s priority
3. isAlive -- Detremine if a thread is still running
4. join -- Wait for a thread to terminate
5. run -- Entry point for the thread
6. sleep -- Suspend a thread for a period of time
7. start -- Start a thread by calling its run method.
Class
A class is a way to bind the data.The members declared inside a class are local
to that class.We can difine any number of class in a program.
Syntax

class classname
{
member variable declaration;
member function declaration;
};

We can define local variables in a class.The member variables declare in that


class can access only by the member functions.To access the class members
outside the class use class object.

Syntax

classname objectvariable;

Objectvariable.classmember

The member functions can be defined in the class and can access outside of the
class.
Syntax for function defanition

Datatype functionname( datatype parametervariable1,datatype


parametervariable 2,……………)
{
function body;
}

To access the class member functions outside of a class

Syntax

Classobject.functionname();

Constructor
Constructor is a special member function who’s task is to initilize obejct of a
class.A Constructor name is same as class name.Constructor does not not
support return type and they are two types they are

1. Parametarized constructor
2. Default constructor

Parametrarized Constructor

The constructor which receive value by using parameter variable are called
parametarized constructor

Syntax

Classname(datatype parametervariable1,datatype parametervariable2,………..)


{
constructor body;
}

Default construtor

Construtor which does not recive value from calling section is called default
constructor

Classname()
{
construtor body;
}
Inheritance

Reausability is the advantage of ObjectOrientedProgramming.Java classes can


be reused in several ways.This is basically done by creating new classes,reusing
the properties of existing ones.The mechanism of deriving a new class from an
old one is called inheritance.The old class is known as the base class or parent
class and the new one is called the subclass or drived class or child class

Inheritance may take different forms

Single Inheritance

Multiple Inheritance

Hierarchical Inheritance

Multilevel Inheritance

Defining a subclass

A subclass is defined as follows

Class subclassname
{
variables declaration;
methods declaration;
}

The keyword extends signifies that the properties of the superclassname are
extended to the subclassname.The subclass will now contain its own variables
and methods as well those of the superclass.This kind of situation occurs when
we want to add some more properties to an existing class without actually
modifing it.

Defining a superclass

A subclass is defined as follows

Class superclassname extends subclassname


{
variables declaration;
methods declaration;
}

The keyword extends signifies that the properties of the superclassname are
extended to the subclassname.The subclass will now contain its own variables
and methods as well those of the superclass.This kind of situation occurs when
we want to add some more properties to an existing class without actually
modifing it.

Intrefaces

An interface is basically a kind of class.Like classes, interfaces contain methods


and variables.The syntax for defining an interface is very similar to that for
defining a class.The general form of an interface definition is

Interface interfacename
{
variable declartion;
methods declartion;
}
Extending Interfaces

Like classes,interfaces can also be extented.That is an interface can be


subinterfaced from other interfaces.

Syntax

Interface name2 extends name1


{
body of name2
}

Implementing Interfaces

Interfaces are used as superclasses whose properties are inherited by classes..It


is therefore necessary to create a class that inherits the given interface.

Syntax

Class classname implements interfacename


{
body of classname
}

Here the class classname implements the interface interfacename.

Syntax

Class classname extends superclass implements interface1,interface2,………


{
body of classname
}

S-ar putea să vă placă și