core java lessons
DESCRIPTION
Core Java LessionsTRANSCRIPT
CORE JAVA LESSONSWRITE ONCE RUN ANYWHERE
OOPS Concept
Think, walk and live in
Object oriented paradigm
OOPS Concept
Classes and Objects
Encapsulation
Abstraction
Inheritance
Polymorphism
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.
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.
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
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
OOPS Concept – Inheritance
Example
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
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
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++
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
Benefits of Java Language
• Simple and powerful
• Safe
• Object oriented
• Robust
• Architecture neutral and portable
• Compiled and interpreted
• Multi threaded
• Distributed
Java is a simple language
• Java is designed to be easy for the professional programmer to learn and
use.
Java is a portable
• Write once run every where
Java is a compiled and interpreter
language
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
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.
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
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.
Getting started - Writing first java program
• Writing First Hello world java program
• Compiling and running java program