1. Home
  2. Computing & Technology
  3. Linux
7.2 Simple Programming under Linux
Learn advanced Linux commands
 
 Related Resources
• Linux Newbie Administrator Guide
• 0. Linux Benefit
• 1. Before Installation
• 2. Linux Resources/Help
• 3. Basic Operations FAQ
• 4. Newbie Admin FAQ
• ~ 4.1 Lilo
• ~ 4.2 Drives
• ~ 4.3 X-Windows
• ~ 4.4 Configurations
• ~ 4.5 Networking
5. Shortcuts / Commands
• 6. Linux Applications
• 7. Learn Linux Commands
• A. How to Upgrade Kernel?
 

javac
java

The Java language compiler and interpreter. Under Linux, both javac and java are actually scripts which call kaffe with appropriate options (try cat /usr/bin/java).

A trivial example for a java "standalone" program. I use my favourite text editor, e.g. kate (in X terminal) to type in the following java code:
/* Comments are marked like in C++
 * A java class to display "Hello World"
 */
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World."); // Print "Hello World." followed by a newline
    }
}
I save this into a file named try_java.java. Now, I can compile it using:

javac try_java.java
This creates a file called HelloWorldApp.class which contains the "bytecode" (semi-compiled code which requires an interpreter to run). I can run it on the command line using:

java HelloWorldApp
For an example on how to embed a simple java applet into an html web page, have a look at http://java.sun.com/docs/books/tutorial/getStarted/cupojava/unix.html from which my java "standalone" program was borrowed
.

Next > Back to "Learn Linux Commands"

Can't find what you are looking for?
Search the

Stay up-to-date!
Subscribe to the Linux free newsletter.

Explore Linux
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Linux

©2009 About.com, a part of The New York Times Company.

All rights reserved.