Sie sind auf Seite 1von 7

JAVA

1. Java is a simple and powerful object oriented programming language.


2. Java originated at Sun Microsystems, Inc. in 1991.
3. It was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and mike Sheridan.
4. The main aim of java is to provide a platform independent programming language.
5. Platform Independent: It is not depending on any operating system. We can write any platform
and we can compile and execute this java program any platform. When we compile java
program JVM (Java Virtual Machine) converts platform independent byte code.
6. JVM: Java was designed with a concept of “write once and run everywhere”. Java virtual
Machine plays the central role in this concept. JVM is the environment in which java programs
execute. When the source code (.java file) is complied, it is translated into byte codes and then
place into (.class file). A JVM can either interpret the byte code one instruction at a time or byte
code can be compiled further for the real microprocessor using what is called a just-in-time
compiler.
7. Features of JAVA
a. Reusability of code
b. Emphasis on data rather than procedure
c. Data is hidden and cannot be accesses by external functions
d. Objects can communicate with each other trough functions
e. New Data and functions can be easily added
8. OOPS:
a. Abstraction:
Abstraction is nothing but data hiding. In Java we have some pre-defined objects;
regularly we use those objects even without knowing what happening inside of that
function. This is called abstraction.
For example, for driving a car, you just have to know the process of driving it but
you don't require to know the background details. Similarly JAVA provides the facility of
data abstraction where you can perform the program without knowing its background
details.
b. Encapsulation:
Encapsulation is the technique of making then fields in a class private and providing
access of the fields via public methods. If a field is declared private, it cannot be
accessed outside of the class, thereby hiding the fields within the class. For this reason,
encapsulation is also referred to as data hiding.
The main benefit of encapsulation is the ability to modify our implemented code
without breaking the code of others who use our code. With this feature encapsulation
gives maintainability, flexibility and extensibility to our code.
c. Inheritance:
Inheritance can be defined as the process where one object acquires the properties of
another. With the use of inheritance the information is made manageable in a
hierarchical order. There are two key words we use in inheritance are extends and
implements. In Inheritance we can find IS-A relationship.
EX:

The above example these are true:


1. Animal is the super class of Mammal class.
2. Animal is the super class of Reptile class.
3. Mammal and Reptile are sub classes of Animal Class.
4. Dog is the subclass of both Mammal and Animal Classes.

IS-A Relationship:

Mammal IS-A Animal

Reptile IS-A Animal

Dog IS-A Mammal

Hence: Dog IS-A animal as well

Implements:

The implements keyword is used by classes by inherit from interfaces. Interfaces can
never be extended.
d. Polymorphism
Polymorphism is a term that describes a situation where one name may refer to
different methods.
In java there are two types of polymorphism: overloading type and overriding type.
1. Overloading:
Overloading occurs when several methods have same names with different method
signatures. Overloading is determined at the compile time.

2. Overriding:
Overriding occurs when a class method has the same name and signature as a
method in parent class. Overriding is determined at the run time.
9. Interface:
An interface is a collection of abstract methods.
Similarities between Class and interface:
1. An interface can contain any number of methods.
2. An interface is written in a file with a .java extension, with the name of the interface
matching the name of the file.
3. The byte code of an interface appears in a .class file
4. Interfaces appear in packages, and their corresponding byte code file must be in a
directory structure that matches the package name

Dissimilarities between class and interface:

1. We cannot instantiate an interface


2. An interface does not contain any constructors
3. All of the methods in an interface are abstract
4. An interface cannot contain instance fields. The only fields that can appear in an interface
must be declared both static and final.
5. An interface is not extended by a class; it is implemented by a class
6. An interface can extend multiple interfaces.
EX:
10. Abstract Class: An Abstract class is a class that cannot be instantiated. All other functionality of
the class still exists, and its fields, methods, and constructors are all accessed in the same
manner.
If we want to access abstract class methods and variables we have to create another class and
extend to the abstract class. Then we can access abstract class methods and variables.
11. Abstract Method:
a. The class must also be declared abstract. If a class contains an abstract method, the
class must be abstract as well.
b. Any child class must either override the abstract method or declare it-self abstract.
c. A child class that inherits an abstract method must override it. If they do not, they must
be abstract, and any of their children must override it.
d. Ref: Employee.java, Salary.java, main.java
12. Keyword: Keywords are reserved words that are predefined in the language
13. Class: Class is nothing but a blueprint for objects which defines its properties and behaviors. A
class can contain fields and methods to describe the behavior of an object. Methods are nothing
but members of a class that provide a service for an object
14. Object: An object is an instance of a class created using a new operator. The new operator
returns a reference to a new instance of a class.
The process of creating objects from a class is called instantiation.

Data Structures:
There are many classes and Interfaces are very powerful and perform a wide range of functions
in java util package.
Enumeration:
Enumeration interface isn’t itself a data structure, but it is very important with the context of
other Data Structures. Enumeration interface retrieves successive element from a data
structure.
Enumeration interface defines the methods by which we can enumerate the elements in a
collection of objects.
Methods:
boolean hasMoreElements();
Object NextElement();

BitSet:
A bitset is a class creates a special type of array that holds bit values. This is similar to
vector class.
Vector:
A vector is a class similar to dynamic arrays. Vector is synchronized. Like an array,
elements of a Vector object can be accessed via an index into the vector.
The nice thing about using the Vector class is that you don't have to worry about setting it to a
specific size upon creation; it shrinks and grows automatically when necessary.
Stack:
Stack class implements Last-In-First-Out(LIFO) order stack of elements. It is subclass of
vector. Stack includes all the methods defined by Vector, and adds several of its own.
Methods:
Boolean empty(); tests stack is empty or not
Object peek(); returns top of the element
Object pop(); remove the element from the top
Object push(Object element); add element to top and returns same element
Int search(Object element); search stack element

Dictionary:
A dictionary is an abstract class which defines a data stricter for mapping keys to values.
Methods:
Enumeration elements(); returns an enumeration
Object get(Object key); returns object that contains a the value associated with key.
Boolean isEmpty(); returns true if the dictionary is empty.
Enumeration keys(); returns enumeration of keys from the dictionary
Object put(Object key, Object value); Insert key and value
Object remove(Object key);removes key and value
Int size(); returns size of dictionary

Hashtable:
Hashtable is also like Dictionary. It stores key and a value.
Properties:
Properties is a subclass of Hashtable. It is used to maintain lists of values in which the
key is a String and the value is also a String.

Multi Threading:
Java provides built-in support for multi threaded programming. Multi threaded program
contains two or more parts that can run concurrently, each part of such program is called a
thread and each thread defines a separate path of execution.
A multithreading is a specialized form of multitasking.
process: A process consists of the memory space allocated by the operating system that can
contain one or more threads.

REF:

1. http://www.tutorialspoint.com/java/index.htm
2. http://www.programmersheaven.com/2/FAQ-JAVA-What-Is-Polymorphism

Das könnte Ihnen auch gefallen