Transcript Java Tools
The Java Programming Environment:
compiling to bytecode
Classe1.java
The programmer
write source code
with a text editor.
Classe2.java
One source file for
each public class
The source code
is submitted to a
compiler.
The compiler
translates the source
code into Java
bytecode.
Classe1.class
Classe2.class
One class file for
each class
Bytecode is a low level language similar to machine language.
JDK, Jan Pettersen Nytun - HiA 1
The Java Programming Environment:
executing the code
Classe1.class
Classe2.class
A Java Virtual
Machine (JVM)
interprets (executes)
the bytecode.
A JVM is a program
which simulates a machine
A Java enabled browser contains
a JVM.
A Java “program” that can run
inside a browser is called an applet.
It is also possible to make stand-alone
applications.
The class loader, which is part of the JVM, will load classes as they are needed.
Before the bytecode is interpreted it will be inspected by a bytecode verifier.
The bytecode verifier will make sure that the bytecode is legal and that it don’t
break Java’s security restrictions.
JDK, Jan Pettersen Nytun - HiA 2
The Java Programming Environment:
compiling to native code
There are some native code compilers (compilers that
generates code for a particular machine platform) available for Java,
but just-in-time (JIT) compilers are more common.
A just-in-time (JIT) compiler will generate native
code the first time a class is used, the code is cached
for later use.
Some hardware support for bytecode is also
available.
JDK, Jan Pettersen Nytun - HiA 3
JDK - Java Development Kit
• The Java Development Kit contains the
software and tools that you need to compile,
debug, and run applets and applications that
you've written using the Java programming
language.
• JDK is available free from SUN
Microsystems, the creators of the Java
programming language (http://java.sun.com/products/jdk/) .
JDK, Jan Pettersen Nytun - HiA 4
Some of the basic command-line tools
in the Java Development Kit (JDK)
• javac -Is the Java compiler. Java source code (file with a .java extension)
is compiled into Java bytecodes (class file, extension .class) .
• java - Is the Java Interpreter, it executes Java class files.
• jdb - Is a command-line debugger for Java classes.
• appletviewer - Is the Java applet viewer, it allows you to run applets
without a web browser.
• javah - Is used to integrate C and Java.
• javap - Disassembles class files.
• javadoc - Generates documentation from a Java source file.
JDK, Jan Pettersen Nytun - HiA 5
javap the Java Class Disassembler
• It is possible to do some reverse engineering from Java bytecode classes.
• With javap you can get a human-readable version of the specified Java
bytecode classes.
Usage: javap <options> <classes>
where options include:
-c
Print bytecode for each method
(disassemble the code).
-private Shows all classes, variables, and methods.
JDK, Jan Pettersen Nytun - HiA 6
javap In the given example the file MenuApplet.class is
disassembled
C:\Java\myclasses>javap -private MenuApplet
Compiled from MenuApplet.java
public synchronized class MenuApplet extends java.applet.Applet
implements java.awt.event.ActionListener
/* ACC_SUPER bit set */
{
public MenuApplet();
public void init();
public void actionPerformed(java.awt.event.ActionEvent);
private void showPage(java.lang.String);
}
JDK, Jan Pettersen Nytun - HiA 7
javadoc -
Generates API documentation
in HTML format from Java source code.
• The documentation describes the class, its inheritance
hierarchy, and each nonprivate variable and method in the
class.
• Comments in the source code that begin with /** and end with
*/ is also included. Each separate line of the comment must
start with an *.
• Special tags placed in the source code are recognized. These
doc tags enable you to autogenerate a complete, wellformatted API from your source code. The tags start with an
"at" sign (@).
JDK, Jan Pettersen Nytun - HiA 8
javadoc - Example from a
source file
/*
* MenuApplet.java
* Copyright (c) 1998 HiA, All Rights Reserved.
*/
import java.applet.*;
/**
* This applet will display two buttons, each leading to a given URL.
* @author Jan Pettersen Nytun
* @version 1.1, 98/08/13
*/
public class MenuApplet extends Applet implements ActionListener {
/**
* Initialize the applet.
* @return <code>void</code>
*/
public void init() {
...............
JDK, Jan Pettersen Nytun - HiA
9