Java: Difference between revisions
From charlesreid1
No edit summary |
|||
| Line 39: | Line 39: | ||
Hello, world! | Hello, world! | ||
</pre> | </pre> | ||
=Using Jar Files= | |||
If you have a jar file that contains class definitions and you wish to use it, you can do the following: | |||
* To check contents of the jar, use the jar utility - it works a lot like tar | |||
* jar xf - expands (shows contents of) jar | |||
==Compile== | |||
To compile code <code>mysource.java</code> with a jar file called <code>org.example.jar</code>: | |||
On Linux/Mac: | |||
<pre> | |||
javac -cp '.:org.example.jar' mysource.java | |||
</pre> | |||
On Windows: | |||
<pre> | |||
javac -cp .;org.example.jar mysource.java | |||
</pre> | |||
After this, you obtain the bytecode file mysource.class | |||
==Run== | |||
Now run the bytecode file: | |||
<pre> | |||
java -cp '.:org.example.jar' mysource | |||
</pre> | |||
<pre> | |||
java -cp .;org.example.jar mysource | |||
</pre> | |||
Revision as of 21:57, 14 September 2016
Cool: http://www.ibm.com/developerworks/library/j-robots/index.html
Getting Started
Download and install Java, if you need to.
Hello World
This will walk through compiling and running a "Hello world" example in Java.
The program
Here's a simple Java "Hello world" program:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
Compiling
To compile this program, use the javac command:
$ javac HelloWorld.java
This will create a HelloWorld.class file, which is the Java executable.
Running
To run a Java executable, use the java command, and pass it the executable's filename without the extension:
$ java HelloWorld Hello, world!
Using Jar Files
If you have a jar file that contains class definitions and you wish to use it, you can do the following:
- To check contents of the jar, use the jar utility - it works a lot like tar
- jar xf - expands (shows contents of) jar
Compile
To compile code mysource.java with a jar file called org.example.jar:
On Linux/Mac:
javac -cp '.:org.example.jar' mysource.java
On Windows:
javac -cp .;org.example.jar mysource.java
After this, you obtain the bytecode file mysource.class
Run
Now run the bytecode file:
java -cp '.:org.example.jar' mysource
java -cp .;org.example.jar mysource
Libraries
awesome-java repo on github [1]
immutables in Java (similar notation to javascript/d3) [2]
libgdx for 3d games in Java [3]
- 3d graphics: https://github.com/libgdx/libgdx/wiki/3D-Graphics
stanford core NLP in java [4]
legion of the bouncy castle [5]
- lightweight crypto API in Java
apache shiro for session management (large enterprise or small mobile) [6]
selenium web browser test suite [7]
jsoup crawler and html parser [8]
crawler4j another crawler and html parser [9]