java class example
Sponsored Links
Sponsored Links
Secleted [ 0 ] software to compare
Results 1 - 15 of about 6486
Runtime Java Class Editor 1.0
Runtime Java Class Editor is a tool for editing loaded (running) Java classes and much more. more>>
RJCE allows all methods or variables of user defined classes to be altered at runtime. These alterations are then applied to a single instance, a collection of instances (i.e. list, set or map), or an entire class.
This helps you to test your application in an interactive way; altering running programs helping a trial and error approach to programming; testing code and saving it when its correct. Long running algorithms, such as simulations, can also easily be refined without the need for restarts or lose of data.
RJCE can be used to write a program from within itself ensuring high coupling between testing and development, with no delay before the outcome of any alterations.
RJCE allows scripts to run from within your application, allowing users to configure or extend an application dynamically, bypassing normal language access rules controlled by public, private and protected. This can be done by easily instatiating an instance of CodeEditorFrame from the rom.gui package.
RJCE permits faster development of applications by allowing easy migration from scripts to Java programs.
<<lessThis helps you to test your application in an interactive way; altering running programs helping a trial and error approach to programming; testing code and saving it when its correct. Long running algorithms, such as simulations, can also easily be refined without the need for restarts or lose of data.
RJCE can be used to write a program from within itself ensuring high coupling between testing and development, with no delay before the outcome of any alterations.
RJCE allows scripts to run from within your application, allowing users to configure or extend an application dynamically, bypassing normal language access rules controlled by public, private and protected. This can be done by easily instatiating an instance of CodeEditorFrame from the rom.gui package.
RJCE permits faster development of applications by allowing easy migration from scripts to Java programs.
Download (3.1MB)
Added: 2005-04-18 License: BSD License Price:
1713 downloads

Java Clazz Utils 1.2.2
Java Clazz Utils offers you a full-featured and crossplatform Java bytecode viewer and decompiler which can support latest Java versions (from 1.4 till 1.6). more>>
Java Clazz Utils 1.2.2 offers you a full-featured and crossplatform Java bytecode viewer and decompiler which can support latest Java versions (from 1.4 till 1.6). It can be used both as command line tool and user application with Swing interface. It contains InfoJ, Decompiler and jclazz-GUI.
Major Features:
- InfoJ can be used to generate information about Java class. The output includes all possible data that can be extracted from class file: fields, methods, attributes, access flags, signatures, debug information, opcodes etc.
- Decompiler can be used to reproduce Java source code from compiled Java class file. It uses debug information to produce Java code which is nearly the same as original source file. Nevertheless, there are several restrictions and Java code constructions that prevent decompiler from producing the same code as original and even correct Java code. You can find out more about these cases below on this page.
- jclazz-GUI is user-friendly interface for quick start and easy to use.
Enhancements:
- Save of decompiled file writes to predefined file name - Fixed
- Condition structures "condition ? operation1 : operation2" were decompiled incorrectly - Fixed
- URL to bug reporting page is corrected
Added: 2009-05-01 License: GPL Price: FREE
1 downloads
Java::Import::Examples 0.03
Java::Import::Examples is an example of how to use Java::Import to call into Java classes. more>>
Java::Import::Examples is an example of how to use Java::Import to call into Java classes.
Making RMI calls from Perl
One nice thing about Java is the extremely straight forward manner in which it allows you to make calls to remote objects residing on distant servers. Many people use this ability as a point of integration between their system and a posible third party or legacy system. Unfortunatly, for the most part the ability to make calls to these remote objects is something that only other Java applications can do without making a big fuss about it. However, we can now do this from Perl.
Assume that I have a RMI server from which I can get data from in the form of simple Java Beans. One method of doing this is to use the GCJ::Cni library and natively compile and wrap a set of Java Classes which can then be used from my Perl script. However, there is an easier way.
Lets begin by descriping the Java interfaces that well be working with. We first have the Remote Interface that we will be interacting with:
import java.rmi.*;
public interface RemoteInterface extends Remote {
public SomeBean getMessage(String seedMessage) throws RemoteException;
}
And we also have the bean we will be asking for:
import java.io.*;
public class SomeBean implements Serializable {
private String value;
public SomeBean() {}
public void setValue ( String _value ) { ... }
public String getValue ( ) { ... }
}
As far as any Perl client program is concerned this is all we need to know about.
Now all there is left to do is write a client:
use Java::Import qw(
java.rmi.Naming
);
my $remote_interface = java::rmi::Naming->lookup(jstring("//localhost/Home"));
my $bean = $remote_interface->getMessage(jstring("Hi there"));
print $bean->getValue(), "n";
Thats all there is. Notice that all we had to tell Java::Import about was java.rmi.Naming, this is because it was the only class we used by name in our Perl code, every other Java class (the objects held by $bean and $remote_interface) was returned by some other method call originating from java.rmi.Naming.
In order to run this example we have to make sure everything is in its place. We start by compiling the client code. Assuming that we have been given a Stub class file (RemoteObject_Stub.class) we can do the following:
gcj -C SomeBean.java RemoteInterface.java
fastjar -cvf client.jar SomeBean.class RemoteInterface.class RemoteObject_Stub.class
Making sure our server is reachable we can then run the client code:
CLASSPATH=client.jar perl client.pl
Thats it, you should then see the message returned by your server.
<<lessMaking RMI calls from Perl
One nice thing about Java is the extremely straight forward manner in which it allows you to make calls to remote objects residing on distant servers. Many people use this ability as a point of integration between their system and a posible third party or legacy system. Unfortunatly, for the most part the ability to make calls to these remote objects is something that only other Java applications can do without making a big fuss about it. However, we can now do this from Perl.
Assume that I have a RMI server from which I can get data from in the form of simple Java Beans. One method of doing this is to use the GCJ::Cni library and natively compile and wrap a set of Java Classes which can then be used from my Perl script. However, there is an easier way.
Lets begin by descriping the Java interfaces that well be working with. We first have the Remote Interface that we will be interacting with:
import java.rmi.*;
public interface RemoteInterface extends Remote {
public SomeBean getMessage(String seedMessage) throws RemoteException;
}
And we also have the bean we will be asking for:
import java.io.*;
public class SomeBean implements Serializable {
private String value;
public SomeBean() {}
public void setValue ( String _value ) { ... }
public String getValue ( ) { ... }
}
As far as any Perl client program is concerned this is all we need to know about.
Now all there is left to do is write a client:
use Java::Import qw(
java.rmi.Naming
);
my $remote_interface = java::rmi::Naming->lookup(jstring("//localhost/Home"));
my $bean = $remote_interface->getMessage(jstring("Hi there"));
print $bean->getValue(), "n";
Thats all there is. Notice that all we had to tell Java::Import about was java.rmi.Naming, this is because it was the only class we used by name in our Perl code, every other Java class (the objects held by $bean and $remote_interface) was returned by some other method call originating from java.rmi.Naming.
In order to run this example we have to make sure everything is in its place. We start by compiling the client code. Assuming that we have been given a Stub class file (RemoteObject_Stub.class) we can do the following:
gcj -C SomeBean.java RemoteInterface.java
fastjar -cvf client.jar SomeBean.class RemoteInterface.class RemoteObject_Stub.class
Making sure our server is reachable we can then run the client code:
CLASSPATH=client.jar perl client.pl
Thats it, you should then see the message returned by your server.
Download (0.028MB)
Added: 2007-06-01 License: Perl Artistic License Price:
876 downloads
DB_cart Class 1.13
DB_cart Class is a MySQL shopping cart script that can be used with third party product catalogues and membership systems. more>>
DB_cart Class is a MySQL shopping cart script that can be used with third party product catalogues and membership systems. The MySQL database structure is neutral to existing systems.
DB_cart Class can handle the shopping cart (add, update, and empty) and checkout process (set the shipment address and email the order).
For existing cart users, the shopping cart is still available upon the users next visit and is visible by checkout. The last option is configurable togther with a time period.
Enhancements:
- There are modifications and improvements inside the main class file, several examples, and the table structure has been extended.
- There two additional fields for the shipment values (name2 and address2).
- All messages are available in German, English, and Dutch.
- The standard text inside the email messages is in external files now; this content is parsed inside the improved email method.
<<lessDB_cart Class can handle the shopping cart (add, update, and empty) and checkout process (set the shipment address and email the order).
For existing cart users, the shopping cart is still available upon the users next visit and is visible by checkout. The last option is configurable togther with a time period.
Enhancements:
- There are modifications and improvements inside the main class file, several examples, and the table structure has been extended.
- There two additional fields for the shipment values (name2 and address2).
- All messages are available in German, English, and Dutch.
- The standard text inside the email messages is in external files now; this content is parsed inside the improved email method.
Download (0.035MB)
Added: 2006-06-16 License: BSD License Price:
1227 downloads
asm2class 0.1.2
asm2class is an assembly Java to class file compiler. more>>
Asm2class is a java assembly to class file compiler.
Asm2class is release under the terms of the GPL License. The current version of asm2class (0.1.2) is a beta version and allow generating class file from java assembly file that contains class definition, field definition, method definition and constructor definition.
This release support also abstract class, abstract method and native method definition.
Asm2class know more thatn 90% of the java assembly language. Asm2class can do dead code detection, uninitialized register detection.
<<lessAsm2class is release under the terms of the GPL License. The current version of asm2class (0.1.2) is a beta version and allow generating class file from java assembly file that contains class definition, field definition, method definition and constructor definition.
This release support also abstract class, abstract method and native method definition.
Asm2class know more thatn 90% of the java assembly language. Asm2class can do dead code detection, uninitialized register detection.
Download (1.17MB)
Added: 2005-04-22 License: GPL (GNU General Public License) Price:
1646 downloads
jclassinfo 0.19.1
jclassinfo is an information extractor for Java bytecode. more>>
jclassinfo reads java class files and provides information about the class, dependencies and more. It is a pure C implementantion.
Main features:
Class Information
- Java VM version required,
- super class,
- interfaces implemented. --general-info
- Constant pool dump --constant-pool
- Methods --methods
- Fields --fields
- Class attributes --attributes
Dependency Information
- Packages required --packages
- Classes required --classes
- Methods required --methods-ref
Options affecting verbosity
- Disassemble code --disasm
- Print limits and exception table for methods --verbose
- Print debugging information --method-debug-info
- Change visibility --visibility=< public | package | protected | private | synthetic >
<<lessMain features:
Class Information
- Java VM version required,
- super class,
- interfaces implemented. --general-info
- Constant pool dump --constant-pool
- Methods --methods
- Fields --fields
- Class attributes --attributes
Dependency Information
- Packages required --packages
- Classes required --classes
- Methods required --methods-ref
Options affecting verbosity
- Disassemble code --disasm
- Print limits and exception table for methods --verbose
- Print debugging information --method-debug-info
- Change visibility --visibility=< public | package | protected | private | synthetic >
Download (0.026MB)
Added: 2005-03-07 License: GPL (GNU General Public License) Price:
1693 downloads
Class::HPLOO 0.23
Class::HPLOO is an easier way to declare classes on Perl, based in the popular class {...} style and ePod. more>>
Class::HPLOO is an easier way to declare classes on Perl, based in the popular class {...} style and ePod.
USAGE
use Class::HPLOO ;
class Foo extends Bar , Baz {
use LWP::Simple qw(get) ; ## import the method get() to this package.
attr ( array foo_list , int age , string name , foo ) ## define attributes.
vars ($GLOBAL_VAR) ; ## same as: use vars qw($GLOBAL_VAR);
my ($local_var) ;
## constructor/initializer:
sub Foo {
$this->{attr} = $_[0] ;
}
## methods with input variables declared:
sub get_pages ($base , @pages , %options) {
my @htmls ;
if ( $options{proxy} ) { ... }
foreach my $pages_i ( @pages ) {
my $url = "$base/$pages_i" ;
my $html = get($url) ;
push(@htmls , $html) ;
$this->cache($url , $html) ;
}
return @htmls ;
}
## methos like a normal Perl sub:
sub cache {
my ( $url , $html ) = @_ ;
$this->{CACHE}{$url} = $html ;
}
sub attributes_example {
$this->set_foo_list(qw(a b c d e f)) ;
my @l = $this->get_foo_list ;
$this->set_age(30) ;
$this->set_name("Joe") ;
$this->set_foo( time() ) ;
print "NAME: ". $this->get_name ."n" ;
print "AGE: ". $this->get_age ."n" ;
print "FOO: ". $this->get_foo ."n" ;
}
}
## Example of use of the class:
package main ;
my $foo = new Foo(123) ;
$foo->get_pages(http://www.perlmonks.com/, [/index.pl,/foo] , {proxy => localhost:8080}) ;
<<lessUSAGE
use Class::HPLOO ;
class Foo extends Bar , Baz {
use LWP::Simple qw(get) ; ## import the method get() to this package.
attr ( array foo_list , int age , string name , foo ) ## define attributes.
vars ($GLOBAL_VAR) ; ## same as: use vars qw($GLOBAL_VAR);
my ($local_var) ;
## constructor/initializer:
sub Foo {
$this->{attr} = $_[0] ;
}
## methods with input variables declared:
sub get_pages ($base , @pages , %options) {
my @htmls ;
if ( $options{proxy} ) { ... }
foreach my $pages_i ( @pages ) {
my $url = "$base/$pages_i" ;
my $html = get($url) ;
push(@htmls , $html) ;
$this->cache($url , $html) ;
}
return @htmls ;
}
## methos like a normal Perl sub:
sub cache {
my ( $url , $html ) = @_ ;
$this->{CACHE}{$url} = $html ;
}
sub attributes_example {
$this->set_foo_list(qw(a b c d e f)) ;
my @l = $this->get_foo_list ;
$this->set_age(30) ;
$this->set_name("Joe") ;
$this->set_foo( time() ) ;
print "NAME: ". $this->get_name ."n" ;
print "AGE: ". $this->get_age ."n" ;
print "FOO: ". $this->get_foo ."n" ;
}
}
## Example of use of the class:
package main ;
my $foo = new Foo(123) ;
$foo->get_pages(http://www.perlmonks.com/, [/index.pl,/foo] , {proxy => localhost:8080}) ;
Download (0.027MB)
Added: 2007-06-09 License: Perl Artistic License Price:
867 downloads
Java Binary Enhancement Tool 3 R1
Java Binary Enhancement Tool is a Java assembler, dissassembler, and binary editor. more>>
The Java Binary Enhancement Tool (JBET) is a general Java program analysis and manipulation tool. Existing class files can be disassembled, reassembled, or edited programmatically through the JBET API. JBET can also be used to create new Java class files from scratch. JBET uses a convenient internal representation of all the contents of Java binary (.class) files, allowing the user to edit the classes easily, in a structured manner.
JBET was developed as part of the DARPA Self-Protecting Mobile Agents project under the OASIS and Active Networks programs (contract number N66001-00-C-8602) in order to study automated software obfuscation.
The Java language was chosen for this project because of the (relative) ease of constructing binary editing tools provided by the large amount of type information present in the class files. Our two reports, the Obfuscation Techniques Evaluation Report, and the Obfuscation Report, are available from the download area. The obfuscation tool developed is not part of this release.
JBET was also used in the DARPA/AFRL Survivable Server project (contract number F30602-00-C-0183) to add additional security checks to the Java Standard Library. (The Java SecurityManager API does not support many desirable security checks, such as continued authorization of file accesses after opening.)
JBET was used to replace the native method references in the Java standard library with stubs that call a pluggable security policy. This tool, called Jpolicy, is also available for download at this website. Jpolicy is very incomplete at this time, but may be interesting to those working in Java security or changing the standard library themselves.
The internal representation of Java class files used by JBET is intented to make it easy for programmers to write Java binary code transforms. Each element of Java class files has a corresponding internal data structure: ClassInfo for entire classes, MethodInfo for methods, FieldInfo for fields, Snippit for code blocks, and Instruction for individual instructions. Snippit and Instruction understand Java opcode syntax and semantics, allowing automated creation of valid Java programs. A Java-compatible class verifier is also included.
Some code transforms are difficult to program directly by manipulating Java instructions. For those transforms, a directed acyclic graph (DAG) representation of code is available. In the DAG representation, each basic block has a corresponding DAG, with a set of input and output nodes. Edges in the graph connect "producer" nodes (such as constants, or the result of calculations) to "user" nodes (such as method calls or other calculations). Methods are divided into basic blocks and control flow is stored at the basic block level (possible because Java has only fixed jump targets)
JBET requires a Java 1.4 virtual machine to run, although it can operate on class files from earlier Java versions. The packaging and build environment supplied supports Linux and Windows with Cygwin; however, the build process is simple and could be performed manually on other platforms. Perl is required for regression testing.
Jpolicy requires a Java 1.4 virtual machine to build, either Linux or Windows NT/XP with Cygwin. gcc is required for building on Windows (supplied with Cygwin). The runtime system can be either Java 1.3 or 1.4 (with Suns JVM only), running on Linux or Windows NT/XP. Windows 9x and Windows 2000 may work as well, but have not been tested.
Installation
1. Install jdk 1.4.1.
2. Set CLASSPATH to jdk1.4.1/jre/lib/rt.jar
3. cd src; make
4. If that didnt work, examine the makefile. java or javac may not be in the path.
5. To build a jar file that can be used with "java -jar jbet.jar", run "make jar".
6. If you have perl installed, run the tests with "make test".
Optionally, run "make regen; make test".
Make a symbolic link from jbet3/bin/jbet to somewhere in your path.
Usage
JBET uses the JNI format for class names, and JNI type and method descriptors. For a summary of this syntax, use jbet help syntax. Suns JVM specification may also be helpful.
To look at a class disassembly, use jbet print. Try disassembling a class you have source for, and was built with debug info (-g): jbet -P < classpath > print < classname >. Suns JVM specification has an instruction reference.
<<lessJBET was developed as part of the DARPA Self-Protecting Mobile Agents project under the OASIS and Active Networks programs (contract number N66001-00-C-8602) in order to study automated software obfuscation.
The Java language was chosen for this project because of the (relative) ease of constructing binary editing tools provided by the large amount of type information present in the class files. Our two reports, the Obfuscation Techniques Evaluation Report, and the Obfuscation Report, are available from the download area. The obfuscation tool developed is not part of this release.
JBET was also used in the DARPA/AFRL Survivable Server project (contract number F30602-00-C-0183) to add additional security checks to the Java Standard Library. (The Java SecurityManager API does not support many desirable security checks, such as continued authorization of file accesses after opening.)
JBET was used to replace the native method references in the Java standard library with stubs that call a pluggable security policy. This tool, called Jpolicy, is also available for download at this website. Jpolicy is very incomplete at this time, but may be interesting to those working in Java security or changing the standard library themselves.
The internal representation of Java class files used by JBET is intented to make it easy for programmers to write Java binary code transforms. Each element of Java class files has a corresponding internal data structure: ClassInfo for entire classes, MethodInfo for methods, FieldInfo for fields, Snippit for code blocks, and Instruction for individual instructions. Snippit and Instruction understand Java opcode syntax and semantics, allowing automated creation of valid Java programs. A Java-compatible class verifier is also included.
Some code transforms are difficult to program directly by manipulating Java instructions. For those transforms, a directed acyclic graph (DAG) representation of code is available. In the DAG representation, each basic block has a corresponding DAG, with a set of input and output nodes. Edges in the graph connect "producer" nodes (such as constants, or the result of calculations) to "user" nodes (such as method calls or other calculations). Methods are divided into basic blocks and control flow is stored at the basic block level (possible because Java has only fixed jump targets)
JBET requires a Java 1.4 virtual machine to run, although it can operate on class files from earlier Java versions. The packaging and build environment supplied supports Linux and Windows with Cygwin; however, the build process is simple and could be performed manually on other platforms. Perl is required for regression testing.
Jpolicy requires a Java 1.4 virtual machine to build, either Linux or Windows NT/XP with Cygwin. gcc is required for building on Windows (supplied with Cygwin). The runtime system can be either Java 1.3 or 1.4 (with Suns JVM only), running on Linux or Windows NT/XP. Windows 9x and Windows 2000 may work as well, but have not been tested.
Installation
1. Install jdk 1.4.1.
2. Set CLASSPATH to jdk1.4.1/jre/lib/rt.jar
3. cd src; make
4. If that didnt work, examine the makefile. java or javac may not be in the path.
5. To build a jar file that can be used with "java -jar jbet.jar", run "make jar".
6. If you have perl installed, run the tests with "make test".
Optionally, run "make regen; make test".
Make a symbolic link from jbet3/bin/jbet to somewhere in your path.
Usage
JBET uses the JNI format for class names, and JNI type and method descriptors. For a summary of this syntax, use jbet help syntax. Suns JVM specification may also be helpful.
To look at a class disassembly, use jbet print. Try disassembling a class you have source for, and was built with debug info (-g): jbet -P < classpath > print < classname >. Suns JVM specification has an instruction reference.
Download (0.19MB)
Added: 2005-03-07 License: BSD License Price:
1697 downloads
GCJ::Cni::Examples 0.03
GCJ::Cni::Examples is a Perl module with examples of how to use GCJs CNI interface to write Perl Modules in Java. more>>
GCJ::Cni::Examples is a Perl module with examples of how to use GCJs CNI interface to write Perl Modules in Java.
EXAMPLES
Writing Treaded modules in Java
One benefit of using GCJ is that it takes advantage of POSIX threading. This is nice since Perls threading model is, shall we say, less than ideal. Now, you could theoretically write a module in C or C++ and and use the standard POSIX library to do your threaded work for you, however, why not take advantage of the nice Threading interface that Java provides to you by default. This may also come in handy if you have a massively threaded Java library that youd like to call from Perl.
For this example assume that I want to do matrix multiplication, albeit in a very crazy manner. Therefore, I will write a Java class, Matrix, and a method, multiply, which will take another matrix to perform the operation between. Heres the crazy part, for each cell in the resulting matrix I will spawn a new thread, as an internal class, and give it a row and a column from which they will derive the result. I know this is a little wierd but the point is that Ill be spawning a lot of new threads. To multiply two 10x10 matrices we will have to spawn 100 threads (one thread per cell in the resulting 10x10 matrix). Imagine doing this in Perl, then imagine doing it in Java; natively compiled Java. Much faster and a lot less headaches.
The Java Interface/pseudocode is as follows:
public class Matrix {
public Matrix ( int numRows, int numCols ) {
...Constructor stuff...
}
public void set ( int row, int col, int val ) {
...set an element...
}
public int get ( int row, int col ) {
...get an element...
}
public Matrix multiply ( Matrix times ) {
...set it up...
for ( int i = 0; i < rows; i++ ) {
for ( int j = 0; j < times.getCols(); j++ ) {
//GO NUTS!!!!
ArrayMultiplier multiplier = new ArrayMultiplier(this, times, result, i, j);
multiplier.start();
...etc...
}
}
...wait for the threads to exit and return the new matrix...
}
public int getRows ( ) {
...get number of rows...
}
public int getCols ( ) {
...get number of columns...
}
public void print ( ) {
...print the matrix to stdout...
}
private class ArrayMultiplier extends Thread {
public ArrayMultiplier ( Matrix a, Matrix b, Matrix result, int row, int col ) {
...Construct this bad boy...
}
public void run ( ) {
int sum = 0;
for ( int i = 0; i < a.getCols(); i++ ) {
sum += (a.get(row, i) * b.get(i, col));
}
result.set(row, col, sum);
}
}
}
Now, we want to call this class from Perl. My perferred manner is through SWIG so thats what were going to use. However, you do not need to use SWIG, you can use whatever method you prefer when wrapping C++ classes. We begin by creating a C++ header file from our above class. This is done by using GCJs gcjh utility. First we need to class compile Matrix.java
gcj -C Matrix.java
Then we go ahead and create the header file:
gcjh Matrix
Easy enough. We can then extract the interface we want to have available in Perl from the generated header file and from it create a i file to be used as input to SWIG. I usually start by copying my header file to the same named file but with an i extension instead. I then remove all of the grimy C++ gruff, private methods and variables, slap a module directive on it and call it done. It wont always be this easy though. When youre done an interface file for the above class should look something like this:
%module Matrix;
typedef int jint;
class Matrix
{
public:
Matrix (jint, jint);
virtual void set (jint, jint, jint);
virtual jint get (jint, jint);
virtual ::Matrix *multiply (::Matrix *);
virtual jint getRows ();
virtual jint getCols ();
virtual void print ();
};
We then put SWIG to work and generate our C++ wrapper for Perl:
swig -perl -c++ Matrix.i
After the above command we now will see two new files in our current directory, Matrix.pm and Matrix_wrap.cxx; these correspond the module directive we gave in Matrix.i.
At this point all we have left to do is compile, and use.
gcj -c Matrix.java
gcc -c -I -include Matrix.h Matrix_wrap.cxx
gcc -shared -lgcj -lstdc++ Matrix.o Matrix_wrap.o -oMatrix.so
A simple Perl file using this module might look something like:
sub populate_matrix {
my $matrix = shift;
for ( my $i = 0; $i < $matrix->getRows(); $i++ ) {
for ( my $j = 0; $j < $matrix->getCols(); $j++ ) {
$matrix->set($i, $j, $i * $j);
}
}
}
use GCJ::Cni;
use Matrix;
GCJ::Cni::JvCreateJavaVM(undef);
GCJ::Cni::JvAttachCurrentThread(undef, undef);
my $matrix = new Matrix::Matrix(10, 10);
populate_matrix($matrix);
my $matrix2 = new Matrix::Matrix(10, 10);
populate_matrix($matrix2);
$matrix3 = $matrix->multiply($matrix2);
$matrix3->print();
GCJ::Cni::JvDetachCurrentThread();
Ill leave it up to the reader to write a Perl module that does the same thing, that is, spawns 100 threads. In my own personal fiddling I found that just spawning that many threads (never mind doing any kind of work) was over 3 time slower in Perl. In this situation we at least get to use our favorite language, Perl, and offload some of the heavy hitting to a language more suited for it.
Where this really comes in handy is when you have an existing multi-threaded Java library that you would like to expose to Perl. You could theoretically natively compile various components of your library and then generate Perl bindings to access it. In this way, you get a little extra speed and efficiency as well as code reuse and binding.
<<lessEXAMPLES
Writing Treaded modules in Java
One benefit of using GCJ is that it takes advantage of POSIX threading. This is nice since Perls threading model is, shall we say, less than ideal. Now, you could theoretically write a module in C or C++ and and use the standard POSIX library to do your threaded work for you, however, why not take advantage of the nice Threading interface that Java provides to you by default. This may also come in handy if you have a massively threaded Java library that youd like to call from Perl.
For this example assume that I want to do matrix multiplication, albeit in a very crazy manner. Therefore, I will write a Java class, Matrix, and a method, multiply, which will take another matrix to perform the operation between. Heres the crazy part, for each cell in the resulting matrix I will spawn a new thread, as an internal class, and give it a row and a column from which they will derive the result. I know this is a little wierd but the point is that Ill be spawning a lot of new threads. To multiply two 10x10 matrices we will have to spawn 100 threads (one thread per cell in the resulting 10x10 matrix). Imagine doing this in Perl, then imagine doing it in Java; natively compiled Java. Much faster and a lot less headaches.
The Java Interface/pseudocode is as follows:
public class Matrix {
public Matrix ( int numRows, int numCols ) {
...Constructor stuff...
}
public void set ( int row, int col, int val ) {
...set an element...
}
public int get ( int row, int col ) {
...get an element...
}
public Matrix multiply ( Matrix times ) {
...set it up...
for ( int i = 0; i < rows; i++ ) {
for ( int j = 0; j < times.getCols(); j++ ) {
//GO NUTS!!!!
ArrayMultiplier multiplier = new ArrayMultiplier(this, times, result, i, j);
multiplier.start();
...etc...
}
}
...wait for the threads to exit and return the new matrix...
}
public int getRows ( ) {
...get number of rows...
}
public int getCols ( ) {
...get number of columns...
}
public void print ( ) {
...print the matrix to stdout...
}
private class ArrayMultiplier extends Thread {
public ArrayMultiplier ( Matrix a, Matrix b, Matrix result, int row, int col ) {
...Construct this bad boy...
}
public void run ( ) {
int sum = 0;
for ( int i = 0; i < a.getCols(); i++ ) {
sum += (a.get(row, i) * b.get(i, col));
}
result.set(row, col, sum);
}
}
}
Now, we want to call this class from Perl. My perferred manner is through SWIG so thats what were going to use. However, you do not need to use SWIG, you can use whatever method you prefer when wrapping C++ classes. We begin by creating a C++ header file from our above class. This is done by using GCJs gcjh utility. First we need to class compile Matrix.java
gcj -C Matrix.java
Then we go ahead and create the header file:
gcjh Matrix
Easy enough. We can then extract the interface we want to have available in Perl from the generated header file and from it create a i file to be used as input to SWIG. I usually start by copying my header file to the same named file but with an i extension instead. I then remove all of the grimy C++ gruff, private methods and variables, slap a module directive on it and call it done. It wont always be this easy though. When youre done an interface file for the above class should look something like this:
%module Matrix;
typedef int jint;
class Matrix
{
public:
Matrix (jint, jint);
virtual void set (jint, jint, jint);
virtual jint get (jint, jint);
virtual ::Matrix *multiply (::Matrix *);
virtual jint getRows ();
virtual jint getCols ();
virtual void print ();
};
We then put SWIG to work and generate our C++ wrapper for Perl:
swig -perl -c++ Matrix.i
After the above command we now will see two new files in our current directory, Matrix.pm and Matrix_wrap.cxx; these correspond the module directive we gave in Matrix.i.
At this point all we have left to do is compile, and use.
gcj -c Matrix.java
gcc -c -I -include Matrix.h Matrix_wrap.cxx
gcc -shared -lgcj -lstdc++ Matrix.o Matrix_wrap.o -oMatrix.so
A simple Perl file using this module might look something like:
sub populate_matrix {
my $matrix = shift;
for ( my $i = 0; $i < $matrix->getRows(); $i++ ) {
for ( my $j = 0; $j < $matrix->getCols(); $j++ ) {
$matrix->set($i, $j, $i * $j);
}
}
}
use GCJ::Cni;
use Matrix;
GCJ::Cni::JvCreateJavaVM(undef);
GCJ::Cni::JvAttachCurrentThread(undef, undef);
my $matrix = new Matrix::Matrix(10, 10);
populate_matrix($matrix);
my $matrix2 = new Matrix::Matrix(10, 10);
populate_matrix($matrix2);
$matrix3 = $matrix->multiply($matrix2);
$matrix3->print();
GCJ::Cni::JvDetachCurrentThread();
Ill leave it up to the reader to write a Perl module that does the same thing, that is, spawns 100 threads. In my own personal fiddling I found that just spawning that many threads (never mind doing any kind of work) was over 3 time slower in Perl. In this situation we at least get to use our favorite language, Perl, and offload some of the heavy hitting to a language more suited for it.
Where this really comes in handy is when you have an existing multi-threaded Java library that you would like to expose to Perl. You could theoretically natively compile various components of your library and then generate Perl bindings to access it. In this way, you get a little extra speed and efficiency as well as code reuse and binding.
Download (0.020MB)
Added: 2007-06-04 License: Perl Artistic License Price:
877 downloads
Java::JCR::Nodetype 0.08
Java::JCR::Nodetype is a Perl module that can load the JCR node type class wrappers. more>>
Java::JCR::Nodetype is a Perl module that can load the JCR node type class wrappers.
SYNOPSIS
use Java::JCR::Nodetype;
This loads the Perl classes mapped to the javax.jcr.nodetype package.
You might notice the odd letter case of this package differs from that of the node type class (Java::JCR::Nodetype::NodeType). This has to do with the way the package was imported. This may be corrected in the future.
<<lessSYNOPSIS
use Java::JCR::Nodetype;
This loads the Perl classes mapped to the javax.jcr.nodetype package.
You might notice the odd letter case of this package differs from that of the node type class (Java::JCR::Nodetype::NodeType). This has to do with the way the package was imported. This may be corrected in the future.
Download (0.047MB)
Added: 2007-06-05 License: Perl Artistic License Price:
871 downloads
Java::JCR::Workspace 0.08
Java::JCR::Workspace is a Perl wrapper for javax.jcr.Workspace. more>>
Java::JCR::Workspace is a Perl wrapper for javax.jcr.Workspace.
This is an automatically generated package wrapping javax.jcr.Workspace with a nice Perlish API.
For full documentation of what this class does, see the Java API documentation: http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/Workspace.html
The deviations from the API documentation include the following:
- You will need to use Perl, intead of Java, to make any use of this API. (Duh.)
The package to use is Java::JCR::Workspace, rather than javax.jcr.Workspace.
- All method names have been changed from Java-style camelCase() to Perl-style lower_case().
Thus, if the function were named getName() in the Java API, it will be named get_name() in this API. As another example, nextEventListener() in the Java API will be next_event_listener() in this API.
- Handle exceptions just like typical Perl. Java::JCR::Exception takes care of making sure that works as expected.
<<lessThis is an automatically generated package wrapping javax.jcr.Workspace with a nice Perlish API.
For full documentation of what this class does, see the Java API documentation: http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/Workspace.html
The deviations from the API documentation include the following:
- You will need to use Perl, intead of Java, to make any use of this API. (Duh.)
The package to use is Java::JCR::Workspace, rather than javax.jcr.Workspace.
- All method names have been changed from Java-style camelCase() to Perl-style lower_case().
Thus, if the function were named getName() in the Java API, it will be named get_name() in this API. As another example, nextEventListener() in the Java API will be next_event_listener() in this API.
- Handle exceptions just like typical Perl. Java::JCR::Exception takes care of making sure that works as expected.
Download (0.047MB)
Added: 2007-06-04 License: Perl Artistic License Price:
872 downloads
Java::JCR::Exception 0.08
Java::JCR::Exception is a Perl wrapper for repository exceptions. more>>
Java::JCR::Exception is a Perl wrapper for repository exceptions.
SYNOPSIS
eval {
my $node = $root->add_node(foo, nt:unstructured);
};
if ($@) {
print STDERR "Failed to add node foo: $@n";
}
This class is used to make the exceptions thrown from the Java code work more nicely in Perl. Primarily, this involves performing nicer stringification than is provided by Inline::Java.
<<lessSYNOPSIS
eval {
my $node = $root->add_node(foo, nt:unstructured);
};
if ($@) {
print STDERR "Failed to add node foo: $@n";
}
This class is used to make the exceptions thrown from the Java code work more nicely in Perl. Primarily, this involves performing nicer stringification than is provided by Inline::Java.
Download (0.047MB)
Added: 2007-06-05 License: Perl Artistic License Price:
871 downloads
Java::JCR::Lock 0.08
Java::JCR::Lock is a Perl module that can load JCR lock extension wrappers. more>>
Java::JCR::Lock is a Perl module that can load JCR lock extension wrappers.
SYNOPSIS
use Java::JCR::Lock
This loads the Perl classes mapped to the Java package named javax.jcr.lock.
Installation:
Installation can be a bit tricky because this library depends upon Inline::Java,
which didnt install without going through the process by hand. (I usually just
let CPAN do all the work.) You must first install Inline::Java.
Then, you must install libwww-perl, as I use that to download the Jar files. I
hope to remove this dependency in the future, but its there for now.
After installing both of those, you should be able to run:
perl Build.PL
./Build
./Build test
./Build install
I generally try to make my build scripts as standard as possible. If you prefer
using make, I have Module::Build distributing a makefile generator too:
perl Makefile.PL
make
make test
make install
<<lessSYNOPSIS
use Java::JCR::Lock
This loads the Perl classes mapped to the Java package named javax.jcr.lock.
Installation:
Installation can be a bit tricky because this library depends upon Inline::Java,
which didnt install without going through the process by hand. (I usually just
let CPAN do all the work.) You must first install Inline::Java.
Then, you must install libwww-perl, as I use that to download the Jar files. I
hope to remove this dependency in the future, but its there for now.
After installing both of those, you should be able to run:
perl Build.PL
./Build
./Build test
./Build install
I generally try to make my build scripts as standard as possible. If you prefer
using make, I have Module::Build distributing a makefile generator too:
perl Makefile.PL
make
make test
make install
Download (0.047MB)
Added: 2007-06-05 License: Perl Artistic License Price:
872 downloads
Java for C++ 0.4
Java for C++ is a tool to generate C++-wrapper-classes for existing Java-classes. more>>
Java for C++ is a tool to generate C++-wrapper-classes for existing Java-classes. This tool reads a list of Java class names and creates source code for C++-classes to wrap them.
The implementation of the wrapper classes uses JNI (Java Native Interface) to call the "real" Java classes.
The C++-API to use these wrapper classes is very close to the API of the original Java classes. So developers of C++-software can use Java-classes as if they have been implemented in C++.
Enhancements:
- A problem where null values for method arguments, method return values, or field values caused some generated code to crash was fixed.
- Updating is strongly encouraged.
<<lessThe implementation of the wrapper classes uses JNI (Java Native Interface) to call the "real" Java classes.
The C++-API to use these wrapper classes is very close to the API of the original Java classes. So developers of C++-software can use Java-classes as if they have been implemented in C++.
Enhancements:
- A problem where null values for method arguments, method return values, or field values caused some generated code to crash was fixed.
- Updating is strongly encouraged.
Download (0.043MB)
Added: 2005-12-22 License: GPL (GNU General Public License) Price:
1404 downloads
Java Properties 0.8.3
Java Properties provides an efficient way to access bean-like properties of Java objects. more>>
Java Properties provides an efficient way to access bean-like properties of Java objects.
In a nutshell, provides an efficient way to access bean-like properties of java objects. Unlike java bean properties, a chain of properties can be specified efficiently, allowing convenient access to properties of nested domain objects.
Runtime class-generation and caching can be used very easily to obviate the need for reflection, without losing the flexibility it provides.
Class Properties It also provides classes which manipulate objects at runtime by using strings to address conceptual variables (think bean properties) in a similar fashion to the java reflection mechanisms.
Class Property example Say we have the following classes:
public class Order {
...
public Customer getCustomer() { ... }
...
}
public class Customer {
...
public Address getAddress() { ... }
...
}
public class Address {
...
public String getLine1() { ... }
public String getLine2() { ... }
...
}
Now, we could do this to access line 1 of the address:
result = order.getCustomer().getAddress().getLine1();
But what if there are nulls? What if we want to compare the first line of the address from two different orders? Whith properties this is really simple:
ClassProperty p = PropertyManager.getProperty(Order.class,"Customer:Address:Line1",true);
result = p.getValue(order);
The idea is simple enough - you use the string "Customer:Address:Line1" to specify a series of getXXX calls. Importantly, it the library handles nulls for you, returning null if any of the objects in the chain are null.
Note, this is not simply a wrapper around java reflection, since it includes non-reflective optimizations by making use of the cojen library to generate class files at runtime to acces these properties.
The real benefit lies in being able to specify which properties you wish to access at runtime. You can even pass this ability on to the users of your library or application. Unlike reflection, class files are generated for the properties, and these files are cached - which means once you have specified a property once, further uses of the same property dont use reflection and are very fast.
Property API vs Java Bean Properties. The property API models accessor/mutator method pairs as conceptual variables called properties. The approach used is similar to, but more flexible than java bean properties, and more performant than reflection if runtime class generation is used. Unlike java bean properties, a chain or path of properties can be specified (and more importantly, turned into bytecode using runtime generation) to traverse a complex tree of objects.
It is simple to create applications portable between different security environments - using runtime generation where allowed, and falling back to reflection where security is tighter.
Dynamic Class Management. The properties package also provides classes to handle the loading (and unloading/reloading) of classes at runtime. It provides a framework useful for dynamically loading runtime-generated classes, for example.
While the property API can happily ignore the dynamic loading framework, it can also make use of it to enable runtime class generation.
<<lessIn a nutshell, provides an efficient way to access bean-like properties of java objects. Unlike java bean properties, a chain of properties can be specified efficiently, allowing convenient access to properties of nested domain objects.
Runtime class-generation and caching can be used very easily to obviate the need for reflection, without losing the flexibility it provides.
Class Properties It also provides classes which manipulate objects at runtime by using strings to address conceptual variables (think bean properties) in a similar fashion to the java reflection mechanisms.
Class Property example Say we have the following classes:
public class Order {
...
public Customer getCustomer() { ... }
...
}
public class Customer {
...
public Address getAddress() { ... }
...
}
public class Address {
...
public String getLine1() { ... }
public String getLine2() { ... }
...
}
Now, we could do this to access line 1 of the address:
result = order.getCustomer().getAddress().getLine1();
But what if there are nulls? What if we want to compare the first line of the address from two different orders? Whith properties this is really simple:
ClassProperty p = PropertyManager.getProperty(Order.class,"Customer:Address:Line1",true);
result = p.getValue(order);
The idea is simple enough - you use the string "Customer:Address:Line1" to specify a series of getXXX calls. Importantly, it the library handles nulls for you, returning null if any of the objects in the chain are null.
Note, this is not simply a wrapper around java reflection, since it includes non-reflective optimizations by making use of the cojen library to generate class files at runtime to acces these properties.
The real benefit lies in being able to specify which properties you wish to access at runtime. You can even pass this ability on to the users of your library or application. Unlike reflection, class files are generated for the properties, and these files are cached - which means once you have specified a property once, further uses of the same property dont use reflection and are very fast.
Property API vs Java Bean Properties. The property API models accessor/mutator method pairs as conceptual variables called properties. The approach used is similar to, but more flexible than java bean properties, and more performant than reflection if runtime class generation is used. Unlike java bean properties, a chain or path of properties can be specified (and more importantly, turned into bytecode using runtime generation) to traverse a complex tree of objects.
It is simple to create applications portable between different security environments - using runtime generation where allowed, and falling back to reflection where security is tighter.
Dynamic Class Management. The properties package also provides classes to handle the loading (and unloading/reloading) of classes at runtime. It provides a framework useful for dynamically loading runtime-generated classes, for example.
While the property API can happily ignore the dynamic loading framework, it can also make use of it to enable runtime class generation.
Download (0.017MB)
Added: 2007-01-10 License: GPL (GNU General Public License) Price:
1017 downloads
Secleted [ 0 ] software to compare
Copyright Notice:
Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future software development. The above java class example search only lists software in full, demo and trial versions for free download. Download links are directly from our mirror sites or publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed