Java Color
Java Color
Visibility
Default
Private Protected Public
/Friendly
1. Private àPrivate visibilities specify that this section can not be
access directly from the out side of the object but can be access from
any where of object. That means, private section can be access from
public, friendly and protected section of the object .So finally we can
say that private section is visible in a single object at a time. Private
section is not inheritable. That means function and variable present in
the private section
Class is an user define data type which is used to create new data
type as the requirement of the user by encapsulating different
standard data type or other user define data type in a single unit.
It is also possible to say that common name of set of object is
called class. alternately we can say that class is the blue print or
logical design of object in the encapsulated form of instance
variable and methods so in class methods and variable are present
with there appropriate type . In java 4 types of visibility are present
and they are applied in class in design time. It is also known to us
that the method are common for a set of object so all method
should be public.
1. Private àPrivate visibility specifies that this section can not
be access directly from the out side of the object but can be access
from any where of object. That means private section can be access
from public, friendly and protected section of the object .So finally
we can say that private section is visible in a single object at a
time. Private section is not inheritable. That means function and
variable present in the private section.
2. Deffoult/Friendelly àThe default visibility is friendly in
java. The default section can be access directly from the out side of
the object. That means the default section can be access in entire
program of a particular package (Collection of related class).
Default section can be inherited into the subclass. That means
variable and function present in the default section. Default section
can be override and overwrite in the subclass default section can
contains instance variable as well as methods.
3. Protected à The protected section can also be access directly
from the out side of the object. That means the protected is visible
in entire program in a particular package same as default. We
know that the default section can not be access in another package
but protected section can be access other package in subclass.
protected section can not be access in non subclass in other
package protected section can contains methods as well as instance
5
variable protected can be inherit into sub class and the method and
instance variable can be overwrite and override in the subclass . To
protect overwriting and overriding the final keyword are used
before the visibility of function and variable.
A.Function.
B.Inheritance.
C.Package.
Inheritance is a process by which we can create new classes using
existing sub class is called super class and the new class is called
base class. Alternately we can say that inheritance is a process to
implement the concept of parent child relationship that means in
7
java more than one super class can not be present for a single
subclass. That means more than one super class can not inherit into
a single subclass so multiple as well as hybrid inheritance can not
be implemented in java. The main purpose of is to reuse the
existing code present in super class in subclass the following
advantage are present in inheritance.
Types of inheritance-----
INHERETANCE
HERERICAL/TREE
SINGLE/SIMPLE MULTILEVEL STRUCTRE
CLASS A
CLASS B
CLASS C
B C D E
F G H I J K L M
Abstract classà Abstract class is that type of the class which has no
capacity to create object. Abstract class must be inherit into subclass to
create existence of the abstract class. Abstract class is used as a super
class in inheritance.
MULTITHREADING
Multithreading is those type of programming concept which is used to
implement the concept of multitasking. Thread means, small program
which can be executed at a time. Multithreading means more then one
smalls program which are executed simultaneously not concurrently
using small span of time and using the round robin scheduling. We know
that JVM is an operating system over the operating system, so in JVM a
scheduler is present which is responsible to implement multithreading.
In multithreading threads are different states :-
(1) New born state
(2) Ready state
(3) Running state
(4) Suspended state (temporarily)
(5) Terminated state or killed
In JAVA a thread class is present
which is used to implement the concept of multithreading. A run( )
function is present in the thread class which is used to run a thread. An
init( ) function is present, which is used to initialize a thread or new
born thread is created. Start( ) function is also present, which is used
to ready a thread to execute. Stop( ) function is present which is
responsible to terminate a thread. For temporarily suspended of thread
three functions are present and they are-
(1) Sleep
(2) Suspended
(3) Wait
The sleep( ) is automatically deactivated
after specific time given in millisecond in the sleep( ) function. The
suspended( ) function is deactivated when a resume( ) function is
called. Wait function is deactivated when a notify( ) is called.
16
Exceptions are a type of error besides then the syntax error or logical
error as divide by zero. Alternately we can say that those types of error
which are not belonging to syntax error or logical error are called
EXCEPTION. Exceptions are divide in to two categories :-
(1) Synchronous or software related exception.
(2) Asynchronous or hardware related exception.
A synchronous type of exception is also
called software exception. Which are arise due to software limitation,
like arithmetic exception, input/output exception, number format
exception etc. synchronous exceptions can be smoothly handled by
JAVA programming language, because huge number system defined
exception classes are present. The popular exceptions classes are –
input/output exception, arithmetic exception, number format exception,
array index out of bound exceptions, string index out of bounds
exception, class not found exception, sql exception etc. using system
defined exception classes any type of exception can be handled besides
then the system defined exception. User can also create his own
exception classes to handle exceptions. In JAVA programming the
following tools are used to handle exceptions.
(1) Try ( )
(2) Catch ( )
(3) Throw ( ) /Throws ( )
The try block is used to identify
exception. After identifying the exception JAVA automatically throws
the exception to appropriate catch block, if the exceptions are system
defined exception. If the exceptions are user defined exceptions then the
throw statement is used to throw the exception to appropriate catch
block. A single function can contain more then one try block and
correspondingly more then one catch block. It is also possible to present
more then one catch block corresponding to a single try block.
Asynchronous exceptions are those types of
exceptions which are arises due to hardware failure, which can not be
handled by the JAVA programming language. Asynchronous exceptions
can not be handled by any programming language.
19
We know that methods are common for a set of object and instance
variables are distinct for every object. Methods are allocated their
memory at the time of class declaration and instance variables are
allocated their memory at the time of object creation. In JAVA
programming language objects are allocated their memory at the time of
execution using the new operator. After allocation of memory the
instance variables are binds with their associated methods at the time of
execution. This type of data binding is also called dynamic binding or
late binding or execution time binding or run time binding. In JAVA
object can not allocate their memory statically at the time of
compilation. They allocate their memory at the time of execution. So
only dynamic binding is present in JAVA. The concept of static binding
is partially implemented using the concept of static variables and static
function. Which are allocate their memory at the time of compilation
and can be executed without object. The concept of dynamic binding is
present in JAVA due to JAVA supports distributed processing. In
distributed processing a large program can be decomposed to its smaller
segments and distributed among all the processors which are connected