Session 1
Session 1
rA
pt
ec
h
C
en
tre
U
se
O
Fundamentals of Java
nl
y
y
Explain the structured programming paradigm
nl
O
Explain the object-oriented programming paradigm
se
Explain the features of Java as a OOP language
U
Describe Java platform and its components
tre
List the different editions of Java
en
Explain the evolution of Java Standard Edition (Java SE)
C
Describe the steps for downloading and installing Java
h
ec
nl
O
se
The solution adopted to solve a problem is
U
provided as a sequence of instructions or
specifications of activity which enables a
tre
user to achieve the desired result.
en
Software Applications
C
h
ec
software applications.
rA
nl
O
It plays an important role while developing software applications.
It can be defined as the field of business or technology to which a problem
se
belongs.
U
Following figure shows the development of software application as a
tre
solution for managing various operations in a banking domain:
en
C
h
ec
pt
rA
Fo
nl
O
The development of software application is done using a programming
language.
se
A programming language is used as a medium for communicating the
U
instruction to the computer.
tre
The programming language enforces a particular style of programming
that is referred to as a programming paradigm.
en
Following are the two types of programming paradigm:
C
h
Structured Object-oriented
ec
Programming Programming
pt
rA
Paradigm Paradigm
Fo
nl
O
• In structured programming paradigm, the application
se
development is decomposed into a hierarchy of subprograms.
U
• The subprograms are referred to as procedures, functions, or
modules in different structured programming languages.
tre
• Each subprogram is defined to perform a specific task.
en
• Some of structured programming languages are C, Pascal, and
Cobol.
C
Following figure displays bank application activities broken down into
h
subprograms:
ec
pt
rA
Fo
nl
O
structured programming
languages are as follows:
se
Data is shared globally
U
tre
Efforts are spent on
en
accomplishing the solution
rather than focusing on
problem domain. C
h
ec
nl
O
programming style.
se
U
Some of the features that were aimed are as follows:
tre
Development of reliable software at reduced cost.
en
Reduction in the maintenance cost.
C
Development of reusable software components.
h
Completion of software development with the specified time
ec
interval.
pt
rA
nl
O
Designed around data, rather than focusing only on the functionalities.
se
U
Following shows different activities involved in the object-
tre
oriented software development:
en
C
h
ec
pt
rA
Fo
O
the functionality of the system.
se
U
Object-oriented Design (OOD) phases
tre
determines the process of planning a system in
which objects interact with each other to solve a
en
software problem.
C
h
Object-oriented Programming (OOP) deals with
ec
Unified Modeling Language (UML) helps to create visual models in the system.
The actual implementation of these visual models is done using an OOP
Fo
language.
nl
follows:
O
Object – Represents an entity which possesses certain features and
se
behaviors.
U
Class – Is a template that is used to create objects of that class.
tre
Abstraction – Is a design technique that focuses only on the essential
features of an entity for a specific problem domain.
en
Encapsulation – Is a mechanism that combines data and implementation
C
details into a single unit called class.
h
Inheritance – Enables the developer to extend and reuse the features of
ec
existing classes and create new classes. The new classes are referred to as
derived classes.
pt
different ways.
Fo
O
Any tangible or touchable entity in the real-world can be
se
described as an object.
U
Following figure shows some real-world entities:
tre
en
C
h
ec
pt
rA
Fo
O
Characteristics – Defined as attributes, properties, or features
describing the object.
se
Actions – Defined as activities or operations performed by the
U
object.
tre
Example of an object, Dog.
en
Properties – Breed, Color, and Age
C
Actions – Barking, Eating, and Running
h
ec
pt
defined.
nl
O
‘State’ refers to object’s characteristics or attributes.
se
‘Behavior’ of the software object comprises its actions.
U
Following figure shows a software object, a Car with its state and
behavior:
tre
en
C
h
ec
pt
rA
Fo
nl
O
• They help to understand the real-world.
se
1
U
• They map attributes and actions of real-world
tre
entities with state and behavior of software
en
2 objects.
C
h
ec
pt
rA
Fo
nl
O
Have common state and behavior.
Can be grouped under a single class.
se
Example: All car objects have attributes, such as color, make, or model.
U
Class:
tre
Can be defined that a class is a template or blueprint which defines the
en
state and behavior for all objects belonging to that class.
Following figure shows a car as a template and a Toyota car as an object or
instance of the class: C
h
ec
pt
rA
Fo
nl
members.
O
Fields – Are variables that depict the state of objects.
se
U
tre
en
C
h
ec
pt
rA
Fo
nl
object:
O
se
Class Object
U
Class is a conceptual model Object is a real thing
tre
Class describes an entity Object is the actual entity
en
Class consists of fields (data Object is an instance of a class
members) and functions
C
h
ec
pt
rA
Fo
nl
O
It helps programmers to develop wide range of applications that
can run on various hardware and Operating System (OS).
se
It is also a platform that creates an environment for executing
U
Java application.
tre
It caters to small-scale to large-scale problems across the
en
Internet.
C
Java applications are built on variety of platforms that range
h
from:
ec
nl
O
• Team of engineers from Sun Microsystems wanted to
se
design a language for consumer devices.
U
• Project was named as ‘Green Project’.
tre
• Team included: James Gosling, Mike Sheridan, and
Patrick Naughton.
1991
en
• Efforts were taken to produce portable and a platform
independent language that can run on any machine.
C
• Result was evolution of Java.
h
• Initially called ‘OAK’ and later renamed to Java .
ec
pt
rA
Fo
nl
• Internet and Web started emerging and was used
O
worldwide.
se
• Sun Microsystems turned Java into an Internet
programming language.
1995
U
• It emerged as a Web technology that added dynamic
tre
capabilities to the Web pages.
Java Moved: Middle-tier
en
nl
O
• Sun Microsystems was acquired by Oracle Corporation.
se
• The project Coin was launched to enhance Java
programming language.
U
2009 • Java EE 6 was released with simplified development and
tre
deployment model.
en
C
• The specification for Java 7 was approved by the Java
Community Process (JCP).
h
2010
ec
pt
rA
Fo
nl
O
It is characterized by following features:
se
Simple
U
tre
• Inherits its syntax from predecessor programming languages,
such as C/C++.
en
• Helps programmers to adapt to Java language without any
extra skills and extensive trainings.
C
• Eliminates the use of pointers, operator overloading, and
h
multiple inheritance features supported by predecessor
ec
languages.
pt
rA
Fo
nl
O
• Java is a pure OOP language that uses classes and objects that
address to the real-world problem domains.
se
• Even, the application development in Java starts with a class
designing.
U
tre
Robust
en
• C and C++ languages - Dynamic memory allocation/deallocation is
done manually through pointers that resulted in memory related
errors.
C
h
• Java incorporates:
ec
automatically.
rA
O
se
• Security checks applied at different layers ensures that the Java
programs are protected against malicious codes.
U
• Java programs that are accessed on the network are known as
tre
applets.
• Java applies security to applets by placing them in a sandbox that
en
ensures it should not have direct access to files or resources
C
available on the local system.
• Java Virtual Machine (JVM) which is a runtime environment for
h
executing Java programs applies its own security features to Java
ec
language.
pt
• JVM ensures that the code loaded for execution is well-formed and
rA
O
se
• Supports portability by converting application into architecture
neutral bytecode during compilation.
U
• Java has defined language specifications, such as size of
tre
primitive data types and operators that are independent of the
hardware platform.
en
• For example, an integer variable in Java always occupies 32 bits
on whichever machine the code is executed.
C
• These features satisfies the major goal of Java language which is
h
‘Write once, run anywhere’.
ec
pt
Multithreaded
rA
O
• Supports distributed programming in which resources can be
se
accessed across the network.
U
tre
Dynamic
en
• At runtime an application can dynamically decide which classes
it requires and loads them accordingly.
C
• This gives new perspective to Java for designing and developing
h
applications.
ec
pt
rA
Fo
nl
O
hardware-based platforms.
se
Contains Java Runtime Environment (JRE) with
U
components namely:
tre
Java Virtual Machine (JVM)
en
Java class library also referred to as Java Programming
Interface (Java API)
C
h
ec
pt
rA
Fo
nl
O
It is known as a virtual machine because it is an imitation of a
se
U
There are different implementations of JVM available for
tre
different platforms, such as Windows, Unix, and Solaris.
en
C
h
ec
pt
rA
Fo
nl
O
Is an intermediate form closer to
machine representation.
se
Is an optimized set of instructions
U
executed by the Java runtime
environment.
tre
This environment is known as
en
JVM.
The same bytecode can be
executed by different C
h
ec
implementations of JVM on
pt
various platforms.
rA
Fo
nl
O
These components are classes and interface grouped into
libraries referred to as packages in Java.
se
Example:
U
The Swing library provides classes for User Interface (UI) components.
tre
The Input/Output (I/O) library provides the standard interface for reading
en
and writing data into files stored in the system.
C
h
ec
pt
rA
Fo
nl
O
computers.
se
Java Enterprise Edition (Java EE) - Is built on top of Java SE
U
platform and provides a standard specification for developing
tre
and deploying distributed, scalable, and multi-tier enterprise
en
applications.
Java Mobile Edition (Java ME) - Is a robust platform for
C
developing embedded Java applications for consumer electronic
h
ec
nl
O
JRE
JRE provides JVM and Java libraries that are used to run a Java program.
se
JDK
U
Known as Java Development Kit (JDK).
tre
Is a binary software development kit released by Oracle Corporation.
Is an implementation of Java and distributed for different platforms, such as
en
Windows, Linux, Mac OS X, and so on.
C
Contains a comprehensive set of tools, such as compilers and debuggers that
are used to develop Java applications.
h
ec
pt
rA
Fo
nl
O
se
U
API - Provides the core functionality of the Java programming
tre
language.
en
Deployment Tools – Provides software for deploying the
C
developed applications to end-users.
h
User Interface Toolkits - Enables the developer to create
ec
nl
Releases Implementation
O
JDK 1.0 Creation of packages with classes in the standard library
se
JDK 1.1 Included an event delegation model for Graphical User
Interface (GUI) package AWT, JavaBeans, and Java
U
Database Connectivity (JDBC) API
tre
JDK 1.2 (Java 2) Included a new graphical API, named Swing. Also, added
APIs for reflection and collection framework (based on data
en
structure)
C
JDK 1.3 Included a directory interface to lookup for components,
named, Java Naming and Directory Interface (JNDI)
h
JDK 1.4 Included regular expression API, assertions, exception
ec
and processing
rA
JDK 1.6 Included script language, visual basic language support, and
improvements in the GUI
© Aptech Ltd. Introduction to Java/Session 1 35
y
Java SE 7 is the new major release of Java with internal version
nl
number as 1.7.
O
The lists of new features that are incorporated in the language
se
are as follows:
U
Supports the use of String class in the switch decision-making
tre
construct.
en
Integer types can be assigned with a binary number value.
Supports the use of underscore character ( _ ) between the digits of a
numeric value. C
h
An expandable try statement called try-with-resources
ec
se
Download button to install
U
the JDK on download page
tre
en
C
h
ec
pt
rA
Fo
U
Accept License Agreement.
tre
The agreement outlines that the
user agrees to Oracle by
en
installing the JDK
C
h
ec
pt
rA
Fo
en
Windows 32-bit OS, click
jdk-7u11-windows-
i586.exe under C
h
Download
ec
pt
rA
Fo
en
box, select the location
C to save the JDK
installer and then, click
h
ec
Save
pt
rA
Fo
nl
O
The installer installs development tools, source code, and the JRE
se
U
Following figure shows the directory structure of the installed
tre
JDK on the system:
en
C
h
ec
pt
rA
Fo
nl
O
se
Directory Description
U
bin Contains tools that are used for developing a
Java application, such as compiler and JVM
tre
db Contains a relational database named
en
Apache Derby
C
include Contains header files that are used to interact
with C applications
h
jre Represents the JRE used by the JDK
ec
pt
rA
Fo
nl
O
Environment variables are pointers pointing to programs or other
se
U
PATH - Set to point to the location of Java executables (javac.exe and java.
tre
exe).
en
CLASSPATH - Specifies the location of the class files and libraries needed
by the Java compiler to compile applications.
C
h
ec
pt
rA
Fo
nl
steps in Windows 7:
O
Right-click My Computer icon on the desktop and then, click Properties
se
U
Click Advanced system settings link on the left tab.
tre
Under Advanced tab, click Environment Variables.
In the System variables area, select the PATH variable and then, click Edit
en
C:\ WINDOWS\system32;C:\WINDOWS;C:\Program
pt
Files\Java\jdk1.7.0\bin
rA
Fo
nl
steps:
O
Right-click My Computer icon on the desktop and click Properties from
se
U
Click Advanced system settings link on the left tab.
tre
Under Advanced tab, click Environment Variables.
In the System variables area, click New button.
en
nl
O
programming, also referred to as programming paradigm.
se
In structured programming paradigm, the application
U
tre
subprograms.
en
In object-oriented programming paradigm, applications are
C
designed around data, rather than focusing only on the
h
functionalities.
ec
nl
O
platforms. Java platform is a software-only platform that
se
runs on top of the other hardware-based platforms.
U
The editions of Java platform are Java SE, Java EE, and Java
tre
ME.
en
The components of Java SE platform are JDK and JRE. JRE
C
provides JVM and Java libraries that are used to run a Java
h
program. JDK includes the necessary development tools,
ec