Java on Linux

L

Lesley

Hi

Last time I did any Java programming was on a Windows machine in
2000/2001.

I have no clue how to install Java on a Linux box but I'd like to be
able to use Java again. Mostly because I am teaching somebody how to
program and, for particular reasons, we are using Java.

He has a Windows box but I do not want to wreck the Linux install on
my laptop.
It would be convenient to use the laptop to work out a syllabus and
work out some examples. I have Blackdown Java installed on the laptop
and I have a vague idea that this is related to the Sun Java stuff but
:-

1. I don't know how to work out if I have the SDK installed or not.
2. I don't know what the relationship between Blackdown and the Sun
Java is. I want to avoid conflicts in example programs.
3. There used to be a path one had to set to the path of the class
libraries installed on the machine. How is this managed in Linux?
Through the PATH environment variable?
4. Have there been any *huge* changes in the language since 2K? I'm
using books I bought then.

TIA for any answers, hints tips etc

Regards
LesleyB
 
J

John C. Bollinger

Lesley said:
Last time I did any Java programming was on a Windows machine in
2000/2001.

I have no clue how to install Java on a Linux box but I'd like to be
able to use Java again. Mostly because I am teaching somebody how to
program and, for particular reasons, we are using Java.

You could try downloading the Sun-supported Linux install package (from
Sun, of course) and using it. Check whether its compatible with your
Linux distribution. You might also want to check out the Java Packaging
Project, but that might be more than you need.
He has a Windows box but I do not want to wreck the Linux install on
my laptop.
It would be convenient to use the laptop to work out a syllabus and
work out some examples. I have Blackdown Java installed on the laptop
and I have a vague idea that this is related to the Sun Java stuff but
:-
1. I don't know how to work out if I have the SDK installed or not.

You could look for the Java compiler (javac) on your laptop. Try
"find / -name javac -print". It will probably take a while to run, but
it will display the name and location of any file of the specified name
that it finds.
2. I don't know what the relationship between Blackdown and the Sun
Java is. I want to avoid conflicts in example programs.

If your only talking about tutorial-type example programs then you are
unlikely to run into any problems of consequence. Certainly the Java
language, the Java virtual machine, and the standard Java class library
have never been open to incompatible reimplementation under the terms of
any Java license I am aware of Sun ever issuing.
3. There used to be a path one had to set to the path of the class
libraries installed on the machine. How is this managed in Linux?
Through the PATH environment variable?

You are thinking of the classpath. It works under Linux just the same
as under windows: you specify the CLASSPATH environment variable and /
or specify the path on the java or javac command line via the
appropriate switch. It has not for a long time been necessary to put
the standard class libraries in your classpath, however -- only user
classes.
4. Have there been any *huge* changes in the language since 2K? I'm
using books I bought then.

Depends what you mean. In the simplest terms, yes, there have been huge
changes. On the other hand, it is unlikely that much valid Java source
written even to Java 1.1 would fail to still be valid Java source.
Class files compiled four years ago ought still to run on today's newest
Java VMs. But there have been a great many additions to the standard
class libraries, and in the most recent Java release (1.5.0, a few weeks
ago) there are several very significant additions to the Java language
itself.

Have you considered that attempting to teach programming via a language
that you're not current with might be an unnecessarily difficult
challenge? And that the student might be better served by instruction
in a language that the instructor is fluent in?


John Bollinger
(e-mail address removed)
 
O

Oscar kind

Lesley said:
I have no clue how to install Java on a Linux box [...]

The correct procedure depends on your distribution.

If it is RedHat or another distribution that uses rpm (or can handle it
using alien), you want to download the rpm file from sun (same URL as for
Windows: http://java.sun.com/). The procedure is as follows:
1. Make the file executable.
2. Run the file; it creates an rpm file.
3. As root, install the rpm file in the usual manner.

If your distribution is something else, use the generic Linux
distribution. This requires a bit more work though:
1. Make the file executable.
2. Run the file; it unpacks into a subdirectory.
3. As root, move the newly created subdirectory to a convenient place,
such as /usr/local .
4. As root, change the ownership to root.root .
5. As root, add JAVA_HOME to /etc/profile (adjust the path correctly):
export JAVA_HOME=/dir/to/java
The next part is subjective, but I'd do it thus:
6. As root, link the binaries to /usr/local/bin to make them generally
available: ln -s ${JAVA_HOME}/bin/* /usr/local/bin/
7. As root, link the manual pages to /usr/local/man/man1 to make them
generally available: ln -s ${JAVA_HOME}/man/man1/* /usr/local/man/man1/
8. Reload your environment, and you're set.
 
S

Steve Horsley

Lesley said:
1. I don't know how to work out if I have the SDK installed or not.
I would probably do $ find / -name javac
2. I don't know what the relationship between Blackdown and the Sun
Java is. I want to avoid conflicts in example programs.
Can't help there - I've not used Blackdown.
3. There used to be a path one had to set to the path of the class
libraries installed on the machine. How is this managed in Linux?
Through the PATH environment variable?

I have never set the classpath, and never felt a need.
I suggest that you remove any classpath settings.

For setting your path though, see below.
4. Have there been any *huge* changes in the language since 2K? I'm
using books I bought then.

Yes. 1.5 introduced generics and some other syntax additions.
TIA for any answers, hints tips etc
The Sun JDK for Linux comes as a self-extracting binary, that produces
a tarball or an RPM (you choose which to download). This installs the
files, but not the shell path. I suggest you add this file, to get
java placed in your path:

/etc/profile.d/java.sh:

if [ -z "$JAVA_HOME" ]; then
export JAVA_HOME=/usr/java/jdk1.5.0
export PATH="$PATH:$JAVA_HOME/bin"
fi

Steve
 
M

Michael Borgwardt

John said:
You are thinking of the classpath. It works under Linux just the same
as under windows: you specify the CLASSPATH environment variable and /
or specify the path on the java or javac command line via the
appropriate switch. It has not for a long time been necessary to put
the standard class libraries in your classpath, however -- only user
classes.

Actually, it has been for a long time considered best practice to leave
the CLASSPATH environment variable empty and specify the classpath
on the command line.
 
J

John C. Bollinger

Michael said:
Actually, it has been for a long time considered best practice to leave
the CLASSPATH environment variable empty and specify the classpath
on the command line.

You are quite right, but I said nothing to the contrary. I'm sure in
any case that the OP appreciates your effort to guide her more
specifically toward the currently accepted best practices.


John Bollinger
(e-mail address removed)
 
L

Lesley

John C. Bollinger said:
You could try downloading the Sun-supported Linux install package (from
Sun, of course) and using it. Check whether its compatible with your
Linux distribution. You might also want to check out the Java Packaging
Project, but that might be more than you need.

Had a quick look at all the differnt downloads on Sun and have
selected the SDK with NetBeans in it. One for Linux and one for my XP
install.
You could look for the Java compiler (javac) on your laptop. Try
"find / -name javac -print". It will probably take a while to run, but
it will display the name and location of any file of the specified name
that it finds.
Did all that, and reran my installation disks selecting Java. There
seems to be a GNU Java around on my system accessible via gcj command.
However I've attempted the myframe.call from Just Java by Peter van
Linden (4th edition) using 'gcj myframe.class' and got undefined
reference to 'main'.
If your only talking about tutorial-type example programs then you are
unlikely to run into any problems of consequence. Certainly the Java
language, the Java virtual machine, and the standard Java class library
have never been open to incompatible reimplementation under the terms of
any Java license I am aware of Sun ever issuing.

Glad to hear that.
You are thinking of the classpath. It works under Linux just the same
as under windows: you specify the CLASSPATH environment variable and /
or specify the path on the java or javac command line via the
appropriate switch. It has not for a long time been necessary to put
the standard class libraries in your classpath, however -- only user
classes.
TYVM.

Depends what you mean. In the simplest terms, yes, there have been huge
changes. On the other hand, it is unlikely that much valid Java source
written even to Java 1.1 would fail to still be valid Java source.
Class files compiled four years ago ought still to run on today's newest
Java VMs. But there have been a great many additions to the standard
class libraries, and in the most recent Java release (1.5.0, a few weeks
ago) there are several very significant additions to the Java language
itself.

Have you considered that attempting to teach programming via a language
that you're not current with might be an unnecessarily difficult
challenge? And that the student might be better served by instruction
in a language that the instructor is fluent in?

Yes, very much so. But he hasn't found anyone else at the Uni yet
who'll give him one-to-one tutorials. I am aware of both the stress
factor for me *and* the issue of quality of instruction. He's a
Masters degree student at a local University. Part of his problem is
that he has absolutely *no* programming experience and I can certainly
help out there. I am aware one of my weak points is lack of
knowledge of the classes available in Java. The University provides
him with a set of simple i/o classes (keybd input, graphic output,
etc) they have built and at some point I will be getting him to make a
copy of that package, analyse it, improve it and build upon it.

The side effect for me is I get to focus on two things : how to teach
someone something (in this case programming, plus OOP plus some Java)
and revisiting Java itself. I might not be the best Java teacher in
the world, yet ;) *but* I have already improved his knowledge with
something as simple as pre and post decrement operators, discussing
the side effect and the speed fo each.

There are the issues about the concept of static, getting across the
issues of encapsulation and why there are private, public and
protected methods and fields in a class. My biggest issue is to build
a coherent set of examples that he will benefit from and I am looking
at it from the old fashioned view point that most (useful) programs
have data input, data output and some processing in between. So I want
to build his i/o skills to include file i/o for example. (One thing
not covered in his University package). Another issue is getting him
to do the homework too. I have to keep telling him he can't learn to
program just by reading the books, he actually has to do it too. So
what I have to find is a project that will motivate him and help him
learn to design programs using Java. etc etc etc

Thanks for your input

Lesley
 
M

Morten Alver

2. I don't know what the relationship between Blackdown and the Sun
Java is. I want to avoid conflicts in example programs.

I've used the Sun, Blackdown and IBM Java distributions on linux, and
not had any compatibility problems between them.

I believe as good as all Linux distributions provide an easy way to
install Java through their standard package management systems. You'd
have to say which distribution you are using to get more specific info
on this.
 
L

Lesley

Oscar kind said:
Lesley said:
I have no clue how to install Java on a Linux box [...]

The correct procedure depends on your distribution.

If it is RedHat or another distribution that uses rpm (or can handle it
using alien), you want to download the rpm file from sun (same URL as for
Windows: http://java.sun.com/). The procedure is as follows:
1. Make the file executable.
2. Run the file; it creates an rpm file.
3. As root, install the rpm file in the usual manner.

If your distribution is something else, use the generic Linux
distribution. This requires a bit more work though:
1. Make the file executable.
2. Run the file; it unpacks into a subdirectory.
3. As root, move the newly created subdirectory to a convenient place,
such as /usr/local .
4. As root, change the ownership to root.root .
5. As root, add JAVA_HOME to /etc/profile (adjust the path correctly):
export JAVA_HOME=/dir/to/java
The next part is subjective, but I'd do it thus:
6. As root, link the binaries to /usr/local/bin to make them generally
available: ln -s ${JAVA_HOME}/bin/* /usr/local/bin/
7. As root, link the manual pages to /usr/local/man/man1 to make them
generally available: ln -s ${JAVA_HOME}/man/man1/* /usr/local/man/man1/
8. Reload your environment, and you're set.

Sorry for the delay in replying but thank you very much for these
details.
I have SuSE 8.3 on a laptop and am currently running XP on my Athlon
box. The Athlon had a few problems when I tried to install Linux on
it last year but that was v2.4.10 of the kernel. When I tried to
connect the laptop up to the Celeron box I also have something went
wrong with the NIC on the Celeron, which had previously thrown a fault
after an online update. (SuSE again).

I have tried installing Java from the 8.3 distro disks but do not get
the javac compiler at all, just the GNU one. I now need to remove all
the existing Java and install what I want outside the normal SuSE
remit.

Interestingly I installed Debian woodyr2 on the Celron box and the
ethernet card came back up but I am suspecting my 5-6 year old
faithful workhorse is on it's last legs.

Anyhow I've downloaded both the Windows and Linux versions of Java 2
SDK 1.4.2-04 with NetBeans and I'll see how that goes. Selecting the
right package isn't easy and I noted there's a number of different
packages, JS2E has a version 5.0 and a 1.4.2 with Sun being remarkably
forthright about what these version numbers refer to on this page
http://java.sun.com/j2se/ . And of course v 5,0 is really v 1.5.0
which presumably is in beta?

Once again many thanks for your help

Regards

Lesley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top