Application Architecture Using Java

aniseedsplashSoftware and s/w Development

Aug 15, 2012 (4 years and 10 months ago)

289 views

Application Architecture Using
Java

Hong Li

Introduction


Developed by a team led by James Gosling at Sun
Microsystem.


Originally called Oak, designed in 1991


Renamed Java in 1995, redesigned for developing
Internet Application


Full
-
featured, general
-
purpose programming
language


Java initially became attractive because Java
program can be run from a web browser. It is called
applet


Java can also be used to develop application on the
server side. Called Java servlets or JavaServer
Page

Characteristics of Java


Java is simple


Java is Object
-
Oriented


Java is distributed. Distributed computing
involves several computers working
together on a network.


Java is Interpreted. Programs are compiled
into the Java Virtual Machine code called
bytecode. The bytecode is machine
-
independent and can run on any machine
that has a Java interpreter, which is part of
the Java Virtual Machine (JVM)

Specification, API, JDK and
IDE


The Java language specification is a
technical definition of the language that
includes syntax and semantics


API contains predefined classes and
interfaces


J2SE
-
Java 2 standard edition


J2EE
-
Java 2 Enterprise Edition (server side
application)


J2ME
-
Java 2 Micro edition (mobile devices)

Java Development Toolkit
(JDK)


Sun releases each versions of J2SE with a Java
Development Toolkit (JDK)


JDK consists of a set of separate programs for
developing and testing Java program


Jbuilder by Borland (www.borland.com)


NetBean open source by Sun(
www.netbeans.org
)


Sun One, a comercial vrsion of NetBeans by Sun


Eclipse open source by IBM (
www.eclipse.org
)


These tools provide an integrated development
environment (IDE) for rapidly developing Java
programs.


Application and Applet


A Java program can be written in
many ways.


Applications are standalone programs.
It can be executed from any computer
with a Java interpreter


Applets are special kind of Java
programs that can run directly from a
Java
-
compatible Web Browser

A simple Java Program


Display message “Welcome to Java!”

// this application program prints Welcome to
Java!

// file name: Welcome.java


public class Welcome

{


public static void main(String [] args)


{


System.out.println(“Welcome to Java!”);


}

}

Class and methods


The class is essential Java construct. To program in
Java, you must understand classes and be able to
write and use them. A program is defined by using
one or more classes.


System.out is known as the standard output object.
println is a method in the object


Every Java application must have a user
-
declared
main method that defines where the program
begins. The Java interpreter executes the
application by invoking the main method


Displaying text in a message
dialog box


// file name: WelcomeDialog.java


import javax.swing.JoptionPane;


public class WelcomeDialog


{


public static void main(String[] args)



{



JOptionPane.showMessageDialog(null,
“Welcome to Java!”,”Example
2”,JOptionPane.INFORMATION_MESSAGE);


}


}

Jbuilder


Start
-
>program
-
>Jbuilder
-
>Jbuilder


Creating project


File
-
>new Project


Give a name and select directory, then click next


Keep all setting for path, then click next


For simplicity, uncheck Enable source package
discovery and compilation


Click finish

Jbuilder continued


Create a Java program File
-
>new class


Give file name, check only public and generate
main method, uncheck others


Click OK


Compile a Java program


Project
-
>make xxx.java


Execute a Java program


Run
-
> xxx.java using default