Introduction to JAVA

45

Transcript of Introduction to JAVA

Page 1: Introduction to JAVA

Introduction to JAVA

Java J2EE Training

Page 2: Introduction to JAVA

Introduction to Java• Java History• Features of Java• Java Versions• Application Area

Page 3: Introduction to JAVA

Features Of Java

• S i m p l e• O b j e c t - O r i e n t e d• P l a tf o r m

i n d e p e n d e n t• S e c u r e d• R o b u s t• A r c h i t e c t u r e

n e u t r a l• P o r t a b l e• D y n a m i c• I n t e r p r e t e d• H i g h P e r f o r m a n c e• M u l ti t h r e a d e d• D i s t r i b u t e d

Page 4: Introduction to JAVA

History of Java• James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java

language project in June 1991. The small team of sun engineers called Green Team.

• Originally designed for small, embedded systems in electronic appliances like set-top boxes.

• Firstly, it was called "Greentalk" by James Gosling and file extension was .gt.

• After that, it was called Oak and was developed as a part of the Green project.

• Originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation)

Page 5: Introduction to JAVA

James Gosling

Page 6: Introduction to JAVA

Features Of Java

• Simple– Similar to C and C++– Omits operator overloading, multiple inheritance– Goto statement is eliminated– Header files are eliminated– Explicit use of pointers– Garbage collection– A rich set of predefined classes

Page 7: Introduction to JAVA

Features Of Java

• Object-Oriented– Forces the programmer to use the classes and object– Class

• Member variables( data ) and member functions ( methods )

Page 8: Introduction to JAVA

Features Of Java

• Robust– designed for writing highly reliable or robust software:– automatic garbage collection, which prevents memory

leaks– Type safety of data– Extensive compile tome and runtime checking– Object Oriented Exception Handling of run time errors• Divide by zero exception.

Page 9: Introduction to JAVA

Features Of Java

• Architectural Neutral and Interpreted– compiler generates bytecodes– Easy to interpret on any machine– “Write once and run anywhere WORA”

Page 10: Introduction to JAVA

Features Of Java

• Powerful– Networking– Threads– Distributed Objects– Database Access– Graphics– Data structure library– Serialization– Digital Signatures

Page 11: Introduction to JAVA

Features Of Java

• Java is Popular

Page 12: Introduction to JAVA

Features Of Java

• Distributed– Supports TCP/IP– RMI– Access remote objects

via URL

Page 13: Introduction to JAVA

RMI

Page 14: Introduction to JAVA

Features of Java

• MultiThreaded– Parallel processing

Eg: Winword application saving document every 10 minutes using thread

Page 15: Introduction to JAVA

Major Java Editions

• Standard Edition• Enterprise Edition• Micro Edition

Page 16: Introduction to JAVA

Major Java Editions

• Standard Edition• Applications

– Desktop programing– Applets, Java FX– Big Data Apps

• Examples– MindCraft– Eclipse, Netbeans– GWT

Page 17: Introduction to JAVA

Features Of Java

• Enterprise Edition– Java EE ( formerly J2EE )

• Applications– Servlets, JSP, JSF, PrimeFaces– EJB, Spring and Hibernate

• Examples– Amazon.com– Ebay– Paypal

Page 18: Introduction to JAVA

Features Of Java• Java Micro Edition– Java running on small devices

• Applications– CellPhones,embedded, printers

• Examples– Blackberry, android( optimized java SE )

Page 19: Introduction to JAVA

Java SE VersionsYear Version Platform CodeName Features

1996 1 1.01997 1.1 11998 1.2 2 Playground Swings, Frameworks

2000 1.3 2 Kestrel Assertion, chained exceptions2002 1.4 2 Merlin2004 1.5 5 Tiger Generics, Varargs,

Printf, Enhanced for loop

2006 1.6 6 Mustang Updates to collection and swing

2011 1.7 7 Dolphin Diamond operator, Strings in swichTry-with resources

2014 1.8 8 - Lambda for functional programing,Streams for bulk updates

Page 20: Introduction to JAVA

JDK8• Java development kit– Bundle of software components that are needed to

develop java application – JDK consists • Java Compiler ( javac ) • Java Interpreter (java)• Java debugger• Java applet viewer• Javap

Page 21: Introduction to JAVA

JVM• The JVM is an abstract computing machine• It is responsible for Java's cross-platform portability

Page 22: Introduction to JAVA

JRE• The JRE is the software environment in which programs

compiled for a typical JVM implementation can execute• Implementation of the JVM• Code necessary to run Java programs• dynamically link native methods• manage memory• handle exceptions

Page 23: Introduction to JAVA

JIT

Page 24: Introduction to JAVA

JIT ( Just In Time Compiler)

Page 25: Introduction to JAVA

Object Oriented Programing• Object Oriented methodology• Advantages of object oriented approach• Features of Object Oriented approach

Page 26: Introduction to JAVA

Object Oriented Programing• Software development methodology• Maps to real world objects

– Graphics Car Real Cal

• Revolves around objects and classes• Object can communicate with each other• Software is divided into modules• Arranges the object in hierarchy.

Page 27: Introduction to JAVA

Object Oriented Programing• Consists of classes and object.• Object communicates with each other by passing messages

What is an object????

Page 28: Introduction to JAVA

Object Oriented Programing

• Object is an instance of class• Object is an real time entity– State – Behavior– Identity

NotePad Code{

filenameText:readOnly

Open()Close()Minimize()MaxmizeSave()}

Object = Instance Of Notepad

Page 29: Introduction to JAVA

Object StatesAn Object has state and behavior

Page 30: Introduction to JAVA

Objects

• Objects have state and behavior– State: What an object knows about itself– Behavior :What an object can do.

Object Name

State = charecterstics

Behaviour:

DogState: Name Breed Height Weight

Behaviour: eat() run() walk()

Page 31: Introduction to JAVA

Classes

• Collection of objectswheelsSeats

Car Music

GearsA.C

Engine

Page 32: Introduction to JAVA

Class• Class consists of

– Member variables and member methods.– State/ characteristics is represented via member variables– Member methods defines the responsibility of the class– Data within object represents its state.

– Messaging Application • State-> Member Variables

– To: – Text:

• Behaviour – Member functions– sendSms– Forward– delete

Page 33: Introduction to JAVA

Class

• Class is blue print– Logical structure– Set of instructions given to JVM , how to create instance ( object ) out

of it.

Page 34: Introduction to JAVA

Messages

ToText

sendSmsForwardcancel

Messages1: Tom

To : 123-456-7896Text : Hi Tom,

sendSmsForwardcancel

Messages2: Jack

To : 478-963-7896Text : Hi Jack

sendSmsSaveDelete

Class

Object Tom Object

Jack

Page 35: Introduction to JAVA

Classes and Objects

• Object communicates with each other by sending messages.– Bat Communicates with ball.

Page 36: Introduction to JAVA

Quiz• John is designing a contact management system . Application

should store the details of a person such as ( name, number, email ) . User should be able to add a contact ,update a contact and delete a contact.

Name of the class: Data to be recored. Functionality of contact management system.

Page 37: Introduction to JAVA

Contacts

Name:Numberemail

createContactupdateContactdeleteContact

Contacts1: Tom

Name: TomNumber : 456-789-7895Email :[email protected]

createContactupdateContactdeleteContact

Contacts2: Jack

Name: JackNumber 789-896-8965Email: [email protected]

createContactupdateContactdeleteContact

Page 38: Introduction to JAVA

Quiz

Identify the possible states of a computerHint: A) Sleep

Identify the possible state of a media player

Page 39: Introduction to JAVA

QuestionJohn, is developing a Calculator application. The application should accept two numbers from the user and perform addition, subtraction, multiplication and division on the numbers entered by the user. Help John to design the problem.

Page 40: Introduction to JAVA

Advantages Of Object Oriented Approach

• Realistic Modelling

Page 41: Introduction to JAVA

Advantages Of Object Oriented Programing

• Realistic ModellingBike

String color; String model;Integer speed;

Accelerate()Decelerate()Break()

Page 42: Introduction to JAVA

Advantages Of Object Oriented Approach

• Code Reusability

Contacts1: Tom

Name: TomNumber : 456-789-7895Email :[email protected]

createContactupdateContactdeleteContact

Page 43: Introduction to JAVA

Features Of Object Oriented Programing

• Flexibility to change:

WordAppV1

WordAppV2

NEW

Page 44: Introduction to JAVA

Features Of Object Oriented

• Modularity

Page 45: Introduction to JAVA

Features• Information Hiding– The basic idea is that if code chunk A doesn't

really need to know something about how code chunk B (which it calls) does its job, don't make it know it. Then, when that part of B changes, you don't have to go back and change A