Java: Difference between revisions

From 太極
Jump to navigation Jump to search
Line 8: Line 8:
* [http://www.bioinformatics.babraham.ac.uk/projects/fastqc/ FastQC] The code uses Java 2D graphics APIs in awt like BasicStroke, Color, Dimension, Graphics, Graphics2D, RenderingHints and javax.swing.JPanel. It also uses java.util.Vector.
* [http://www.bioinformatics.babraham.ac.uk/projects/fastqc/ FastQC] The code uses Java 2D graphics APIs in awt like BasicStroke, Color, Dimension, Graphics, Graphics2D, RenderingHints and javax.swing.JPanel. It also uses java.util.Vector.


= Tutorial =
= Tutorial/Books =
* [http://docs.oracle.com/javase/tutorial/ Oracle Tutorial]
* [http://docs.oracle.com/javase/tutorial/ Oracle Tutorial]
* [http://www.headfirstlabs.com/books/hfjava/ Head First Java]
* [http://www.headfirstlabs.com/books/hfjava/ Head First Java]
* [http://www.murach.com/books/javp/index.htm Murach's Java Programming]
* [http://programmingbydoing.com/ Programming by Doing]
* [http://programmingbydoing.com/ Programming by Doing]
* [http://introcs.cs.princeton.edu/java/home/ Introduction to programming in Java]
* [http://introcs.cs.princeton.edu/java/home/ Introduction to programming in Java]

Revision as of 16:16, 1 June 2014

Install openjdk

See http://openjdk.java.net/install/. On Ubuntu, I can use

sudo apt-get install openjdk-7-jdk

Some projects written in Java

  • FastQC The code uses Java 2D graphics APIs in awt like BasicStroke, Color, Dimension, Graphics, Graphics2D, RenderingHints and javax.swing.JPanel. It also uses java.util.Vector.

Tutorial/Books

Compile a simple Java program

javac Example.java # generate Example.class; bytecode version of the program
java Example   # run bytecode in Java Virtual Machine

Get a hello world program from http://docs.oracle.com/javase/tutorial/getStarted/cupojava/unix.html.

Swing

Hello World Example

For example, create a new subdirectory 'start' and put HelloWorldSwing.java there. Then we can build and run the swing program by

javac start/HelloWorldSwing.java # Or javac HelloWorldSwing.java if we are in start directory
java start.HelloWorldSwing

Quit Button Example

Note that it is necessary to create the directory com/zetcode according to package statement in java code. Also the filename must be consistent with the class name.

mkdir com
mkdir com/zetcode
nano com/zetcode/QuitButtonExample.java
javac com/zetcode/QuitButtonExample.java
java com/zetcode/QuitButtonExample