Difference between revisions of "Using the Java Virtual Machine"

From wiki.emacinc.com
Jump to: navigation, search
m (Fixed bug.)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{todo|SEOKWREV; Finish Writing; (05.06.14-17:30->KY+)|Klint Youngmeyer|project=oe 4, oe 5,md,ky,SEOKWREV,bs}}
+
{{todo|Revise; Finish Writing; (05.06.14-17:30->KY+)(05.07.14-14:55->MD+)(05.07.14-17:56->KY+)(05.07.14-19:15->MD+)(05.07.15-15:25->MG+)|Klint Youngmeyer|project=oe 4, oe 5,md,ky,mg,Revise,bs}}
  
 
{{#seo:
 
{{#seo:
Line 7: Line 7:
 
|description=A short tutorial for using the JamVM Java Virtual Machine.
 
|description=A short tutorial for using the JamVM Java Virtual Machine.
 
}}
 
}}
The Java Virtual Machine is an optional package and is not included by default in EMAC Linux builds. If you would like to include this package with your build, the custom package number is SL040-NPN-00140. To inquire about purchasing this package, please contact EMAC at [http://info@emacinc.com info@emacinc.com].
+
{{warning | The Java Virtual Machine is an optional package and is not included by default in EMAC Linux builds.}}
 +
 
  
 
== JamVM ==
 
== JamVM ==
  
A Java virtual machine (JVM) is the software that converts Java bytecode into a program that can run in the target system. Java mostly uses the just in time (JIT) compilation method which partially compiles the code so that the JVM on any target can complete compiling the code for the target's specific instruction set. The JIT method saves time by only needing to be compiled once then using the same bytecode on multiple separate platforms. The Java Virtual Machine that is included in the EMAC package is JamVM. JamVM is a small, open source virtual machine that conforms to the Java virtual machine specification version 2.
+
A Java virtual machine (JVM) is the software that converts Java bytecode into a program that can run in the target system. Java mostly uses the just in time (JIT) compilation method which partially compiles the java source code into java bytecode.  The JVM on any target can compile the java bytecode into the machine code for the target architecture. The JIT method saves time by performing the parsing, lexical analysis, and source level optimization steps ahead of time, thus allowing the same bytecode to have the final translation into the bytecode for multiple separate platforms at the moment the program is executed on the target platform. The Java Virtual Machine that is included in the EMAC package is JamVM. JamVM is a small, open source virtual machine that conforms to the Java virtual machine specification version 2.
  
 
== Compiling Programs ==
 
== Compiling Programs ==
  
It is not currently possible to compile a Java program directly on an EMAC board. A development computer is needed to compile the program and send the bytecode to the board. The process of compiling a basic Java program is fairly simple, the command for compiling the file <code>HelloWorld.java</code> is:
+
It is not currently possible to compile a Java program directly on an EMAC board. A development computer is needed to compile the program and send the bytecode to the board. The process of compiling a basic Java program is fairly simple; the command for compiling the file <code>HelloWorld.java</code> is:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
developer@ldc:~$ javac HelloWorld.java
 
developer@ldc:~$ javac HelloWorld.java
 
</syntaxhighlight>
 
</syntaxhighlight>
 
The <code>javac</code> command calls the Java compiler on the <code>HelloWorld.java</code> source file and produces a file called <code>HelloWorld.class</code>. The <code>HelloWorld.class</code> file will be used to run the program.
 
The <code>javac</code> command calls the Java compiler on the <code>HelloWorld.java</code> source file and produces a file called <code>HelloWorld.class</code>. The <code>HelloWorld.class</code> file will be used to run the program.
{{mbox  | type=notice | text='''NOTE''': The name of the class in the Java source file must match the name of the file without the <code>.java</code> extension.}}
+
{{mbox  | type=notice | text='''NOTE''': The name of the class in the Java source file must match the basename of the file (the filename without the <code>.java</code> extension).}}
 
<br />
 
<br />
The resulting class file will need to be sent to the target board to be run. The easiest way to accomplish this is through <code>scp</code>, assuming the IP address <code>10.0.2.40</code>, the command is:
+
The resulting class file will need to be sent to the target board to be run. The easiest way to accomplish this is through <code>scp</code>. Assuming the IP address <code>10.0.2.40</code>, the command is:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
developer@ldc:~$ scp HelloWorld.class root@10.0.2.40:/root
 
developer@ldc:~$ scp HelloWorld.class root@10.0.2.40:/root
Line 46: Line 47:
 
* KeyboardReader
 
* KeyboardReader
 
* PrimeNumbers
 
* PrimeNumbers
 +
 +
== How to Acquire ==
 +
 +
EMAC can configure all manner of custom Linux software packages. We are constantly adding additional support for new and different devices, including custom hardware. Our Linux packages are tested and pre-configured to provide functionality and utilities, quickly and easily. If you would like to include this JamVM package with your existing build or on a new build, please contact EMAC [mailto://sales@emacinc.com '''sales'''] for information and pricing. The custom package number for the JamVM package is '''<code>SL040-NPN-00140</code>'''. If you require any other software packages, custom kernel or application development support, contact [mailto://sales@emacinc.com '''sales'''] for a quote.

Latest revision as of 15:53, 10 November 2015

TODO: {{#todo:Revise; Finish Writing; (05.06.14-17:30->KY+)(05.07.14-14:55->MD+)(05.07.14-17:56->KY+)(05.07.14-19:15->MD+)(05.07.15-15:25->MG+)|Klint Youngmeyer|oe 4, oe 5,md,ky,mg,Revise,bs}}


WARNING!
The Java Virtual Machine is an optional package and is not included by default in EMAC Linux builds.



JamVM

A Java virtual machine (JVM) is the software that converts Java bytecode into a program that can run in the target system. Java mostly uses the just in time (JIT) compilation method which partially compiles the java source code into java bytecode. The JVM on any target can compile the java bytecode into the machine code for the target architecture. The JIT method saves time by performing the parsing, lexical analysis, and source level optimization steps ahead of time, thus allowing the same bytecode to have the final translation into the bytecode for multiple separate platforms at the moment the program is executed on the target platform. The Java Virtual Machine that is included in the EMAC package is JamVM. JamVM is a small, open source virtual machine that conforms to the Java virtual machine specification version 2.

Compiling Programs

It is not currently possible to compile a Java program directly on an EMAC board. A development computer is needed to compile the program and send the bytecode to the board. The process of compiling a basic Java program is fairly simple; the command for compiling the file HelloWorld.java is:

developer@ldc:~$ javac HelloWorld.java

The javac command calls the Java compiler on the HelloWorld.java source file and produces a file called HelloWorld.class. The HelloWorld.class file will be used to run the program.


The resulting class file will need to be sent to the target board to be run. The easiest way to accomplish this is through scp. Assuming the IP address 10.0.2.40, the command is:

developer@ldc:~$ scp HelloWorld.class root@10.0.2.40:/root

Running Programs

Running a compiled Java program is accomplished by passing the class name to java. To run the HelloWorld program, use the following command with the HelloWorld.class file in the current directory.

developer@ldc:~$ java HelloWorld


Included Examples

EMAC includes a few sample Java programs on the builds that include the JamVM package. The examples are located in the /home/user/Java-Examples. Both the source files and class files are included on the board. If changes need to be made to a source file, the class file will need to be recompiled on a development computer and sent back to the target board.

The included examples are:

  • BinaryConverter
  • GameOfLife
  • HelloWorld
  • KeyboardReader
  • PrimeNumbers

How to Acquire

EMAC can configure all manner of custom Linux software packages. We are constantly adding additional support for new and different devices, including custom hardware. Our Linux packages are tested and pre-configured to provide functionality and utilities, quickly and easily. If you would like to include this JamVM package with your existing build or on a new build, please contact EMAC sales for information and pricing. The custom package number for the JamVM package is SL040-NPN-00140. If you require any other software packages, custom kernel or application development support, contact sales for a quote.