Προηγούμενο Περιεχόμενα
Το Java Virtual Machine εκτελεί
byte-code instructions. Για να δούμε πώς περίπου μοιάζουν
αυτές ορίστε ένα παράδειγμα.
package koko;
class javap_example {
public static void main(String argv[]){
int x=1;
x = 4 + magiko(x);
System.out.println(x);
};
public static int magiko(int n){
return n+1;
};
}
Περνώντας το παραπάνω πρόγραμμα απο τον Java disassembler
(javap -c) παιρνουμε τα παρακατω:
Compiled from 1.java
synchronized class koko.javap_example extends java.lang.Object
/* ACC_SUPER bit set */
{
public static void main(java.lang.String[]);
public static int magiko(int);
koko.javap_example();
}
Method void main(java.lang.String[])
0 iconst_1 # Κάθε γραμμή περιλαμβάνει και απο μια instruction
1 istore_1
2 iconst_4
3 iload_1
4 invokestatic #6 <Method int magiko(int)>
7 iadd
8 istore_1
9 getstatic #7 <Field java.io.PrintStream out>
12 iload_1
13 invokevirtual #8 <Method void println(int)>
16 return
Method int magiko(int)
0 iload_0
1 iconst_1
2 iadd
3 ireturn
Method koko.javap_example()
0 aload_0
1 invokespecial #5 <Method java.lang.Object()>
4 return
Για περισσότερες πληροφορίες για την αρχιτεκτονική των
Virtual Machines και τον ρόλο κάθε μιας απο τις
instructions κοιτάξτε το Java Virtual Machine (των Meyer
& Downing).
Προσέξτε πώς η class MyFrame κάνει
implement τα interfaces ActionListener kai
WindowListener. Σε όσες functions των interfaces δεν
θέλouμε να γράψουμε κώδικα (π.χ. windowClosed) τις
αφήνουμε κενές.
import java.awt.*;
import java.awt.event.*;
class MyFrame extends Frame implements ActionListener,WindowListener
{
Button bOK,bCan;
public MyFrame(){super("MyFrame"); setup(); setVisible(true);}
public void setup()
{
add(bOK=new Button("OK"),"West");
add(bCan=new Button("Cancel"),"East");
bOK.addActionListener(this);
bCan.addActionListener(this);
addWindowListener(this);
pack();
}
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if (o==bOK) System.out.println("OK");
else if (o==bCan) System.out.println("Cancel");
}
public void windowOpened(WindowEvent e){}
public void windowClosing(WindowEvent e){System.exit(0);}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
}
Ένας απλός echoserver με threads σε
java.
Δημιουργήστε ένα directory "echo" κάτω από το $CLASSPATH
και δώστε
javac echoserver.java
java echo.EchoServer &
java echo.Client
package echo;
import java.util.*;
import java.net.*;
import java.io.*;
class EchoServer
{
ServerSocket serverSocket=null;
public EchoServer()
{
try {serverSocket = new ServerSocket(5555);}
catch (IOException ex) {System.err.println(ex); System.exit(1);}
}
public void run()
{
boolean listening = true;
while (listening)
{
Socket clientSocket = null;
try
{
clientSocket = serverSocket.accept();
new ServerThread(clientSocket).start();
}
catch (IOException ex){System.err.println(ex);}
}
try {serverSocket.close();}
catch (IOException ex) {System.err.println(ex);}
}
public static void main(String[] args) {new EchoServer().run();}
}
class ServerThread extends Thread
{
Socket socket;
BufferedReader br;
PrintWriter pw;
ServerThread(Socket soc)
{
super("ServerThread");
try
{
socket = soc;
br = new BufferedReader(new InputStreamReader(soc.getInputStream()));
pw = new PrintWriter(soc.getOutputStream());
}
catch(Exception ex){System.err.println(ex);}
}
public void run()
{
try
{
boolean listening = true;
while (listening)
{
String inputLine = br.readLine();
pw.println("echo: "+inputLine);
pw.flush();
}
pw.close();
br.close();
socket.close();
}
catch (IOException e) {e.printStackTrace();}
}
}
class Client extends Thread
{
PrintWriter os;
BufferedReader is,stdin;
Client(Socket soc) throws IOException
{
os = new PrintWriter(soc.getOutputStream());
is = new BufferedReader(new InputStreamReader(soc.getInputStream()));
stdin = new BufferedReader(new InputStreamReader(System.in));
}
public void run()
{
boolean talking = true;
while (talking)
{
try
{
String s = stdin.readLine();
os.println(s);
os.flush();
String s1 = is.readLine();
System.out.println(s1);
}
catch(Exception ex){System.err.println(ex);}
}
}
public static void main(String[] argv)
{
try
{
Socket soc = new Socket("localhost",5555);
new Client(soc).start();
}
catch(Exception ex){System.err.println(ex); System.exit(1);}
}
}
Προσέξτε πως παρακάμπτουμε το print method της Χ στην Α
class X
{
public int x;
public X(int x1){x=x1;}
public void print(){System.out.println(""+x);}
}
class A
{
X myXInstance = new X(4){public void print(){System.out.println("x="+x);}}
...
}
Αν σας ενδιαφέρει ένα μικρό
παράδειγμα του τί μπορεί να καταφέρει το RMI, στείλτε μου
ένα mail στην διεύθυνση: dglynos@freemail.gr για
να σας στείλω ενα παιχνιδάκι :) γραμμένο σε Java.
Java Tools for Linux
[extracted from www.blackdown.org]
Java 1.1 compatible Web Browsers
* Netscape Communicator v4.06 and 4.5Beta
These versions of the netscape communicator support the JDK 1.1,
including Swing. Both are available at Netscape JDK1.1 Update
Support.
* HotJava(tm) 1.1.4
HotJava web browser is written entirely in Java. You can get more
information about it at HotJava(tm) Browser Page.
IDE's
* NetBeans Developer (commercial)
NetBeans Developer cross-platform, full-featured IDE that combines
support for all stages of application development including visual
GUI design, editing, compilation, and debugging - an industrial
strength yet intuitive development tool for development tool for
developers at all levels. A version for Java 2 is now available
for use so you can start using Java 2 on Linux as soon as the port
is available. In addition, NetBeans features:
+ Sophisticated support for Swing and layout managers, allowing
quick and flexible design of highly functional GUIs.
+ JavaBeans based architecture, making it highly extensible and
customizable, down to every item on the menus and toolbars.
+ A consistent approach to all object types (configuration
objects, various data types, classes and their
fields/methods, beans, etc.), simplifying the learning curve
for NetBeans.
+ Integrated, visual multi-threaded debugger with support for
breakpoints, watches, locales, and threads
+ Source Editor with syntax coloring and advanced features like
dynamic word completion
A non-commercial version is available for free from NetBeans.
* Simplicity for Java (commercial / free trial version)
Simplicity for Java is the most powerful RAD tool available on the
Linux platform for creating Java applications and applets. By
using the Simplicity for Java IDE, developers build Java software
interactively through a visual model which is instantaneously
updated to reflect any changes made to the program's source code
without compiling. Its features include:
+ Execution of Java source code on-the-fly
+ Full support of all AWT and Swing Components and Layout
Managers
+ Code Sourcerer writes Java statements for you
+ Full JavaBeans support
+ Powerful Programmer's Editor features:
+ Method lookup and autocompletion via introspection
+ Search and replace using Perl5 regular expressions
+ Color syntax highlighting
+ Printing in full color
+ Unlimited undo/redo
* Cross-platform development and file formats
* All generated code is pure Java (no proprietary libraries).
* Uses any Java classes on your classpath including jar and zip
files
* Use JDK 1.1 or 1.2 (Java 2)
* View signature, methods, and fields of any class
* Double click compiler error messages to jump directly to code
* Year 2000 Compliant
A free trial of the new version 1.1 is available from Data
Representations, Inc.
CodeGuide (commercial / free non-commercial edition)
CodeGuide is the first IDE which really understands Java. It offers a
vast assortment of powerful programming aids:
* COMPLETE and INSTANTANEOUS error detection to show you errors as
you type.
* Prefix completion of field accesses and method invocations which
works just like the file-completion in the UNIX bash.
* Display of valid methods and fields in the code.
* Display of expected method parameters.
* Source browsing to navigate quickly within your code.
CodeGuide also features other advanced IDE functionality:
* External compiler integration.
* Connection to external VMs.
* Syntax highlighting.
* JDK switching.
* Full Java 2 support.
A non-commercial edition is available for free from Omnicore Software.
StructureBuilder (commercial)
Tendril Software's StructureBuilder products are innovative UML
model-based Java component and application development tools. They are
the only visualization tools to be tightly integrated into an IDE.
StructureBuilder can currently be integrated with NetBeans Developer
and VisualCafe 3.
* StructureBuilder has synchronized source code and Class Diagram.
It supports Sequence Diagrams and Use Case Diagrams.
* StructureBuilder is the only tool that will allow a developer to
generate code from interaction diagrams.
* StructureBuilder is the only tool in its class that can recognize
1:Many relationships when reverse engineering.
* You can generate Javadoc tags automatically and create HTML
documentation of your object model with diagram imagemaps.
* StructureBuilder allows you to visually define, verify and
generate supporting code for JavaBeans and Enterprise JavaBeans as
well as parse, identify and extend existing components.
* The product contains a comprehensive and easy to use Open API.
* StructureBuilder is certified 100% Pure Java and is supported on
the Linux platform, as well as Windows and SPARC.
Download an evaluation version at Tendril's website.
AnyJ (freeware with professional commercial version)
AnyJ is a cross-platform, full-featured IDE that supports all kinds of
of java applications: Servlets, Applets, Applications. Includes a Java
Beans conform Visual GUI-Builder (Swing), Debugger, integrated Version
Control and a very powerful and fast Editor.
* GUI Builder: Full support of AWT and Swing Components, JavaBeans
support, Unlimited undo/redo
* Source Code Engineering: True Intelli*ense-like parser backed code
completion, class browsers & source analysis tools, "Goto
definition" for quick navigation.
* Editor: Autocompletion (uses source parsing or .jar/.class file
scaning), auto import, Unlimited undo/redo,
Syntax Coloring of Java, Html, XML, etc.. Jump to source from
compiler error messages or Stack traces
* integrated graphical debugger (multithreaded, remote debugging,
breakpoints in inner & anonymous classes)
* integrated GUI-based Version Control & Diff-viewer,
* Servlet support (Simply Compile & Run),
* Customizable Shortcuts, Menu's, Plugin Architecture to extend AnyJ
in Java, Dependency Checker to support deployment, Commandline
interface to integrate external tools and scripts.
* Supports JDK 1.1 or 1.2 (Java 2) (WinNT: + MS-SDK)
The Linux release is freeware. Unrestricted non-commercial versions
for Solaris and WinNT are available for free from NetComputing.
BlueJ (free)
BlueJ is an integrated Java environment specifically designed for
introductory teaching. It was developed at Monash University for the
purpose of teaching in a first-year course and is suitable for
teachers and individuals who want to learn or use Java. Some features:
* fully integrated environment
* graphical class structure display
* graphical and textual editing
* built-in editor, compiler, virtual machine, debugger, class
browser, etc.
* easy-to-use interface, ideal for beginners
* interactive object creation
* interactive object calls and testing
* incremental application development
Class and dependancy visualisation helps to understand object-oriented
structures and interaction facilities support very flexible
experimentation and immediate feedback.
JDesignerPro from BulletProof (commercial / free 90 day trial
version)
JDesignerPro is a complete solution for building and deploying your
intranet/internet/extranet applications that require database
connectivity. The visual wizards make development and deployment easy
even for those who have never programmed before. Some of the features
include:
* True WYSIWYG development - build and deploy client-side
applications
* Enterprise Server - build and deploy server-side applications
* Database connection pooling
* Completely Object Oriented Structure - Import any JavaBean or
other component
* Solid User Access Control system to allow deployment to just the
right endusers
* Instant deployment to remote servers
* SQL Wizard for adhoc querying
* Wizards for Forms, Grids, Reports, Charts, Email, Paging and more
* Clients run on Netscape 3.0 or IE 3.0 or later on any platform
* Integrated HelpDesk system for your endusers
* Build over the web - Application Builder can be run over the web
to allow remote development
* Manage server side processes over the web and monitor active
endusers
BulletProof also offers free email support and paid phone support.
Download a free trial from the BulletProof website.
Elixir IDE (commercial/free Lite version)
Elixir IDE is a slick, lightweight programmer's editor for
professional Java developers. It was developed on Linux in 100% Java
sporting the Swing interface. Its features include:
* Pluggable architecture supporting multiple compilers (JDK 1.1,
1.2, Jikes), scripting engine (Scheme), and version control system
(RCS);
* Powerful editor with syntax colouring for Java, HTML, Scheme,
unlimited undo-redo and collapsible code blocks;
* Powerful editor with syntax colouring for Java, HTML, Scheme,
unlimited undo-redo and collapsible code blocks;
* File and source code browser and management environment scalable
for large team development;
* Integrated HTML browser for viewing help files such as Java APIs;
and
* Runs on all JDK 1.1 and 1.2 platforms including Linux, with Swing
user interface.
A free Lite version with 10 Java file limit is available.
LOREx2 for Java (commercial)
LOREx2 for Java is a Java-centric, UML-based CASE tool designed for
Java developers. Developed in 100% Java, LOREx2 runs on all JDK 1.1
platforms including Linux. Its features include:
* Support for UML diagrams with intuitive diagramming features like
an intelligent connector that auto-detects valid connection types
between 2 objects;
* Support for Java keywords like synchronized and @deprecated;
* Java code generation;
* Reverse engineers Java applications to UML diagrams:
+ view class interaction and object structure;
+ perform impact analysis for system maintenance; and
+ no source code needed.
* Support for Java plug-ins to allow tool extension and
customization by Java developers (the Java code generator is
itself one such plug-in); and
* A design repository browser with an object database underneath to
ensure full design and view integrity.
Super Mojo (commercial)
Penumbra's page describes Super Mojo as a "visual Java development
environment, Super Mojo offers three primary advantages to the
developer: Rapid Application Development through ease of use and a
fresh approach to the user interface. Total Application Control
through complete access to all underlying code. Maximum Code Reuse by
pushing the limits of object oriented programming ideals."
WipeOut (freeware with professional commercial version)
softwarebuero is developing Java IDE, WipeOut, for Linux. It's not
just a frontend for the JDK, it also fronts for CVS, make, C++
compiler and GDB. It's features include: general support of C++ and
Java, revision management / team work support, fast, incremental
source code parser, central text editor with syntax highlighting, all
components are fully integrated, nice, productive GUI (no Motif
required!) and automatic generation of makefiles. It includes a
Project/Revision Browser, a Class Browser, a Debugger Front End, and a
Text Editor. For more information Visit the WipeOut Page or download
it here.
JForge (Commercial)
JForge is a Java Beans GUI builder, certified 100% Pure Java by Sun
Microsystems. It provides a WYSIWYG style interface for creating AWT
and JFC based Java Beans or GUI forms, saving and loading of Beans as
Java code or serialized objects, full support for the standard Layout
Managers, a Menu Builder, pluggable user menus and customizable
interface, and a feature-rich API allowing even further customization
or integration with third-party tools. JForge is sold by Tek Tools,
makers of the popular Kawa Java IDE, and is available for a free 30
day evaluation period for either JDK 1.1.x or JDK 1.2 development
environments on all Java-enabled platforms.
Source Navigator (free "lite" version)
SN v4 is a complete ide for Java, c/c++, Tcl, Assembly, Fortran, and
COBOL. It has a Symbol Browser, Class Browsers, Class Hierarchy
Browser, Include Browser, Cross Referencer, GUI Editor, Diff Tool,
Debugger Interface, SDK with APIs. Get your lite version while you buy
a copy for me at the Cygnus Source Navigator site.
JACOB - The Java Commando Base for Emacs (free)
Jacob is a Java class browser and project manager for Emacs and
includes a powerful class wizard. Unlike traditional browsers the
windows are vertically aligned and the full vertical screen size is
still reserved for editing. Height of browser lists (packages,
classes, methods) can be dynamically changed. Now you can spend all
the screen real estate for your methods or classes, just as you like
it. Additionally Jacob generates a makefile to compile, run, and/or
archive (with zip and rcs) your application. JACOB can be found at
http://home.pages.de/~kclee/clemens/jacob/.
Emacs JDE (free)
The JDE Hompage explain JDE as "an Emacs Lisp package that provides a
highly configurable Emacs wrapper for command-line Java development
tools, such as those provided in JavaSoft's JDK. The JDE provides menu
access to a Java compiler, debugger, and API doc. The Emacs/JDE
combination adds features typically missing from command-line tools,
including: syntax coloring, auto indentation, compile error to source
links, source-level debugging, source code browsing."
Visaj (commercial)
Visaj is a rapid visual application builder for Java written
completely in Java. It fully supports JavaBeans and the Java 2
Platform. Visaj enhances developers' productivity by providing a
point-and-click environment and advanced layout editors for rapidly
building pure Java applications.
The rapidity and flexibility inherent in the builder shortens
development times significantly. Its many features, which include an
image editor, resource bundle constructor and live event wiring, means
even the most sophisticated of designs can be put together with ease.
Its full support for Swing brings the power of Sun's rich Java
Foundation Classes to all Java developers and allows developers to
reuse third-party or in-house components with ease.
Visaj and applications built with it are fully compliant with the Sun
Microsystems Java Developer's Kit v. 1.1 and JavaBeans, and will run
on ANY Java platform.
Free evaluation copies are available for download from Imperial
Software Technology.
Sun's Java WorkShop(tm) v2.0 (commercial/trial)
If you have the commercial or trial version, grab the patch for linux
at ftp://ftp.suse.com/pub/SuSE-Linux/suse_update/JWS2.0/. For the
trial version essentially do everything it asks except inserting the
CD. And also erase that huge JDK directory and replacing it with a
soft link to your jdk (but you shouldn't even have to do that). SuSE
distributes it commercially as well.
Instant Basic(tm) for Java(tm) (commercial)
Instant Basic for Java (IB4J) is the first and only 100% Pure Java(tm)
certified fourth-generation language (4GL) tool. It offers an
Integrated Development Environment similar to Microsoft(R) Visual
Basic(R) that enables developers to create new Java-based applets and
applications. IB4J provides easy migration of existing Visual Basic
applications to the Java platform. Available in both a Standard and
Professional Edition.
Sun's JavaStudio(tm) v1.0 (commercial/trial)
If you have the trial version you need to do a few funky things. You
will need the Solaris SPARC distribution and the jws.zip file from the
win32 distribution. Yes that means you must have access to an
installed trail version of JavaStudio on Windows.
* Replace Java-Studio1.0/JDK with a link to /usr/local/java or where
the JDK resides
* Remove the contents of Java-Studio1.0/JS/classes
* Inside Java-Studio1.0/JS/classes, unzip the jws zipfile
* cd to Java-Studio1.0/JS/sparc-S2/bin and apply js-linux.diff
* ./js
FreeBuilder (free)
Still new but the next release looks VERY promising. Visit the
FreeBuilder Homepage. JIT's
* The TYA Just In Time Compiler
TYA is a ``100% inofficial'' JIT-compiler original designed as an
add-on to Randy Chapman's port of JDK 1.0.2 for Linux (x86). Later
I have added some changes in TYA code for working together with
the newer 1.1.x ports by Steve Byrne. TYA is current is a very
stable and usuable development stage. Expect to double the speed
of your java applications. You can download it from the TYA ftp
site .
* Metrowerks JIT for PowerPC
This is freely available from Kevin Buettner and Metrowerks,
thanks guys. Visit the Java for Linux on the PowerPC for more
information and to download it.
* CACAO JIT for Alpha
CACAO is 64 bit just-in-time (JIT) compiler for Java. It
translates Java byte code on demand into native code for the ALPHA
processor. The current version CACAO 0.1 supports the Alpha
processor under Linux and Digital Unix. It can be used with the
class library of the JDK 1.0.2. CACAO version 0.1 does not support
AWT, it only supports java/lang, java/io and java/util.
Java Virtual Machines
* Sun's Java Virtual Machines
The most common is the Java Development Kit (JDK) ports to various
architectures is available at the Ports Page. Sun also has a Java
Runtime Environment (JRE). It includes a Java runtime interpreter
and all required libraries. The JRE does not include appletviewer
or compilers. The JRE is also available at the Ports Page.
* Japhar
Japhar is the Hungry Programer's Java VM. It has been built from
the ground up without consulting Sun's sources. Visit the Japhar
Homepage for more information. Downloads of the distribution are
available at: ftp://ftp.hungry.com/pub/hungry/japhar.
* Kaffe
The Kaffe Homepage says, "Kaffe is a virtual machine design to
execute Java bytecode. Unlike other virtual machines available,
this machine performs "just-in-time" code conversion from the
abstract code to the host machine's native code. This will
ultimately allow execution of Java code at the same speed as
standard compiled code but while maintaining the advantages and
flexibility of code independence. You can download Kaffe at
ftp://ftp.kaffe.org/pub/kaffe/ .
* TowerJ
TowerJ is a native Java deployment compiler and runtime
environment. It allows for the creation of optimized self
contained executables from Java bytecode for improved application
performance, manageability and security.
Translators to Java
* Toba: A Java-to-C Translator
Toba translates Java class files into C source code. This allows
the construction of directly executable programs that avoid the
overhead of interpretation. Toba deals with stand-alone
applications, not applets, and currently support the 1.1 JDK.
* Harissa
Harissa is a Java environment that includes a compiler from Java
bytecode to C and a Java interpreter. While Harissa is aimed at
applications that are statically configured, such as the Javac
compiler, it is also designed to allow code to be dynamically
loaded in an already compiled application. This novel feature is
introduced by integrating our bytecode interpreter in the runtime
library. Data structures are compatible between the Java compiled
code and the interpreter, and data allocated by the interpreter
does not conflict with data allocated by the compiled code.
Harissa is written in C and provides an efficient and flexible
solution for the execution of Java applications.
Compilers
* Jikes
Jikes is a fast, incremental Java byte-code compiler developed by
IBM Research.
Decompilers
* JAD-- the fast JAva Decompiler
The JAD Page says, "Jad is a Java decompiler, i.e. program that
reads one or more Java class files and converts them into Java
source files which can be compiled again. Jad is 100% pure C++
program and it generally works several times faster than
decompilers written in Java. Also Jad doesn't use the Java runtime
for its functioning, therefore no special setup (like changes to
CLASSPATH variable) is required."
Other
* JStyle (free)
JStyle is a family of Java source-code styling filters, written
purely in Java. It includes JSBeautifier - a reindentation filter,
and JSFormatter - a full reformation filter.
* Instant Installer(tm)
100% Pure Java(tm) certified Installer for developers who want to
produce a universal installer that will run on all the Java
platforms. Available from Halcyon Software.
* Instant Converter(tm)
100% Pure Java(tm) converter. Immediate VB to Java Source Code
conversion. Available from Halcyon Software.
* YACC and Lex for Java
Modern Compiler Implementation in Java offers JLex (a lexical
analyzer generator) and CUP (a parser generator) written in Java.
* Free Tools for Java
The Free Tools for Java Page contains an Java Obfuscator, Java
based Installer, Java Assembler and more.
* Packages and Non-development Tools
Some leads are under Other Products.
Προηγούμενο Περιεχόμενα