Top Banner
CORE JAVA LESSONS WRITE ONCE RUN ANYWHERE [email protected]
21
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Core java lessons

CORE JAVA LESSONSWRITE ONCE RUN ANYWHERE

[email protected]

Page 2: Core java lessons

OOPS Concept

Think, walk and live in

Object oriented paradigm

Page 3: Core java lessons

OOPS Concept

Classes and Objects

Encapsulation

Abstraction

Inheritance

Polymorphism

Page 4: Core java lessons

OOPS Concept – Classes and Object

Class - A class can be

defined as a template/blue

print that describes the

behaviours/states that object

of its type support.

Object - Objects have

states and

behaviours/states .

Example: A dog has states -

color, name, breed as well

as behaviors -wagging,

barking, eating. An object is

an instance of a class.

Page 5: Core java lessons

OOPS Concept – Encapsulation

Class A

Private Data

Operations

Class B

Private Data

Operations

• Encapsulation is the mechanism that binds

together code and the data if manipulates,

and keeps both safe from outside

interference and misuse.

• One way to think about encapsulation is as

a protective wrapper that prevents the code

and data from being arbitrarily accessed by

other code defined outside the wrapper.

Page 6: Core java lessons

OOPS Concept – Abstraction

• Abstraction refers to the act of representing essential features without

including the background details.

• hiding unnecessary data from the users and making the application as

user friendly then it is called as abstrcation

Data abstraction is a

technique of creating new

data types that are well suited

to an application

It allows creation of user

defined data types, having

the properties of built in data

types and set of permitted

operations

Page 7: Core java lessons

OOPS Concept – Inheritance

• Inheritance is the property which allows a Child class to inherit some

properties from its parent class.

• New Data types can be defined as extension to previous defined types

• Base class or parent class or super class -> Derived class or child class( or

sub class

• Sub class inherits properties from super class

Page 8: Core java lessons

OOPS Concept – Inheritance

Example

Page 9: Core java lessons

OOPS Concept – Inheritance

(Reusability)

• If multiple class have common attributes/method, these methods can be

moved to common class – parent class

• Example: Rectangle and circle method have a common methods move(),

which changing the centre co-ordinates

Page 10: Core java lessons

OOPS Concept – Inheritance

(Specialization)

• Specialized behavior can be added to the child class

• In this case behavior will be implemented in the child class

• For example, The implementation of area() method in the circle class is

different from the rectangle class

Page 11: Core java lessons

OOPS Concept – Multiple Inheritance

• Inherit properties from more than one class

• This is called multiple inheritance

• Multiple inheritance is not supported in java (Diamond problem) but is

supported in c++

Page 12: Core java lessons

OOPS Concept – Polymorphism

• Polymorphic which means “many forms” has Greek roots

• Poly – many

• Morphos – forms

• Polymorphism gives us the ultimate flexibility in extensibility. The ability to

define more than one function with the same name is called Polymorphism.

• Method overloading

• Method Overriding

Page 13: Core java lessons

Benefits of Java Language

• Simple and powerful

• Safe

• Object oriented

• Robust

• Architecture neutral and portable

• Compiled and interpreted

• Multi threaded

• Distributed

Page 14: Core java lessons

Java is a simple language

• Java is designed to be easy for the professional programmer to learn and

use.

Page 15: Core java lessons

Java is a portable

• Write once run every where

Page 16: Core java lessons

Java is a compiled and interpreter

language

Page 17: Core java lessons

Java is robust language

• Robust means Strong. Java

programs are strong and they don’t

crash easily like c and c++. why?

• Excellent Exception handling

• Memory Management

• Class loader sub system of

JVM will allocate necessary

memory for java program.

• Garbage Collector de allocates

the memory

Page 18: Core java lessons

Java for distributed environment

• Java is designed for the distributed environment

of the Internet. Because it handles TCP/IP

protocols

• Java supports RMI (Remote Method Invocation).

• This feature enables a programmer to invoke

methods across the network.

Page 19: Core java lessons

Getting started - setting up your

environment

• Download and install jdk6 or jdk7 from oracle.com

• Check environment variable for java and javac commands

• Check java and javac command from shell or command prompt

Page 20: Core java lessons

Getting started – Java Tools

Tool Name Brief Description

appletviewer Run and debug applets without a web browser.

apt Annotation processing tool.

See Annotation Processing Tool for program

annotation processing.

extcheck Utility to detect Jar conflicts.

jar Create and manage Java Archive (JAR) files.

See Java Archive Files page for the JAR

specification.

java The launcher for Java applications. In this release,

a single launcher is used both for development and

deployment.

The old deployment launcher, jre, is no longer

provided.

javac The compiler for the Java programming language.

javadoc API documentation generator.

See Javadoc Tool page for doclet and taglet APIs.

javah C header and stub generator. Used to write native

methods.

javap Class file disassembler

jdb The Java Debugger.

See JPDA for the debugger architecture

specifications.

Page 21: Core java lessons

Getting started - Writing first java program

• Writing First Hello world java program

• Compiling and running java program