Java features

25
Welcome To JAVA

Transcript of Java features

Page 1: Java features

Welcome

To

JAVA

Page 2: Java features

JAVA Java Operating System a general purpose OOPL developed by

Sunmicro System(USA) in the year 1991. Originally it was named as OAK & it was renamed in 1995 as

JAVA. JAVA can be used to develop two types of programs , these are

Application and Applets. When we create applications, java is not much different from

other languages. But in case of an applet, it can be dynamically downloaded across the network, which can react to user input.

To execute an application in java, the following two methods can be adopted :

* Compiling the source code into the BYTE CODE using the java compiler, i.e. javac

* Executing the byte code, using the JAVA interpreter, i.e. java

Page 3: Java features

Byte code The Source code is compiled by the java compiler. The

output of the compiler is not an executable code. Rather it is an intermediate code called as the BYTE CODE.

The byte code is stored in a file having extension “.class”

After byte code is generated by the compiler, it is interpreted by the JAVA interpreter to produce the programming result.

Page 4: Java features

JAVA Features

Some of the important features are described below

SIMPLE: java is simple because of the availability of Object Oriented features in it.

SECURED: When an executable program is downloaded, the risk of viral infection is severe, which may infect the system with a virus.

PORTABILITY: Many type of computer with different OS are available almost all computer are connected to the internet now a days. Therefore, the code must be sufficiently portable enough so that it can be dynamically downloaded to the various platforms.

Page 5: Java features

JAVA FeaturesOBJECT ORIENTED: java is a pure object oriented

programming language. The principle is “everything is an object” is implemented in java.

ROBUST: java is robust, because it is a strictly typed language. Due to this, the java compiler checks the code at compile time to allow the programmer correct the syntactical errors. It also handles the memory management mistakes and exceptional condition.

MULTI-THREADED: java supports multi-threaded programming. Which allow the programmer to write programs, that may do many things simultaneously.

Page 6: Java features

JAVA Features Though it is a Object oriented Programming Language is

supports the following features

o DATA ABSTRACTION : Abstraction refers to the act of representing essential features without including the background the explanation details.

o ENCAPSULATION : the wrapping up of data & function/methods into a single unit is known as encapsulation

o MODULARITY : Modularity is the property of system that has been decomposed into a set of cohesive & loosely coupled modules. So the act of partitioning program into individual is called modularity.

Page 7: Java features

JAVA Featureso INHERITANCE : It is the capacity of one class of

things to inherit from another class.

o POLYMORPHISM : It is a ability for a data to be processed in more than one forms. It is a property by which the same message can be sent to object of several different classes.

Page 8: Java features

JVM Java Virtual Machine

The java run time system is other wise known as the JVM.

Execution of every java program is under the control of JVM.

As the source code in JAVA is translated into the byte code , it becomes easier to run the byte code in a wide verity of environments.

Only requirement is the availability of JVM within than environment.

Page 9: Java features

JVM

JVM

(Byte Code)

Java

Interpreter

Machine Code

Page 10: Java features

Command Line Argument An argument which is supplied/passed to the main()

from the command line at the time of calling the main() by the java interpreters is called COMMAND LINE ARGUMENT.

The arguments supplied from the command line are of string type arguments. Therefore these arguments are stored in the parameter of main() which is an array of string objects i.e. args[]

Page 11: Java features

Method Overloading A class can contain two or more methods with same

name but different set of parameters. In this case the methods are said to be overloaded & the process is called method overloading.

In method overloading, methods may or may not have same return type.

Page 12: Java features

Constructor &Constructor Overloading

A constructor is a specialize method/member function of class

A constructor has the same name as the class in which it is declared.

A constructor is syntactically similar to a method with only exception that it has no return type not even void.

Once defined in a class, the constructor is automatically called immediately after the object is created.

Page 13: Java features

Constructor &Constructor Overloading

Like method overloading, constructor can also be over loaded.

Constructor overloading is the process by which two or more constructor defined in a class with different list of parameters.

When overloaded constructor are called, java compiler calls that constructor whose list of parameter exactly matches with the values received from the calling program.

Page 14: Java features

Inheritance The mechanism of deriving a new class from an

existing class is called inheritance.

The class from which the new class is derived is called SUPER CLASS and the class which is derived is called SUB CLASS

Inheritance allows

-> The creation of hierarchical classification

->Code reusability

Page 15: Java features

Types of Inheritance Single Inheritance

A

class

B

class

Page 16: Java features

Types of Inheritance Multilevel Inheritance

A

• Super Class

B

• Sub Class of A (Super class of C)

C

• Sub Class of B

Page 17: Java features

Types of Inheritance Hierarchical Inheritance

A

class

X

class

Y

class

Z

class

Page 18: Java features

Method Overriding When a method in a subclass is exactly same as in

method in a super class, then method overriding takes place.

In method overriding, the subclass and super class method have same name, same return type and same parameter list.

Due to inheritance, the subclass method overrides the super class method. Therefore when an overridden method is called from within a subclass, it always refers to the method define in the sub class

Page 19: Java features

Interface Since java does not support multiple inheritance, it

provides an alternate approach to multiple inheritance and that approach is Interface.

An interface, is a kind of class that lacks instance variable and its methods are declared without only body.

Therefore using an interface, it is specified that what a class must do but not how it does it.

Variable declared with in a interface must have FINAL declaration

Page 20: Java features

Interface Syntax of declaration of variables

static final <type of variable> <variable name>=<value>

E.g. : static final int a=5;

Syntax of declaration of methods

<return type> <method name>(<parameter list>);

E.g. : float compute(float r);

Page 21: Java features

Package Package are container for classes, that are used to keep

the class name space compartmentalized

Packages are stored in a hierarchical manner and packages are explicitly imported into new class definition

The classes defined inside a package are not accessible by the code outside that package.

Page 22: Java features

Package Declaring package

package <package_name>;

E.g. : package mypack;

Page 23: Java features

Package Importing Package

Syntax : import <package_name>.<class_name>/*;

E.g.: import mypack.addcls;

Or

import mypack.*;

Page 24: Java features

Multithreading Java provides built in support for multithreaded

programming.

A multi threaded programming contains two or more parts that can concurrently.

Each part of a program is called thread.

Each thread has its own separate path of execution.

Multithreading makes the maximum use of CPU.

Page 25: Java features

Thank

you