Anda di halaman 1dari 3

PACKAGES

One of the main future of OOP is the code code re-useability, that is use the code that we
already created. It can be achieved by extending classes and implementing interfaces
using packages we can use classes from other program without physically copying them into the
programs
packages are the java's way of grouping a variety classes and\or interfaces together. The
grouping is usually done according to the functionality.
There are two kinds of packages
java API packages(lang, util, io, awt, net, applet)
user defined packages
CRATING A PACKAGE
we can create our own packages using package keyword. The package keyword followed by the
package name. this must be the first statement in the java source file.
Package firstPackage;
public class firstClass
{
--------------------}
INTERFACES
In java one class can not have more than one supper class. But java provides an alternative
approach known as interface to support the concept of multiple interface. So one class can implement
more than one interface.
An interface is basically a kind of class. Interface contain methods and variables but with a
major difference. The difference is that interfaces define only abstract methods and final fields. This
means that interface does not specify any code to implement. These methods and data field contain
only constant.
An interface can be defined by using the keyword iterface
interface interfacename
{
static final type variablename=value;
return-type methodnameF(parameters)
}
EXTENDING INTERFACES
like classes, interfaces can also be extended. That is an interface can be sub-interfaced from
other interface . The sub-interface inherits all the members of the super-interface. This can be achieved
by using the keyword extends
interface name2 extends name1
{
body of name2;
}
IMPLEMENTING INTERFACES
interfaces are used as super-classes. An interfaces can be implemented by using the keywork
implements
class className implements interfaceName
{
body of the classname;
}

EXCEPTION HANDLING
An exception is a condition that is caused by a run time error in the program. When java
interpreter encounter an error. It creates an exception object and throws it. If the exception object is not
caught and handled properly the interpreter display an error message and it will terminate the program.
If we want the program to continue with the execution of the remaining code, then we should try to
catch the exception objects thrown by the error condition and then display an appropriate message for
taking corrective action. This task is known as exception handling
java exceptions can be handled by using the keywords try, catch, throw, throws and finally.
Program statements that you want to monitor for exceptions are contained 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 rational 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. Any code that absolutely must be
executed after a try block completes is put in a finally block. It can be used to handle any exception that
is not caught by any of the previous catch statements .it may be added immediately after the tyr block
or after the last catch block.
INPUT/OUTPUT
We have used variables and arrays for storing data inside the programs. This approach process
the following problems
the data is lost either when a variable goes out of scope or when the program is termiinated.
It is difficult to handle large volume of data using variables and arrays
we can overcome these problems by storing data on a secondary storage using the concept files.j
java support many powerful features for managing input output of data using files. Reading and writing
of data in a file can be done at the level of bytes or characters.
Concept of streams
in file processing input refers to the flow of data into a program and output means the flow of
data out of a program . input to a program comes from the keyboard, the mouse, the memory, the disk,
a network, or another program. Similarly output from a program may go to the screen, the printer, the
memory, the disk, a network or another program.
Java uses the concept of streams to represent the ordered sequence of data. A stream represent a
uniform object oriented interface between the program and the input/output devices.
Stream classes
the java.io package contains a large number of stream classes that provide capabilities for
processing all types of data. These classes may be categorized into two groups based on the data type
on which they operate
1.Byte stream classes that provide support for handling I/O operation on bytes
2.Character stream classes that provide supprot fot managing I/O operation on characters.
Byte stream classes
java provide two kinds of byte stream classes input stream classes and output stream classes.
And also provide two kinds of character stream classes reader and writter
GENERICS
The term generics means parameterized types. Parameterized types are important because they
enable you to create classes, interfaces, and methods in which the type of data upon which they operate
is specified as a parameter.
Using generics, it is possible to create a single class that automatically works with different
types of data. A class, interface, or method that operates on a parameterized type is called generic.
Generalized classes, interfaces, and methods used Object references to operate on various types of

objects

Anda mungkin juga menyukai