Java source files must end in .java and the compiled files must end in .class. Therefore, the new universal language can not be used with MS DOS which allows only 3-letter filename extensions.
Java is case sensitive. Even the case of the letters in the filename must match the name of the primary class (i.e. this is a pain in the ...). Uh, running jdk 1.1 in a DOS window under Windows 98, the case of the filename and the class name do not have to match. I guess that some standards aren't.
C & C++ programs are normally compiled into an executable that runs without any additional support. (Microsoft Visual C++ is an exception - it requires a run-time dll, and perhaps a foundation class dll. For more info, see DLL Hell.)
Java improves (not) this by pseudo compiling into a p-code which is interpreted by the run-time environment. Since there are several versions of the run-time, you must provide a way for your client to download the correct version. However, there are several bug fixes to each version. Therefore, if you cause the user's system to get the latest version, you could be responsible for breaking other programs that used to run perfectly.
Unfortunately, there is no way to be sure which versions of these dll's are available on a given machine. As a result, you should expect your programs to fail on any machine except the one they are developed on.
To make matters worse (monopolies sometimes do this), Microsoft provides java run-times which are different than the Sun standard. (This significantly improves the odds that your java code will not run on your client's machine.)
There's more - with unix systems, software is normally distributed as C source files, perl scripts, shell scripts, and other user readable code. Then, it is up to the user (system administrator) to compile the code and install the executables. Well, many companies don't like to let users see their source code. Java to the rescue! Because java converts human readable source code into p-code, this gives companies a way to distribute machine independent source which users can not read. Then, instead of running fast compiled code, each system has an interpreter that slowly "executes" the p-code.
Java Versions | There are several versions of Java -
some add new features, but other fix problems.
|
Client Side Java - Don't use it | Additional notes in my HTML guide
|
Page Layout | How to control where GUI objects appear on the screen
|
JavaBeans |
.java Files
A basic java application requires
class SameAsFilename { public static void main (string[] arguments) { } }
When you execute a program, the java run-time starts execution by calling the main subroutine inside the class which has the exact same name as the .class file. Even the case of the letters must match. Arguments can be added to the command-line.
Java programs run via the Internet (i.e. in a browser) are called applets. Being a standard language, the basic applet structure is completely different than the application structure.
import java.awt.*; public class SameAsFilename extends java.applet.Applet { public void init() { String param; param = getParameter("ParamName"); } public void paint(Graphics g) // could also use - (java.awt.Graphics g) { // This is where you display some output g.drawString("Some stupid string", 5, 20); } }In this case, the java applet run-time starts execution by calling the init subroutine. Applet parameters are made available using an entirely different syntax from application command-line parameters.
Applets are called via html using code similar to
public void paint( Graphics g ){ g.setColor(Color.red ); g.drawString("Some String", xValue, yValue); }
Misc
Java does not use C/C++ type header files.
Run-Time Design Errors
public int compareTo(Date anotherDate)However, this code works fine.
public boolean equals(Object obj)
The jdk 1.1 java disassembler requires the name of the class file but without the file extenstion. (It took almost 2 hours to figure out this un-documented feature.)
Character-based output
System.out.print("Some String" + AnyVariable); // Applications only System.out.println("Some String" + AnyVariable); // Applications only
Actually, there are a number of errors in the book ... so be careful.
The partially correct anwser is given as no. While technically correct, the better answer is to use print instead of println.
What the book actually says is "Java automatically starts each System.out.println() statement on its own new line, the only way to prevent this ..." which is not correct.
He says no. On page 92 (Chapter 7), this is strongly repeated.
Well, I wrote a program and compiled it with the Java 1.1 that came with the book. The double equals works perfectly.
There are numerous examples in Chapter 7 that use "==" and "!=" with strings.
Actually, the single quote by itself works just fine in a DOS window.