introduction to java programming n.
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to Java Programming PowerPoint Presentation
Download Presentation
Introduction to Java Programming

Loading in 2 Seconds...

play fullscreen
1 / 41

Introduction to Java Programming - PowerPoint PPT Presentation

  • Uploaded on

Introduction to Java Programming. Cheng-Chia Chen Feburary 2008. Course web page. Lecture 1. Introduction. Cheng-Chia Chen. Contents. What is Java? Features of Java Evolution of Java Develop first Java program Deploy java programs through the internet via Java applet

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Introduction to Java Programming' - ilario

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introduction to java programming

Introduction to Java Programming

Cheng-Chia Chen

Feburary 2008

  • What is Java?
  • Features of Java
  • Evolution of Java
  • Develop first Java program
  • Deploy java programs through the internet
    • via Java applet
    • via Java Web Start
what is java
What is Java?

Java is

  • a programming language,
    • defined in The Java language specification (v1,v2,v3)
  • a virtual machine,
    • Defined in The java virtual machine (v1, v2)
  • a platform
    • Standard edition (java se):
    • Java platform standard edition 6.0
    • Enterprise edition(j2ee): V5.0
    • Micro edition (j2me): v1.0,CLDC1.1,MIDP2.0,…

servers & enterprise computers

Desktop & personal computers

High-end consumer devices

Low-end devices



Java 2 Platform editions and their target markets

what is j2ee
What is J2EE ?
  • source
  • What is the Java 2 Platform, Enterprise Edition (J2EE)?
    • a platform that enables solutions for developing, deploying and managing multi-tier server-centric applications.
    • Extend J2SE to a complete, stable, secure, fast Java platform to the enterprise level.
    • A platform which significantly reduces the cost and complexity of developing multi-tier solutions, results in services that can be rapidly deployed and easily enhanced.
benefits of j2ee
Benefits of J2EE

1. Complete Web services support.

2. Faster solutions delivery time to market.

  • Enterprise infrastructure and concerns provided and solved by j2ee.
  • Developers need only focus on writing business logic .

3. Freedom of choice.

  • System assembled from standard components which can be supplied by various vendors.

4. Simplified connectivity.

  • Supply standard to connect legacy systems, enterprise information system, and bring capability to web and mobile devices.

5. Reduce TCO(total cost of ownership) and avoid single-source for software needs of enterprises.

technologies included in j2ee
Technologies included in J2EE
  • Java API for XML-Based RPC (JAX-RPC),
  • JavaServer Pages, Java Servlets,
  • Enterprise JavaBeans components,
  • J2EE Connector Architecture,
  • J2EE Management Model,
  • J2EE Deployment API,
  • Java Management Extensions (JMX),
  • J2EE Authorization Contract for Containers,
  • Java API for XML Registries (JAXR),
  • Java Message Service (JMS),
  • Java Naming and Directory Interface (JNDI),
  • Java Transaction API (JTA),
  • CORBA, and
  • JDBC data access API.
what is j2me
What is J2ME ?
  • 1.What is the Java 2 Platform, Micro Edition (J2ME)?
    • The JavaTM 2 Platform, Micro Edition is the edition of the Java 2 platform targeted at consumer electronics and embedded devices.
    • The J2ME technology consists of a virtual machine (KVM) and a set of APIs suitable for providing tailored runtime environments for consumer and embedded electronics.
  • Configurations v.s. profiles
  • Device characteristics:
    • memory size / processor
    • size and depth of display screen (UI)
    • power consumption (battery-based)
    • networking capability (limited, not TCP/IP based?)
features of the java language
Features of the java language:

Java is

  • simple
  • object-oriented
  • distributed
  • interpreted
  • robust
  • secure
  • architecture-neutral
  • portable
  • high performance
  • multithreaded
  • dynamic
java is simple
Java is Simple
  • Intentionally created to be syntactically similar to C/C++
  • Eliminates traditionally troublesome features of C/C++
    • Pointer arithmetic
    • Multiple inheritance
    • Implicit type coercions
    • Explicit memory management
    • Preprocessor
  • Eliminates features of C/C++
    • struct
    • typedef
    • union
    • enum (recovered in jdk5.0)
    • (Programmer controlled) operator overloading
  • Features included as part of base language:
    • Threads
    • Exception handling
java is object oriented
Java is Object-oriented
  • Systems are built from sets of classes
  • Classes are instantiated at runtime to give objects
  • Objects communicate via messages passing
  • Everything is part of a class
  • supported OO Concepts:
    • Data abstraction and Encapsulation
    • Inheritance
    • Polymorphism
    • Dynamic Binding
    • e.g. variable of Object type can hold everything
  • Logical cluster of classes == package
java is a distributed language
Java is a Distributed language
  • Network programming support built into JDK class library:
    • TCP sockets
    • UDP packets
    • IP addresses
    • URLs
    • RMI (Remote Method Invocation)
    • Web Service
  • Security features designed into language
  • Network programming facilities are one of the language's best features.
java is an interpreted language
Java is an Interpreted language
  • Source code is initially compiled (javac) into architecture-neutral byte-codes
  • Byte-codes are interpreted by the java virtual machine (JVM) (java or Netscape)
  • Dynamic linking/loading (at run time)
  • (Just In Time) JIT compilers lead to a large performance increase in compilation and runtime execution
java is robust
Java is Robust
  • Strongly-typed language (cf Smalltalk and VisualBasic)
  • Compile-time and runtime checking
  • No pointer arithmetic
  • Exception handling
  • Automatic memory management
java is secure
Java is secure
  • Designed with security in mind.
  • Allow users to download untrusted code over a network and run it in a secure environment in which it cannot do any harm.
  • Configurable security levels and restrictions.
  • subjected to intense scrutiny by security experts with [potentially serious ] bugs found and fixed.
    • become a big news if new bugs found!!
  • One of the best mainstream platforms with the strongest security guarantee.
java is architecture neutral
Java is Architecture-neutral
  • Byte-codes are architecture neutral
  • Performance suffers by using bytecodes
java is portable
Java is portable
  • Primitive type sizes are explicit - not architecture dependent
  • Strings and characters are (16-bit) Unicode compliant
    • easier for internationalization.
  • GUI libraries give a native graphic library-independent mechanism for creating quality graphical interfaces (sort of)
    • "They gave us a library that is good for writing programs that look equally mediocre on the different systems."(Core Java, page 9)
high performance
High performance
  • Interpreting leads to quicker development cycle
  • Depends what you compare it to
    • "Slightly faster than VB" - (Core Java, page 9)
    • JITC(Just-In-Time Compiler) help greatly in this respect
    • Sun’s Java HotSpot is Newest high performace JIT compiler.
  • Can use native code for mission-critical performance sections of code
    • JNI: Java Native Interface
    • Sacrifice portability.
  • Based on well-known 20 year old Hoare monitor synchronization
  • Thread support built into language
  • Thread synchronization primitives supplied
  • Garbage collector runs permanently as a low priority background thread
  • Class linking, layout, name resolution and object references not resolved until run-time
  • Runtime Type Information (RTTI) available
    • Can check the type of objects at run-time
    • java.reflect.* package
  • Class class for dynamic instantiation
    • Can create objects of types unkown until runtime.
    • String sexClassName = getSex();
    • Object p = Class.forName(sexClassName).instance();
    • If(p instanceof Male) {…}
    • else if (p instanceof Female) { … }
    • else {… }
an example
An Example


* The HelloJava class implements an application that

* simply displays "Hello Java!" to the standard output.


class HelloJava {

public static void main(String[] args) {

// Display "Hello Java!"

System.out.println("Hello Java!");



prehistory of java
Prehistory of Java
  • Green Project (1990)
    • Consumer device operating software
    • Requirements: small size, robust, portable, extremely reliable ,real-time performance
  • Oak
    • Originally used C++, then realized a new language was needed
    • Original requirements same as for current language
  • Java (1993)
    • Intended market never eventuated
    • WWW starting to takeoff
    • Language design "based on" many current OO languages (e.g., C++, Eiffel, Smalltalk, Cedar/Mesa, Objective C)
    • 1995/5/23 Sun launched Java
    • JDK 1.0 released early 1996/1/23 ( 211 classes / 8 pkgs)
evolution of the java language
Evolution of the Java Language

(8 packages)

(23 packages)

(59 packages)

(76 packages)


(135 packages)

(166 packages)

(202 packages)

develop your first java program and applet
Develop your first Java Program and applet

1. Required software

2. Creating Your First Application

a. Create a Java Source File

b. Compile the Source File

c. Run the Program

d. invoke the program remotely via Java Web Start.

3. Creating Your First Applet

a. Create a Java Source File

b. Create related HTML files

c. Compile and run the Source File

required softwares
Required Softwares

To write your first program, you will need:

1. The JavaTM 2 Platform, Standard Edition.

2. A text editor. Ex:

  • NotePad,
  • Ultraedit,
  • EditPlus2
2 creating your first application
2. Creating Your First Application
  • The first program, HelloWorldApp, will simply display : “Hello World!".
  • Steps:
    • a. Create a Java source file.
    • > Notepad
    • b. Compile the source file into a bytecode file.
    • > javac
    • c. Run the program contained in the bytecode file.
    • >java HelloWorldApp
    • d. invoke the program remotely via JavaWeb Start.
    • d.1 :> jar cf HelloJWS.jar HelloWorlApp.class
    • d.2 : prepare HelloJWS.jnlp
    • d.3 : prepare web page to hyperlink
    • HelloJWS.jnlp
hellojava java


* The HelloWorldApp class implements an application that

* simply displays "Hello World!" to the standard output.


class HelloWorldApp {

public static void main(String[] args) {

// Display "Hello World!"

System.out.println("Hello World!");



d invoke java application remotely via jws
d. Invoke Java application remotely via JWS

<?xml version="1.0" encoding="utf-8"?>

<jnlp spec="1.0" codebase=""



<title>Hello Java Web Start</title>

<vendor>Cheng-Chia Chen</vendor>

<homepage href="index.html"/>

<description>A simpe Demo of Java Web Start.</description>




<j2se version="1.4+"/>

<jar href="helloJWS.jar"/>


<application-desc main-class="HelloJWS"/>


(web page)

<A href=“helloJWS.jnlp”>

Start HelloJWS




java 2 sdk installation instructions for win32
Java 2 SDK Installation Instructions (for WIN32)

1. Download java SDK standard edition

2. Run the Java SDK executable (*.exe).

  • determine where to install java se. (ex: c:\java\jdk6)
  • > set JAVA_HOME= c:\java\jdk6

3. Update the PATH variable

  • so that you can type ‘java’ instead of ‘c:\java\jdk6\bin\java’ to invoke java tools.
  • > path=%JAVA_HOME%\bin;%PATH%

4. Check the CLASSPATH variable

  • Used by java tools to determine where to find your personal (nonsystem) java class files
  • Types of java byte codes (class files):
    • System : java tools know where to find them.
    • Extensions: put in %JAVA_HOME%\jre\lib\ext
    • Personal: via CLASSPATH or –cp/–classpath options

5. Start using the Java 2 SDK tools!

  • java, javac, javadoc, jdb, javap,…
3 creating your first applet
3. Creating Your First Applet

a. Create a Java Source File:

import java.applet.*;

import java.awt.*;


* The HelloJavaApplet class implements an applet that

* simply displays "Hello World!".


public class HelloJavaApplet extends Applet {

public void paint(Graphics g) {

// Display "Hello Java Applet!"

g.drawString("Hello world!", 50, 25);



b create an html file to contain the applet
b. Create an HTML file to contain the applet.



<TITLE>A Simple Program</TITLE>



Here is the output of my program:

<APPLET CODE="HelloJavaApplet.class"



The applet does not work!</APPLET>



  • Save this code to a file called HelloJavaApplet.html.
c compile and run the program
c. Compile and run the program
  • Compile the Source File.
    • Javac
  • Run the program:
    • With Appletviewer:
    • appleviewer HelloWorld
    • With IE explorer, Netscape:
    • double click HelloJavaApplet.html
  • demo
how java code are structured
How java code are structured ?
  • A java application consists of
    • = many packages [from JRE + from 3rd party + your own ]
  • A package consists of
    • many classes
    • many subpackages
  • Note: importing a package does not mean importing its subpackages.
  • A java source file is called a compilation unit, which may
    • contain multiple java class definitions and
    • may be compiled into multiple java byte code (***.class ).
A class has two names:
    • simple name
    • fully qualified name = package name. SimpleName
  • Ex:
    • java.lang.String
    • javax.swing.JButton
  • The package/subpackage/class structure is not only logically analogous to directory/subdirectory/file in OS file system but in fact they are stored physically in file system in this way.
    • Namely, if package p corresponds to a directory d then subpackage p.q of p would be stored in subdirecty q of d, and class p.A of p would be stored in file named A.class or
  • How does java machine find a class or src x.y.z.A in the package x.y.z ?
  • Notes:
    • package x.y.z is a subpackage of x.y, which is a subpackage of x.
    • we called package x, java, javax etc, top-level packages.
    • java find the location of top-level packages from a list of directory given by a system variable called CLASSPATH.
  • Ex: If CLASSPATH = .;d:\my\root Then
  • package x is the dir d:\my\root\x or ./x
  • package x.y is the dir d:\my\root\x\y or ./x/y
  • package x.y.z is the dir d:\my\root\x\y\z or ./x/y/z
  • class or src .y.z.A is the file d:\my\root\x\y\z\A.class or d:\my\root\x\y\z\ or …