java programming- oop concept

15
TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, Dwarka Institutional Area, New Delhi-75 Affiliated Institution of G.G.S.IP.U, Delhi BCA JAVA PROGRAMMING BCA 206 JAVA Basics Keywords: oop, jdk, applets

Upload: trinity-dwarka

Post on 17-Feb-2017

185 views

Category:

Education


0 download

TRANSCRIPT

Page 1: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New

Delhi-75Affiliated Institution of G.G.S.IP.U, Delhi

BCAJAVA PROGRAMMING

BCA 206

JAVA Basics Keywords: oop, jdk, applets

Page 2: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

OOP Concept

Class • A class is a blueprint or prototype• A class is a set of attributes and behaviour

shared by similar object.• Classes are user defined datatype.• A class defines what data can be in an object,

and what operations are performed by the methods

Page 3: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

Object

• It is a tangible entity• It is a instance of class• An object consists of data and functions known as methods which use or

change the data. (Methods are similar to procedures or functions in other languages.)

• An object is a software bundle of related variables and methods. Software objects are often used to model real-world objects you find in everyday life.

• These objects have state and behavior .• A car can be modelled by an object. A car has state (how fast it's going, in

which direction, its fuel consumption, and so on) and behavior (starts, stops, turns, slides, and runs into trees).

• The espresso machine can be modelled as an object. It has state (water temperature, amount of coffee in the hopper) and it has behavior (emits steam, makes noise, and brews a perfect cup of java).

Page 4: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

Principles

• Abstraction• Encapsulation• Inheritance• Polymorphism

Page 5: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

JAVA

• Java technology is both a programming language and a platform.

Page 6: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

• The massive growth of the Internet and the World-Wide Web leads to a completely new way of looking at development and distribution of software.

• To live in the world of electronic commerce and distribution, Java technology must enable the development of secure, high performance, and highly robust applications on multiple platforms in heterogeneous, distributed networks.

JAVA

Page 7: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

Introduction to Java

• Java is an Object oriented programming language platform.

• Developed by Sun Microsystems in 1991• Original name was Oak.• It was conceived by James Gosling.• It has built-in application programming

interface (API) that can handle graphics and user interfaces and that can be used to create applications or applets.

VERSIONS

Page 8: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

JDK Versions

• JDK 1.02 (1995)• JDK 1.1 (1996)• Java 2 SDK v 1.2 (JDK 1.2, 1998)• Java 2 SDK v 1.3 (JDK 1.3, 2000)• Java 2 SDK v 1.4 (JDK 1.4, 2002)• Java 2 5.0 (2006)• Java SE 7(mid 2010)

Page 9: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

JDK Editions

• Java Standard Edition (J2SE)– J2SE can be used to develop client-side standalone

applications or applets.• Java Enterprise Edition (J2EE)– J2EE can be used to develop server-side applications such as

Java servlets and Java ServerPages. • Java Micro Edition (J2ME). – J2ME can be used to develop applications for mobile

devices such as cell phones.

Page 10: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

Applets, Servlets and Applications

• An applet is designed to be embedded in a Web page, and run by a browser

• Applets run in a sandbox with numerous restrictions; for example, they can’t read files and then use the network

• A servlet is designed to be run by a web server• An application is a conventional program

Page 11: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

Features

• Simple• Object oriented• Robust : Memory management and Exception handling• Architecture neutral and portable• Compiled and interpreted• Distributed• Secure• Multithreaded• High performance • Dynamic• Garbage Collected

Page 12: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

Working of Java

• Java solves the problem of platform-independence by using byte code.

• The Java compiler does not produce native executable code for a particular machine like a C compiler would. Instead it produces a special format called byte code.

• Java byte code starts with CA FE BA BE This looks a lot like machine language, but unlike machine

language Java byte code is exactly the same on every platform.

• This byte code fragment means the same thing on a Solaris workstation as it does on a Macintosh PowerBook.

Page 13: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

Platform

Working of JAVA contd..• Java programs that have been compiled into byte code still need an

interpreter to execute them on any given platform. • The interpreter reads the byte code and translates it into the native

language of the host machine on the fly. • The most common such interpreter is Sun's program java (with a little j).

Since the byte code is completely platform independent, only the interpreter and a few native libraries need to be ported to get Java to run on a new computer or operating system.

• The rest of the runtime environment including the compiler and most of the class libraries are written in Java.

• All these pieces, the javac compiler, the java interpreter, the Java programming language, and more are collectively referred to as Java.

Page 14: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

• A class is a template for a Java object, and each class is compiled into a separate file called a class file.

• The Java Virtual Machine itself knows nothing about the Java language, but instead understands class files and the virtual machine instruction set.

• Each class file contains class constants, information about instance variables (variables created for each new object of a class), as well as method code (in bytecode format) and various symbol tables.

• When the programmer asks for a new instance of a class the compiler will generate a new instruction for the virtual machine, along with a reference to the required class name.

Working of JAVA contd..

Page 15: JAVA PROGRAMMING- OOP Concept

TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75

• The virtual machine will then locate and load the appropriate class file, and create a new object according to the template the file contains.

• Within each class file, all references to methods or fields of other classes are stored textually, in an area of the file known as the constant pool.

• This is to ensure that classes can be recompiled with new fields or methods, without breaking older code that uses the same class. This dynamic linking helps to make Java a robust language.

Working of JAVA contd..