Java Programming: Advanced Topics 1
Introduction to Advanced Java Programming
Chapter 1
Java Programming: Advanced Topics 2
Objectives
• Review what Java is and differences between the three editions of the Java 2 platform: J2SE, J2EE, and J2ME
• Explore the context in which Java and related technologies are evolving
• See how Java supports object-oriented programming and look at some popular design patterns
Java Programming: Advanced Topics 3
Objectives (Cont.)
• Learn how to use the basic tools that version of Java 2 Software Development Kit provides, especially javac, java, javadoc, and jar
Java Programming: Advanced Topics 4
Overview of the Java Platform
• The Java language is object-oriented• Java code is architecture-neutral and portable• Java is network-savvy• Java programs are secure• Java is high performance
Java Programming: Advanced Topics 5
Java Programs and Components • JavaBeans: classes or program components
that conform to strict programming conventions• Applets: components that can be launched from
HTML documents and run in a Web browser or applet viewer utility
• Servlets: components that generate content for Web pages at runtime
• Enterprise JavaBeans (EJBs): server-side components used in distributed enterprise environments
Java Programming: Advanced Topics 6
The Three Editions of the Java 2 Platform
• The Java 2 platform comes in three versions:– Java 2 Standard Edition (J2SE)– Java 2 Enterprise Edition (J2EE)– Java 2 Micro Edition (J2ME)
Java Programming: Advanced Topics 7
Containers in the n-Tier J2EE Architecture
Java Programming: Advanced Topics 8
A Brief History of the Java Platform
• 1995: Version 1.0 (Sun Microsystems)• 1997: Version 1.1• 1998: Java 2 platform• 1999: J2SE, J2EE, and J2ME• 2001: Version 1.3 of J2SE• 2002: Version 1.4• 2002: Version 1.3 of J2EE
Java Programming: Advanced Topics 9
Object-Oriented Programming in Java
• The key benefits of object-oriented programming are:– code reuse– flexibility to respond to changing circumstances and
requirements– ease of maintenance
Java Programming: Advanced Topics 10
Object-Oriented Programming in Java (Cont.)
• A program is a collection of objects that send messages to each other
• Object-oriented analysis and design (OOAD): – First stage: perform object-oriented problem analysis– Second stage:
• Identify classes to be implemented• Identify fields and methods the classes must contain to
model the behavior of real-life objects
Java Programming: Advanced Topics 11
Object-Oriented Methodology
• Java lends itself to iterative and incremental object-oriented development methodology
• In large projects, functionality is typically added in stages and each identifiable stage is an increment
• An iteration is a short-term development cycle within an increment
Java Programming: Advanced Topics 12
Object-Oriented Features of Java
• Java supports the following fundamental features of all object-oriented languages:– Abstract data types– Encapsulation– Inheritance– Polymorphism
Java Programming: Advanced Topics 13
Design Patterns and Frameworks
• Design pattern: proposed solution to common design problem
• Frameworks: collections of reusable classes• Popular design patterns:
– Model-View-Controller design pattern – Singleton design pattern – Factory design pattern– Adapter design pattern– Façade design pattern
Java Programming: Advanced Topics 14
Model-View-Controller Design Pattern
Java Programming: Advanced Topics 15
An Implementation of the Singleton Design Pattern
Java Programming: Advanced Topics 16
An Implementation of the Factory Design Pattern
Java Programming: Advanced Topics 17
Standard SDK Tools
• The Java platform includes a tool set for developing Java programs
• The J2SDK tools run only in a command-line window and provide basic functionality
Java Programming: Advanced Topics 18
Standard SDK Tools(Cont.)
• Standard J2SDK tools:– javac compiler– java launcher– javadoc documentation builder– jar packaging utility
Java Programming: Advanced Topics 19
How the Launcher Finds Classes
• Java command locates bytecode files by class name
• Launcher loads bytecode from the file with the extension .class and with the case-sensitive base filename that matches the class name
Java Programming: Advanced Topics 20
How the Compiler Finds Classes
• For public classes– Source file must have the same name as the
class– Every public class must be in a separate file
• javac command has a -sourcepath option to specify the location of input source files when different from the location of compiled classes
Java Programming: Advanced Topics 21
javadoc Comments
• The javadoc tool is a utility for generating HTML documentation directly from comments in Java source code
• Doc comments – Start with a slash and two asterisks (/**)– Terminate with one asterisk and a slash (*/)
Java Programming: Advanced Topics 22
javadoc Comments(Cont.)
• Doc comments can appear before the following kinds of declarations:– Class– Interface– Field– Method
Java Programming: Advanced Topics 23
javadoc Comments(Cont.)
Java Programming: Advanced Topics 24
Creating HTML from javadoc
• To get HTML output in the standard format, run the javadoc program
• Doclet: plug-in program for javadoc that formats and outputs required documentation
• The javadoc tool – Preprocesses doc comments into a data structure– Delegates to a doclet conversion of data into output
Java Programming: Advanced Topics 25
An index.html File Generated by javadoc
Java Programming: Advanced Topics 26
Packaging Programs for Distribution
• The standard way to distribute J2SE is to combine files into a Java archive file using the jar tool
• Before running the jar tool, make sure your files are in the proper folders
Java Programming: Advanced Topics 27
Summary• The Java 2 platform comes in three
versions: Java 2 Standard Edition (J2SE), Java 2 Enterprise Edition (J2EE), and Java2 Micro Edition (J2ME).
• You can write different kinds of programs in Java including standalone applications, applets, servlets and JSPs, JavaBeans and Enterprise JavaBeans (EJBs).
Java Programming: Advanced Topics 28
Summary (Cont.)• Java is an object-oriented language and lends
itself to the creation of reusable components.• Java language supports abstract data types,
encapsulation, inheritance, and polymorphism, uses iterative and incremental methodology, and implements design patterns.
• The SDK includes command line tools: the javac compiler, java launcher, javadoc documentation builder, and jar packaging utility.