Java Overview Olivier de Pertat. Teacher Olivier de Pertat [email protected] Vision IT...

29
IT G ROUP Java Overview Olivier de Pertat
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    213
  • download

    0

Transcript of Java Overview Olivier de Pertat. Teacher Olivier de Pertat [email protected] Vision IT...

IT GROUP

Java Overview

Olivier de Pertat

Teacher

Olivier de [email protected]

Vision IT GroupAddress: 83, rue du Château

92100 BOULOGNEPhone: 01 41 09 77 00Fax: 01 41 09 77 19Mobile: 06 73 36 74 58

Java

JSE: Java Standard Edition Java Runtime Environment (JRE):

JVM: is responsible for the hardware- and operating system-independence of the Java SE platform, the small size of compiled code (bytecodes), and platform security. Java SE API: (Libraries):

Core Technologies, Desktop (or Rich Client) technologies,Support for OOP (java.lang), Collections, I/O, Network…

Core components provide essential functionality for writing powerful enterprise-worthy programs in key areas such as database access (JDBC), security, remote method invocation (RMI), and communications.

Java Plug-In: enables applets to run in popular browsersJava Web Start: deploys standalone applications over a network.

Java Development Kit (JDK): Superset of the JRE adding tools like compilers, debuggers and other tools.

JEE : Java Platform Enterprise EditionStandard for developing portable, robust, scalable and secure server-side Java applications.JEE = J2SE + Server side developmentWeb services, component model, management, and communications APIs SOA (Service Oriented Architecture) / Web 2.0

J2ME : CDC : JVM (Profiling…)CLDC : KVM

Java SE

What is Java?

Object Oriented Programming Language

Virtual Machine Based

A large set of APIs : Java SE APIs

A set of tools:le Java Runtime Enviromnent

le Java SDK Standard Edition

le Java SDK Entreprise Edition

Application and/orJava Program

Java Virtual Machine

Operating System

History

1991-92: Green Project formed at Sun Microsystems as “Consumer Play”

“Oak” environment defined and developed.

“*7” wireless PDA built and demoed on 1992 September 3.

1993-94: “Set-Top Box Play”

1994: “Internet Play”Oak becomes Java.

Java Virtual Machine rewritten in ANSI C.

Java compiler rewritten in Java.

1995 : Mai 95 : Java (23 may). WebRunner becomes HotJava

Mai 95 : Netscape buys a license

Sept. 95 : JDK 1.0 b1 (200 Classes)

Dec. 95 : Microsoft is buying a license

History (cont.)

1996 : Java 1.0 - 200 Classes1996 January: JDK 1.0.1

Summer 96: Java Study Group ISO/IEC JTC 1/SC22

1996 Q4: RMI, JDBC, JavaBeans, ...

1997: JDK 1.1 – new services

1998 : Platform Java 2 - JDK 1.2 - 1250 classes – consolidation Maturity

2000 : Platform Java 2 – version 1.3 : performances improvements, kernel modifications to accept low level extensions

2002 : Platform Java 2 – version 1.4.1

2005 : Java 1.5 : Generics, Annotations…. A new Platform

2006 : Java 1.6

History (Cont.)

C Compilation

PC running Linux

PC running Windows

SPARC running Solaris

PowerPC running AIX

Linux x86Compiler

Binary File

Binary File

Binary File

Binary File

C Source File

Ms WindowsCompiler

Sun SPARCCompiler

IBM – AIXCompiler

Java Compilation

Java SourceFile

Class File

PC running Linux

PC running Windows

SPARC running Solaris

PowerPC running AIX

Compilation

Source Code

$ cat Hello.java

public class Hello

{

public static void main(String [] args)

{

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

}

}

Byte Code

$ od -x Hello.class

0000000 feca beba 0000 2e00 1d00 000a 0006 090f

0000020 1000 1100 0008 0a12 1300 1400 0007 0715

0000040 1600 0001 3c06 6e69 7469 013e 0300 2928

0000060 0156 0400 6f43 6564 0001 4c0f 6e69 4e65

0000100 6d75 6562 5472 6261 656c 0001 6d04 6961

0000120 016e 1600 5b28 6a4c 7661 2f61 616c 676e

0000140 532f 7274 6e69 3b67 5629 0001 530a 756f

0000160 6372 4665 6c69 0165 0a00 6548 6c6c 2e6f

0000200 616a 6176 000c 0007 0708 1700 000c 0018

0000220 0119 0c00 6548 6c6c 5720 726f 646c 2120

0000240 0007 0c1a 1b00 1c00 0001 4805 [………EOF…]

Java Weakness

JVM are slower than native core

Java Uses loads of Memory

Some construction lacks (Switch on Integers, No Operator overloading…)

Some API

There are so many APIs

Significant modification with 1.5

Java Characteristics

OOP

Interpreted

Portable

Simple

Robust

Secure

Multi-threads

Distributed

Object Oriented Programming

Everything is class (there are no functions)

All class extends java.lang.Object (inheritance)

Encapsulation, message communication, polymorphism, inheritance

Object are handled through references

An Object API is provided

Syntax is closed to C language

Java is portable

The compiler generates byte code

JVM exists over Unix, Win32, Mac, OS/2, FireFox, IE, ...

Semantic is precise, strong type enforcement

Primitive data type size is platform independent

Source cam be written in UNICODE

The Java SE API is standard

Java is robust

Language conceived for embedded systems

Memory is managed by a garbage collector.

No direct access to memory (References no pointers)

Exception Mechanism

Accessing to a Null Reference generates an Exception

Arrays are Objects

No mystery with type conversions

Casts are controlled at run time

Java is secured

Mandatory with mobile code

JVM is responsible for Security

3 main layers:Verifier: checks the byte code.

Class Loader: responsible for class loading.

Security Manager : resource access management.

Code can be signed by an encryption key.

Java is multi-threaded

Multi-thread is built-In and integrated to the APIs:synchronized

garbage collector is a low priority thread

java.lang.Thread, java.lang.Runnable

Concurrency is handled by a monitor

Depends on the implementation of the JVM

Java is distributed

Network API (java.net.Socket, java.net.URL, ...).

Dynamic Code Loading/Generation

Applet.

Servlet.

Protocol / Content handler.

Remote Method Invocation.

JavaIDL (CORBA).

Tools

Development Environments:Java 2 standard edition SDK 1.6.xText Editors: VIM, java-mode emacs, Ultra Edit, JEditCompilation environments: ANT, makeTests tools: JUnitIDE : Forte, JBuilder, Visual Age, WebGain, CodeWarriorAtelier UML: Together, Rational Rose Byte-code decompiler: jad

Browsers:Sun HotJavaNetscape Navigator 4 et 6Internet Explorer 4 et 5 (plus pour la prochaine version)Java-Plug-in (tous les browsers)

Java Standard Edition SDK 1.6

javac: java compilerjava: byte code interpreter (JVM)appletviewer: Applet interpreter jar: packaging tools for distribution (bin & lib)jarsigner: archive signer JARjavadoc: documentation generator (HTML, MIF)javah: header generator for native code callsjavap: byte code decompilerjdb: debuggerkeytool: keys and certificate managementorbd: Corba ORBrmic: RMI stub compilerrmiregistry: "Object Request Broker" RMIservertool: CORBA administration tool

JVM OptionsC:\>javaUsage: java [-options] class [args...] (to execute a class) or java -jar [-options] jarfile [args...] (to execute a jar file)

where options include: -client to select the "client" VM -server to select the "server" VM -hotspot is a synonym for the "client" VM [deprecated] The default VM is client.

-cp -classpath <directories and zip/jar files separated by ;> set search path for application classes and resources -D<name>=<value> set a system property -verbose[:class|gc|jni] enable verbose output -version print product version and exit -showversion print product version and continue -? -help print this help message -X print help on non-standard options -ea[:<packagename>...|:<classname>] -enableassertions[:<packagename>...|:<classname>] enable assertions -da[:<packagename>...|:<classname>] -disableassertions[:<packagename>...|:<classname>] disable assertions -esa | -enablesystemassertions enable system assertions -dsa | -disablesystemassertions disable system assertions

C:\>java -X

-Xmixed mixed mode execution (default)

-Xint interpreted mode execution only

-Xbootclasspath:<directories and zip/jar files separated by ;>

set search path for bootstrap classes and resources

-Xbootclasspath/a:<directories and zip/jar files separated by ;>

append to end of bootstrap class path

-Xbootclasspath/p:<directories and zip/jar files separated by ;>

prepend in front of bootstrap class path

-Xnoclassgc disable class garbage collection

-Xincgc enable incremental garbage collection

-Xloggc:<file> log GC status to a file with time stamps

-Xbatch disable background compilation

-Xms<size> set initial Java heap size

-Xmx<size> set maximum Java heap size

-Xss<size> set java thread stack size

-Xprof output cpu profiling data

-Xrunhprof[:help]|[:<option>=<value>, ...]

perform JVMPI heap, cpu, or monitor profiling

-Xdebug enable remote debugging

-Xfuture enable strictest checks, anticipating future default

-Xrs reduce use of OS signals by Java/VM (see documentation)

-Xcheck:jni perform additional checks for JNI functions

Windows Integration

Internet Explorer Integration

Java Running Entities

Standalone Applications Applications are run on the final hostEach application of that kind has a main method: Signature: public static void main(String [] args)

Components: Program hosted in an other application.Complies to a specific known protocol (Interfaces).Applets: Java application running within a Web PageServlets:

Java Application that handles Server requests (Generic Servlet)Usually it handles HTTP requests

EJB (Enterprise Java Bean) :Java Distributed Application handling user session (Session Bean), persistent data (Entity Bean) or a message (Message Driven Bean).Component managed by an application serverMight be transactional

Java Running Entities (Cont.)

Standalone Java Program: Example :

class HelloWorld {

public static void main(String args) { System.out.println("Hello World !"); }}

Classical Invocation:$ java -classpath . HelloWorld

Hello World !

Java Running Entities (Cont.)

Applet: runs within a Web Browser

public class HelloWorldApplet extends Applet {

public void paint(Graphics g) {

g.drawString("Hello World !", 50, 20);

}

}

Servlet: runs within an Application Server (Web Container)

public class HelloWorldExample extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException {

out.println("<html>Hello world !</html>");

}

}

JAR

JAR invocation:$ cat MANIFEST.MF

Manifest-Version: 1.0

Main-Class: HelloWorld

$ jar cfm MyHelloPack.jar MANIFEST.MF HelloWorld.class

$ jar –i MyHelloPack.jar

$ java -jar MyHelloPack.jar

Hello World !