Getting Started with Java on Linux
You should now have a working Java development environment. To test this, we will try to compile and run a simple Java class. Enter the following code into a file named Test.java:
import java.lang.reflect.Array;
class Test
{
public static void main( String argv[] )
{
System.out.println( "Arguments:" );
int i = 0;
while( i < Array.getLength(argv) )
{
System.out.println( argv[i] );
i++;
}
}
}
Then, try to compile it with the following command:
root@localhost:~# javac Test.java
And finally, execute your class by issuing this command:
root@localhost:~# java Test argument1 argument2 argument3 Arguments: argument1 argument2 argument3
As you see, this simple program prints the command-line arguments given and then exits. If this worked, it's safe to say your installation was successful.
Resin (from Caucho Technology) is a web and application server that's fast and easy to get running. We'll begin by downloading and unpacking the Resin source distribution. This can be found at www.caucho.com/download/index.xtp. At the time of this writing, the latest version of Resin standard is 2.1.4 (there's an enterprise version too, but you don't have to worry about that for now).
When the file is on your local machine, unpack it in /usr/local:
root@localhost:~# resin-2.1.4.tar.gz /usr/local root@localhost:~# cd /usr/local root@localhost:/usr/local# tar xvfz resin-2.1.4.tar.gz
As with the JDK, it would be nice to make a symbolic link for Resin so you always are able to access it in /usr/local/resin:
root@localhost:/usr/local# ln -s resin-2.1.4 resin
Because we're going to run Resin as a standalone web server, we need to change the port on which the server will listen before we start it. This can be done by changing a line in /usr/local/resin/conf/resin.conf. Open resin.conf in an editor and locate the following line:
<http port='8080'/>
A common way of using Resin is to let it coexist with Apache, letting Resin take care of only the requests to JSP/Servlets and leaving the rest up to Apache. This is why Resin by default listens to port 8080 instead of 80, which is the standard port for web servers. We are going to let Resin take care of all requests to our server (for which it is very capable). So, change the HTTP port in resinf.conf to 80, save and exit. Then, start Resin by executing the following:
root@localhost:~# /usr/local/resin/bin/httpd.sh
You should get output the looks something like this:
Resin 2.1.4 (built Fri Aug 2 14:16:52 PDT 2002) Copyright(c) 1998-2002 Caucho Technology. All rights reserved. Starting Resin on Tue, 20 Aug 2002 14:02:27 +0200 (CET) [2002-08-20 14:02:29.982] initializing application http://localhost/ [2002-08-20 14:02:29.984] initializing application http://localhost/java_tut [2002-08-20 14:02:29.985] initializing application http://localhost/examples/basic [2002-08-20 14:02:29.986] initializing application http://localhost/examples/tags [2002-08-20 14:02:29.987] initializing application http://localhost/examples/tictactoe [2002-08-20 14:02:29.988] initializing application http://localhost/examples/navigation [2002-08-20 14:02:29.989] initializing application http://localhost/examples/xsl [2002-08-20 14:02:29.990] initializing application http://localhost/examples/templates [2002-08-20 14:02:30.001] initializing application http://localhost/examples/login http listening to *:80 srun listening to 127.0.0.1:6802
Resin is up and running. You can test it out by pointing your browser at http://localhost. The page shown in Figure 1 is what you should see.
It also would be nice to test the server with a simple page of our own. The base document directory for Resin by default is /usr/local/resin/doc, so let's create a page called test.jsp and place it in this directory. test.jsp could look something like this:
<html>
<head>
<title>
My First JSP Page
</title>
</head>
<body bgcolor="#FFFFFF">
<h3>
The value of 'par' is:
</h3>
<h2>
<%= request.getParameter("par") %>
</h2>
</body>
</html>
This JSP prints out the value of the parameter par. So to avoid error messages, we need to define this variable in the URL when calling this page. Point your browser at http://localhost/test.jsp?par=mysecretvalue, where you should see something similar to Figure 2.
Now we're talking; looks like we've got our own Java application server working.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Dynamic DNS—an Object Lesson in Problem Solving
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Tech Tip: Really Simple HTTP Server with Python
- Roll your own dynamic dns
3 hours 51 min ago - Please correct the URL for Salt Stack's web site
7 hours 3 min ago - Android is Linux -- why no better inter-operation
9 hours 18 min ago - Connecting Android device to desktop Linux via USB
9 hours 47 min ago - Find new cell phone and tablet pc
10 hours 45 min ago - Epistle
12 hours 13 min ago - Automatically updating Guest Additions
13 hours 22 min ago - I like your topic on android
14 hours 9 min ago - This is the easiest tutorial
20 hours 44 min ago - Ahh, the Koolaid.
1 day 2 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?





Comments
Re: Getting Started with Java on Linux
i am getting such result after typing javac at home directory
kindly , give me some solution for the problem
[jdk1_3_1_12 is stored in /usr/local]
/usr/local/jdk1.3.1_12/bin/i386/native_threads/javac: error while loading shared libraries: libstdc++-libc6.1-1.so.2: cannot open shared objectfile: No such file or directory
[root@localhost home]#
may be you should store at
may be you should store at ./usr/local/jdk
I think you don't have file l
I think you don't have file libstdc....... Try to find some .rpm that contains that file. I had the same problem, but I don't remember name of the .rpm.
Re: Getting Started with Java on Linux
I really Donot know about this! sorry
Re: Getting Started with Java on Linux
me too....somebody please help..
Re: Getting Started with Java on Linux
This document has two parts. The first explains how to install just the Java software development kit. The second part explains how to install the Sun One Studio (previously known as Forte). This is how it worked for me. Any risk in using this information is yours (don't whine to me, I ain't got no money anyway).
How to install Java JDK:
1. Decide on a directory to hold the jdk folder (I used /usr/local) and change to it using:
linux:~# cd /usr/local
2. Download the "j2sdk-1_4_1_01-linux-i586.bin" from ww.java.sun.com into the current directory.
3. Change the permisions on the file using:
linux:/usr/local# chmod 755 j2sdk-1_4_1_01-linux-i586.bin
4. Run the binary:
linux:/usr/local# j2sdk-1_4_1_01-linux-i586.bin
. This will create a new subdirectory, j2sdk-1_4_1_01, and install the sdk into it after you have scrolled through the license agreement and answered "yes" to "Do you agree to the above license terms? [yes or no]"
5. Enter:
linux:/usr/local# ln -s /usr/local/j2sdk-1_4_1_01 /usr/local/jdk
This creates a symbolic link, /usr/local/jdk, to the j2sdk-1_4_1_01 directory. This way you can have the jdk directory in the path, and upgrade your versions merely by installing it to its own directory and then changing the symbolic link again.
6. Append to /etc/profile:
export PATH=$PATH:/usr/local/jdk/bin
to make sure the /usr/local/jkd/bin directory (but really the
/usr/local/j2sdk-1_4_1_01/bin directory ) is in your path.
7. Reload the /etc/profile by:
linux:~# source /etc/profile
8. Enter
linux:~# javac
to check that it is properly installed.
9. Append to /etc/profile:
export JAVA_HOME=/usr/local/jdk
to tell your system where the JDK base directory can be found.
How To Install Sun One Studio:
1. Download the "j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin" file. Make sure downloaded file is the same size as indicated on the Sun web page.
2. To change permisions run:
linux:~# chmod 777 j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin
3. Decide on a directory( eg. /usr/local).
4. Run:
linux:~# chmod 777 j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin
The installer will start up, ask if you agree to the license terms, and if you say yes, it will ask which directory to install to (I chose /usr/local/s1studio4_1_1). There is no need to be currently in that particluar directory at the time. It will create a new directory tree in /usr/local/s1studio4_1_1 with subdirectories _uninst, j2sdk1.4.1, and s1studio.
5. The installer will put focus on the finish button when it's done. When you press it, a small message box comes up saying that to start the program, you must run runide.sh in /~/s1studio/bin to start the IDE.
6. If you HAVE NOT previously installed the jdk then append to '/etc/profile':
export PATH=$PATH:/usr/local/s1studio4_1_1/j2sdk1.4.1/bin
If you HAVE previously installed the jdk but want to use the new one, then edit '/etc/profile' to remove the export PATH line that contains your old jdk or j2sdk directory and append the new export PATH command to the profile file.
7. Append the next line to /etc/profile:
export PATH=$PATH:/usr/local/s1studio4_1_1/s1studio/bin
Save profile and exit the editor.
8. Reload the /etc/profile by:
linux:~# source /etc/profile
9. The only way I figured the following out, was by reading the runide.sh file. I found no documentation, no hint or clue elsewhere.
To start the IDE, runide.sh needs to know where the jdk is. The installation leaves it no clue, so you have to pass it a command line argument as shown:
runide.sh -jdkhome /usr/local/jdk
or
runide.sh -jdkhome /usr/local/s1studio4_1_1/j2sdk1.4.1
depending on your choice in part 6.
10. The easiest way I found to get the ide to start was to right-click the mouse on the KDE panel, then click on Add in the menu that pops up. On the next sub-menu click on SpecialButton, and next on Non-KDE Application. This will bring up a file selection box. Browse until you find the runide.sh file, and click on it. This will come up with a Non-KDE Application Configuration data-entry box. In the edit field, enter: -jdkhome /usr/local/jdk. You can click on the icon now to change it, or you can change it at any later time by simply right-clicking the icon on the panel to edit the preferences.
At this point I had an icon on the panel which I could left-click on to start the IDE.
Ron Gesell
Jan 28, 2003
Re: Getting Started with Java on Linux
sorry.. just want to ask how to run java applet(yahoo chess applet) on linux(rh9)
i had already install j2sdk1.4.1.02
i follow all the step above(i manage to compile java prog)... but still can open yahoo chess applet...
what else should i install
or should i install j2re?
just begin to know linux..
I think there is an error
I think there maybe an error in the tute. Although I am a beginner, so maybe I'm mistaken
towards the top there is the command :
mv j2sdk-1_4_0_01-linux-i586.bin /usr/local
I think that this is wrong and in fact should be
mv j2sdk-1_4_0_01 /usr/local
What the point in moving the .bin ?
please correct me If Im wrong but beginners like me try to follow the commands exactly and this is confusing
2cj2
Re: I think there is an error
Yes Its me again
I believe that I was correct before. Also I need to know how to set the path name when Im not in root. These couple of points would I feel be of great benefit in what is a great tutorial !
2cj2
Not The Error!!!!!!!
Hey dude.. its not Error as we have to move .bin file to /usr/local directory... Its the name of that package for Linux so its same if write jdk_1_4_0 or jdk_...bin ok by by... Correct me if I'm wrong anyway...
Re: Getting Started with Java on Linux
Nice Java Intro.
But -- Resin is not an application server, Resin is a servlet-engine. And -- Linux being open source and all, why not choose an open source appserver for the example? JBoss or Jonas anyone?
Re: Getting Started with Java on Linux
Why use reflection to get the length of an array?
Every array instance has a member .length ....
Re: Getting Started with Java on Linux
yeah, funny. maybe he likes reflecting
this works just as well....
class Test
{
public static void main( String argv[] )
{
System.out.println( "Arguments:" );
int i = 0;
while( i < argv.length )
{
System.out.println( argv[i] );
i++;
}
}
}
Re: Getting Started with Java on Linux
Haha.... Yeah, well, I'm a little mystery, I guess :)
Getting started with Tomcat instead of Resin
Just in case someone wants to try out Tomcat instead of Resin, here is a quick&dirty summary:
Download Tomcat binary from jakarta.apache.org
Unpack the binary (I unpack mine in /usr/local
Start tomcat by running /usr/local/jakarta-tomcat-4.0.4/bin/startup.sh
You may need to set the JAVA_HOME environment variable to point to your Java directory before Tomcat will start.
By default, Tomcat starts on port 8080. If you want to change it, edit the server.xml file in /usr/local/jakarta-tomcat-4.0.4/conf. (Just search for port="8080")
When you create the test JSP, put it in /usr/local/jakarta-tomcat/webapps/ROOT.
The URL should be http://localhost:8080/test.jsp?par=mysecretvalue
The Tomcat installation comes with documentation, just point your browser to http://localhost:8080 and you should get the main page for your installation, with links to the docs. If you have JDK 1.4, it is easy to enable SSL with Tomcat as well.
Re: Getting started with Tomcat instead of Resin
Currently I've got tomcat running on port 8080, but would like to be able to run it with apache on port 80. So, has anyone able to get it to work with apache? If so what kind of connector did you use and what are the steps?
Re: Getting Started with Java on Linux
Why use Resin ? Jakarta Tomcat is mature, free, and FREE product.
nedim
Re: Getting Started with Java on Linux
This document has two parts. The first explains how to install just the Java software development kit. The second part explains how to install the Sun One Studio (previously known as Forte). This is how it worked for me. Any risk in using this information is yours (don't whine to me, I ain't got no money anyway).
How to install Java JDK:
1. Decide on a directory to hold the jdk folder (I used /usr/local) and change
to it using:
linux:~# cd /usr/local
2. Download the "j2sdk-1_4_1_01-linux-i586.bin" from www.java.sun.com into the
current directory.
3. Change the permisions on the file using:
linux:/usr/local# chmod 755 j2sdk-1_4_1_01-linux-i586.bin
4. Run the binary:
linux:/usr/local# j2sdk-1_4_1_01-linux-i586.bin
. This will create a new subdirectory, j2sdk-1_4_1_01, and install the sdk
into it after you have scrolled through the license agreement and answered
"yes" to "Do you agree to the above license terms? [yes or no]"
5. Enter:
linux:/usr/local# ln -s /usr/local/j2sdk-1_4_1_01 /usr/local/jdk
This creates a symbolic link, /usr/local/jdk, to the j2sdk-1_4_1_01
directory. This way you can have the jdk directory in the path, and
upgrade your versions merely by installing it to its own directory and then
changing the symbolic link again.
6. Append to /etc/profile:
export PATH=$PATH:/usr/local/jdk/bin
to make sure the /usr/local/jkd/bin directory (but really the
/usr/local/j2sdk-1_4_1_01/bin directory ) is in your path.
7. Reload the /etc/profile by:
linux:~# source /etc/profile
8. Enter
linux:~# javac
to check that it is properly installed.
9. Append to /etc/profile:
export JAVA_HOME=/usr/local/jdk
to tell your system where the JDK base directory can be found.
How To Install Sun One Studio:
1. Download the "j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin" file. Make sure
downloaded file is the same size as indicated on the Sun web page.
2. To change permisions run:
linux:~# chmod 777 j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin
3. Decide on a directory( eg. /usr/local).
4. Run:
linux:~# chmod 777 j2sdk-1_4_1-s1studio_ce-rul-bin-linux.bin
The installer will start up, ask if you agree to the license terms, and if
you say yes, it will ask which directory to install to (I chose
/usr/local/s1studio4_1_1). There is no need to be currently in that
particluar directory at the time. It will create a new directory tree in
/usr/local/s1studio4_1_1 with subdirectories _uninst, j2sdk1.4.1, and
s1studio.
5. The installer will put focus on the finish button when it's done. When you
press it, a small message box comes up saying that to start the program, you
must run runide.sh in /~/s1studio/bin to start the IDE.
6. If you HAVE NOT previously installed the jdk then append to '/etc/profile':
export PATH=$PATH:/usr/local/s1studio4_1_1/j2sdk1.4.1/bin
If you HAVE previously installed the jdk but want to use the new one, then edit '/etc/profile' to remove the export PATH line that contains your old jdk or j2sdk directory and append the new export PATH command to the profile file.
7. Append the next line to /etc/profile:
export PATH=$PATH:/usr/local/s1studio4_1_1/s1studio/bin
Save profile and exit the editor.
8. Reload the /etc/profile by:
linux:~# source /etc/profile
9. The only way I figured the following out, was by reading the runide.sh file. I found no documentation, no hint or clue elsewhere.
To start the IDE, runide.sh needs to know where the jdk is. The installation leaves it no clue, so you have to pass it a command line argument as shown:
runide.sh -jdkhome /usr/local/jdk
or
runide.sh -jdkhome /usr/local/s1studio4_1_1/j2sdk1.4.1
depending on your choice in part 6.
10. The easiest way I found to get the ide to start was to right-click the mouse on the KDE panel, then click on Add in the menu that pops up. On the next sub-menu click on SpecialButton, and next on Non-KDE Application. This will bring up a file selection box. Browse until you find the runide.sh file, and click on it. This will come up with a Non-KDE Application Configuration data-entry box. In the edit field, enter: -jdkhome /usr/local/jdk. You can click on the icon now to change it, or you can change it at any later time by simply right-clicking the icon on the panel to edit the preferences.
At this point I had an icon on the panel which I could left-click on to start the IDE.
Ron Gesell
Jan 28, 2003
Re: Getting Started with Java on Linux
Because Tomcat is rubbish. Resin is not that expensive that the licenses price you out of running it, hell, if you're a small company and cant afford it, Caucho will let you off the hook! Go read the license terms.
Seriously, Tomcat is complete rubbish, its slow and cumbersome, and it crashes all the time. Resin is king! Long live resin!
Re: Getting Started with Java on Linux
The above is obviously a troll and should be ignored. Probably a Resin employee giving out dubious advice.
Tomcat is deployed at large companies due to its high regard by the programmers who's jobs would be affected if it wasn't stable. I'll even name one: Universal Studios. Its filling niches where traditional proprietary costs would be prohibitive or overkill.
Its solid, has open source backing (no small thing when you consider the resources this fact brings to bear), and its Free (as in Freedom, not free beer) to use as you please on as many boxen as you please.
And, one final very important point made by another poster here. When the company that makes Resin is long gone, Tomcat will still be there due to its status as an Open Source project. How's THAT for reliability.
Re: Getting Started with Java on Linux
Because Resin is much faster, it automagically reloads the web application when you change a class or the web.xml, etc.
Resin is free for development, you only have to pay a license for your deployment server.
Re: Getting Started with Java on Linux
Because
* Resin is much faster
Give them time, besides, speed isn't everything
* it automagically reloads the web application when you change a class or the web.xml, etc.
Yes, even tomcat does this
* Resin is free for development, you only have to pay a license for your deployment server.
Interestingly enough, aside from the damned sun java requirement, tomcat gives you:
- freedom to use it for whatever purpose,
- freedom to maintain it even if the vendor no longer does,
- freedom to install in as many machines with as many cpus as you wish,
- freedom to resell improved copies (or even giving them away gratis)...
With all of this and you not even have to pay for a license per machine/cpu for your deployment servers... so, tell us again, please, why should an enterprise use resin instead of tomcat?