Dru Lee Parsec
06-12-2002, 05:42 PM
Sections:
1. What is Java?
2. What makes Java so cool?
3. Where can I get Java?
4. How do I set up Java on my computer?
5. Where can I learn more about Java?
1. What is Java?
Java is a computer language developed by Sun Microsystems and it's spinoff company JavaSoft. It is similar to C++ in many ways, however, many people think that Java is easier to understand and to learn than C++.
2. What makes Java so cool?
Well, there are many things that makes Java a cool language to write code in. But the primary reason is something called "WORA" or Write Once Run Anywhere.
WORA allows you to write a program that will run (without re-compiling) on a Linux computer, a Windows 95, 98 NT or 2000 computer, a Mac, or a computer with Sun OS.
How does it do that you may ask?
As we all know, computers run on ones and zeros. The problem is that the set of ones and zeros that means "Add the numbers 4 and 5" on a PC might mean "Print the letter 'Z'" on a Mac. (It doesn't but this is just a hypothetical example). In any case, programs written on one platform won't run on a different platform.
The problem gets worse when you consider the problem of GUI (Graphical User Interface) programming. The Windows GUI library, MFC (Microsoft Foundation Classes) is not supported on any other platform. So any program that uses dialog boxes, windows, buttons, checkboxes, or any of the other gui components we're use to seeing in our software will work only on the platform for which it was written (until now).
Java has a set of gui components, called "Swing", that is core to the language. That's right, the entire gui library is part of the core language. This means you can write programs with a gui that will run on any platform that supports Java.
"OK, That's great!" you say, "But how can Java possibly work on all these different platforms?"
Java source code is written as ASCII text and saved as a .java file. When you run the compiler ( javac ) on a .java file you get one or more .class files.
Normally, a compiler would compile into machine language that is specific to a particular computer platform. But with Java it compiles as far as it can without having to know what kind of computer it's going to run on.
When you run a java program you run it inside a Java Virtual Machine (JVM). This Java Virtual machine knows how to take the .class files and make them run on a particular computer platform. In other workds, there is a JVM for Windows, a different JVM for Linux, a different JVM for Mac OS, and so on.
By installing the correct JVM for your computer you can run any Java program that was properly compiled to a .class file.
3. Where can I get Java?
The Java Development Kit (JDK) also known as the Software Development Kit (SDK) is availble for free here http://java.sun.com/j2se/1.4/download.html
Be sure to download the SDK if you want to write and compile Java programs. The Java Runtime Environment (JRE) only allows you to run Java programs, not to compile them.
4. How do I set up Java on my computer?
Here's how "I" do it. Your mileage may vary.
In Windows I just install the JDK to the C drive and it creates a C:\JDK1.4.1 directory (You directory may change as new versions of the SDK are released.
On Linux I install it to /usr/share/JDK1.4.1. Just make sure that you chmod the directories so your users will have access to the developer tools. On Linux I make the group for the entire Java directory structure "Java" I then make my users members of the "Java" group.
Follow the installation instructions for the version of Java which you downloaded (i.e. Windows or Linux)
You will now have a new directory called jdk1.4.1. Under that is a directory called bin. Put this directory in your path.
You should also create a new environment variable called JAVA_HOME that points to your main installation directory.
In Windows 95/98 you would put a line like this in your autoexec.bat file
set JAVA_HOME=C:\JDK1.4.1
In Windows NT/2000 you would right click "My Computer" and select "Properties". Then select "Advanced" and "Environment Variables" and create a new enviroment variable.
In Linux you would add this line to your .bash_profile file.
export JAVA_HOME=/usr/share/JDK1.4.1
You'll add one more environment variable in a minute, but this will be fine for now.
Close your editor and type ENV to see if the JAVA_HOME and new Path has taken effect (if you're in a gui like KDE or GNOME you may have to close and restart your terminal window for these changes to take effect)
Lets test it. Type the word "java" (without the quotes) in a terminal window and see if you get something like this:
Usage: java [-options] class [args...]
and so on.
If you get the message
java:command not found
then your path is not correct. Essentially the java and javac programs are in that bin directory and you want to get access to them.
The JAVA_HOME environment variable is used by other programs that need to know where your jdk is (like Star Office for example).
There is one more change you'll need to make. For Java to work it needs to know where the class files are for any program that you're writing.
For our example lets make a directory called myjava. Do this by typing:
mkdir myjava
This is where our example programs are going to be. Now we need to tell Java where our programs will be by adding the following line to autoexec.bat or your My Computer properties dialog or .bash_profile file in exactly the same way we added the JAVA_HOME and PATH lines earlier.
export CLASSPATH=.:C:/myjava
In both Windows and Linux you will have to close and reopen your MSDos window or terminal windows for these changes to take effect.
Also, in Linux you will have to type
source ~/.bash_profile
to make it re-read that file to see the changes you made.
Let's test it! Let's write a "Hello World" program in Java and make it work.
Go to your myjava directory and write the following program saving it as Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Be sure that the name of the class and the filename are exactly the same (including capitalization). In other words if you write a class called DoThisWeirdThing it MUST be saved in a file called DoThisWeirdThing.java Back at your command line type:
javac Hello.java
If you typed everything correctly you'll get a prompt again. Type "ls" in Linux or "dir" in Windows to see the contents of your directory and you should see a Hello.class file. At your command line type:
java Hello
and you should see the words "Hello World" print out.
If you can make this work then you've got Java installed properly. (That wasn't too hard was it?)
5. Where can I learn more about Java.
I suggest you download the free HTML documentation from www.javasoft.com. It has the entire language referenced via an easy to use browser interface. I always keep this file up in a browser while I program as a quick reference.
I'd also like to suggest the book "Thinking In Java" by Bruce Eckel. I like this book for 2 reasons: One, it's pretty much the best Java book I've found and Two, the entire book is available for free online at www.bruceeckel.com (Although it would be cheaper to buy it than to use up an entire laser printer cartridge printing it out).
All the source code examples in Bruce's book are also available at his web site.
Another good source of Java knowledge is the Java Developers Connection (JDC) which is a free forum that you can join at www.javasoft.com. There are quite a few Java programmers online that can answer your questions.
I hope this helps you install Java on your computer.
Good Luck!
Dru Lee Parsec
1. What is Java?
2. What makes Java so cool?
3. Where can I get Java?
4. How do I set up Java on my computer?
5. Where can I learn more about Java?
1. What is Java?
Java is a computer language developed by Sun Microsystems and it's spinoff company JavaSoft. It is similar to C++ in many ways, however, many people think that Java is easier to understand and to learn than C++.
2. What makes Java so cool?
Well, there are many things that makes Java a cool language to write code in. But the primary reason is something called "WORA" or Write Once Run Anywhere.
WORA allows you to write a program that will run (without re-compiling) on a Linux computer, a Windows 95, 98 NT or 2000 computer, a Mac, or a computer with Sun OS.
How does it do that you may ask?
As we all know, computers run on ones and zeros. The problem is that the set of ones and zeros that means "Add the numbers 4 and 5" on a PC might mean "Print the letter 'Z'" on a Mac. (It doesn't but this is just a hypothetical example). In any case, programs written on one platform won't run on a different platform.
The problem gets worse when you consider the problem of GUI (Graphical User Interface) programming. The Windows GUI library, MFC (Microsoft Foundation Classes) is not supported on any other platform. So any program that uses dialog boxes, windows, buttons, checkboxes, or any of the other gui components we're use to seeing in our software will work only on the platform for which it was written (until now).
Java has a set of gui components, called "Swing", that is core to the language. That's right, the entire gui library is part of the core language. This means you can write programs with a gui that will run on any platform that supports Java.
"OK, That's great!" you say, "But how can Java possibly work on all these different platforms?"
Java source code is written as ASCII text and saved as a .java file. When you run the compiler ( javac ) on a .java file you get one or more .class files.
Normally, a compiler would compile into machine language that is specific to a particular computer platform. But with Java it compiles as far as it can without having to know what kind of computer it's going to run on.
When you run a java program you run it inside a Java Virtual Machine (JVM). This Java Virtual machine knows how to take the .class files and make them run on a particular computer platform. In other workds, there is a JVM for Windows, a different JVM for Linux, a different JVM for Mac OS, and so on.
By installing the correct JVM for your computer you can run any Java program that was properly compiled to a .class file.
3. Where can I get Java?
The Java Development Kit (JDK) also known as the Software Development Kit (SDK) is availble for free here http://java.sun.com/j2se/1.4/download.html
Be sure to download the SDK if you want to write and compile Java programs. The Java Runtime Environment (JRE) only allows you to run Java programs, not to compile them.
4. How do I set up Java on my computer?
Here's how "I" do it. Your mileage may vary.
In Windows I just install the JDK to the C drive and it creates a C:\JDK1.4.1 directory (You directory may change as new versions of the SDK are released.
On Linux I install it to /usr/share/JDK1.4.1. Just make sure that you chmod the directories so your users will have access to the developer tools. On Linux I make the group for the entire Java directory structure "Java" I then make my users members of the "Java" group.
Follow the installation instructions for the version of Java which you downloaded (i.e. Windows or Linux)
You will now have a new directory called jdk1.4.1. Under that is a directory called bin. Put this directory in your path.
You should also create a new environment variable called JAVA_HOME that points to your main installation directory.
In Windows 95/98 you would put a line like this in your autoexec.bat file
set JAVA_HOME=C:\JDK1.4.1
In Windows NT/2000 you would right click "My Computer" and select "Properties". Then select "Advanced" and "Environment Variables" and create a new enviroment variable.
In Linux you would add this line to your .bash_profile file.
export JAVA_HOME=/usr/share/JDK1.4.1
You'll add one more environment variable in a minute, but this will be fine for now.
Close your editor and type ENV to see if the JAVA_HOME and new Path has taken effect (if you're in a gui like KDE or GNOME you may have to close and restart your terminal window for these changes to take effect)
Lets test it. Type the word "java" (without the quotes) in a terminal window and see if you get something like this:
Usage: java [-options] class [args...]
and so on.
If you get the message
java:command not found
then your path is not correct. Essentially the java and javac programs are in that bin directory and you want to get access to them.
The JAVA_HOME environment variable is used by other programs that need to know where your jdk is (like Star Office for example).
There is one more change you'll need to make. For Java to work it needs to know where the class files are for any program that you're writing.
For our example lets make a directory called myjava. Do this by typing:
mkdir myjava
This is where our example programs are going to be. Now we need to tell Java where our programs will be by adding the following line to autoexec.bat or your My Computer properties dialog or .bash_profile file in exactly the same way we added the JAVA_HOME and PATH lines earlier.
export CLASSPATH=.:C:/myjava
In both Windows and Linux you will have to close and reopen your MSDos window or terminal windows for these changes to take effect.
Also, in Linux you will have to type
source ~/.bash_profile
to make it re-read that file to see the changes you made.
Let's test it! Let's write a "Hello World" program in Java and make it work.
Go to your myjava directory and write the following program saving it as Hello.java
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Be sure that the name of the class and the filename are exactly the same (including capitalization). In other words if you write a class called DoThisWeirdThing it MUST be saved in a file called DoThisWeirdThing.java Back at your command line type:
javac Hello.java
If you typed everything correctly you'll get a prompt again. Type "ls" in Linux or "dir" in Windows to see the contents of your directory and you should see a Hello.class file. At your command line type:
java Hello
and you should see the words "Hello World" print out.
If you can make this work then you've got Java installed properly. (That wasn't too hard was it?)
5. Where can I learn more about Java.
I suggest you download the free HTML documentation from www.javasoft.com. It has the entire language referenced via an easy to use browser interface. I always keep this file up in a browser while I program as a quick reference.
I'd also like to suggest the book "Thinking In Java" by Bruce Eckel. I like this book for 2 reasons: One, it's pretty much the best Java book I've found and Two, the entire book is available for free online at www.bruceeckel.com (Although it would be cheaper to buy it than to use up an entire laser printer cartridge printing it out).
All the source code examples in Bruce's book are also available at his web site.
Another good source of Java knowledge is the Java Developers Connection (JDC) which is a free forum that you can join at www.javasoft.com. There are quite a few Java programmers online that can answer your questions.
I hope this helps you install Java on your computer.
Good Luck!
Dru Lee Parsec