Frequently Asked Questions about Java
Questions I've been asked about Java
1. Do I have to buy Java?
2. What is the latest version of Java?
3. What is the direct link to download Java?
4. Will Java run on a Macintosh?
5. Will Java run on my Linux PC?
6. Can I take a class on Java from you?
7. What's the best way to learn Java?
8. Is Java an easy language to learn?
9. I've heard that Java is object-oriented. What does that mean?
10. Is there a Java IDE like there is for Visual Basic?
11. In your Java Introductory book, you use Notepad to create Java source code files. Is there an easier way?
12. In your Java Introductory book you stopped short of creating an Applet--why, and where can I find this information?
13. Is Microsoft's J++ Java?
14. Is JavaScript the same as Java?
15. I've heard that C# is a replacement for Java--is that true?
16. Will a knowledge of Java get me a good job?
17. What are the System Requirements for Java?
18. Is there a Certification Exam for Java like there is for Microsoft products like VB and C++?
19. Why doesn't my "Hello World!" program compile?
20. Why doesn't my "Hello World!" program run?
21. How do I set the CLASSPATH?
22. Why do I get this compiler error: "Can't make static reference to method..."?
23. Where can I find information about Java Certification?
24. Will you be writing Java articles like you do VB6 articles?
25. I'm working on a project with lots of classes and I use the JDK. A recompile from scratch takes forever when I do it a class at a time.
How do I recompile everything?
26. What does "deprecated" mean? I got this in a compiler error message.
27. How do I compare two Strings?
28. In your book, you use the terms 'overload' and
'override'--what is the difference?
29. How do I get Java talking to a Microsoft Access
database?
30. What is a "GOTCHA"?
31. What is "Dippy Bird" and where can I get it?
32. I'm using Win95, and my DOS window won't accept filenames
longer than 8.3.
33. Despite everything I've read here, I'm still having
troubles compiling my program. Can you help me?
No, Java is free (don't be fooled into buying Microsoft's J++ which is NOT Java and which is NOT free).
You can download real Java for free from the Sun Microsystems Website, or, if you prefer to avoid a lengthy download, you can request that Sun send it to you on a CD---your cost is basically shipping. Here's the link for the CD:
http://www.sun.com/developers/tools/jumpstart.html
The latest version of Java is the Java 2 SDK (Software Development Kit) Version 1.4. You can read more about it here:
That depends on the operating system you are using.
For Windows, download the latest version of Java here:
For other operating systems, start with this page:
http://java.sun.com/j2se/1.4/download.html
Yes. The best starting point is Apple's Java specific home page at
http://developer.apple.com/java/
From there, you can find the latest
"release" version plus any early access (aka "Beta")
releases.
Yes. For a Linux version of the latest version of Java, follow this link:
http://java.sun.com/j2se/1.4/download.html
Yes, I offer a Java Study group, which is not quite as formal as a class. For more information, check this link:
http://www.johnsmiley.com/javafaq.htm
and for a schedule of my upcoming classes/study groups, check this link:
http://www.johnsmiley.com/bootcamps.htm
That depends. People learn in different ways, but everyone needs to start by obtaining a copy of Java.
Once you've done that, you now have three choices.
1. Buy a good book on Java. Naturally, I recommend my book
2. Take a class on Java at a local school, college, university or online. You might want consider doing that with me. For a schedule of the classes I offer, follow this link:
http://www.johnsmiley.com/bootcamps.htm
3. Just start programming (the way I learn), by taking some small project and coding it in Java. If you get stuck, you can find some tutorials on my Java Links Page
http://www.johnsmiley.com/java/links.htm
to get you past the rough spots.
Well...
It's not the easiest. Of the major languges, VB is the easiest language to learn, and C++ is the most difficult. Java fits somewhere in between--but the benefits of learning Java far exceed the difficulty in learning it.
In Java, all of your development is done via something known as a class.
In object-oriented terms, a class is a template (think of a cookie-cutter for your favorite cookie) for an object (the actual cookie).
Programmers who develop programs using object-oriented programming languages are taught to view the problem to be solved in terms of real-world objects (like an order, a timecard, a customer or an employee) that can be solved by designing these objects so that they interact with other objects. For instance, an employee completes a time card.
It's been proven that developing in object-oriented programs results in a better product, and one that can more easily be maintained or modified in the future.
Many programmers code their Java classes (see #9 above) using the Editor that is supplied with their Operating Systme (I use Windows Notepad myself).
The Java Development Kit (JDK) that you download from Sun Microsystems does not come with an IDE per se--but you can download one for free from Sun called Forte, and there are some other free ones available. In addition, there are other IDE's available for purchase.
I have an extensive list of Java IDE's posted on my Java Links Page
http://www.johnsmiley.com/java/links.htm
You might want to check my answer to #10 above.
Also, although not strictly speaking an IDE like some of those listed on my Links Page, you might want to consider Textpad, which allows you to download a trial version and run it for a while.
Textpad is basically an editor, but it does permit you to compile and execute your Java programs from within its editor. For more information on Textpad, follow this link:
In short, I ran out of pages.
Not to worry, though. I've written a Chapter 14 addendum for the book, and you can view the chapter on Applet creation here
http://www.johnsmiley.com/java/chapter14.htm
No. J++ is not Java, and Microsoft has announced that they do not intend to support J++ in the future.
No, JavaScript is a scripting language used to write code in an HTML document. Despite the name, it is not Java.
I should probably let Microsoft answer this, but I'll give it shot.
If you read the description of C#, you would believe you are reading a description for Java. Object-oriented, open source, cross platform. So, the bullet statements about C# match those of Java. Does that mean Java will go away?
Unlikely--there are a zillion Java developers---it will take quite some doing to have them jump to a Microsoft product.
More likely, you'll see C# eventually take the place of C++ and Visual Basic.
Yes. The more you know, the better.
Good question.
For a Windows PC, here they are:
The JavaTM 2 SDK is intended for use on Windows 95, Windows 98 (1st or 2nd edition), Windows NT 4.0 with Service Pack 5, Windows ME, Windows XP Home, Windows XP Professional, Windows 2000 Professional, Windows 2000 Server, or Windows 2000 Advanced Server operating systems running on Intel hardware. In non-English locales, the only edition of Windows 2000 tested with this release is the Professional edition.
A Pentium 166MHz or faster processor with at least 32 megabytes of physical RAM is required to run graphically based applications. Forty-eight megabytes of RAM is recommended for applets running within a browser using the Java Plug-in product. Running with less memory may cause disk swapping which has a severe effect on performance. Very large programs may require more RAM for adequate performance.
You should have 70 megabytes of free disk space before attempting to install the Java 2 SDK software.
Yes. Actually, there are two exams--Certified Programmer and Certified Developer. The Certified Developer exam requires that you actually write a program! (neat idea, huh?
For more information on Java Certification exams, check this link
http://www.sun.com/service/suned/
My thanks to Peter van der Linden for this answer--you can find this FAQ answer, and other great ones, listed at; http://www.afu.com/javafaq.html
There are three basic possibilities:
1. Are you successfully running the javac compiler? Try
javac -garbage
to see if it prints out a message about correct usage. If not, invoke javac using the full pathname, or set your PATH variable to include the directory that contains javac.
2. Is the CLASSPATH environment variable used correctly?
In JDK 1.0.2, beginners had to set CLASSPATH, and it had to include both system libraries and your programs.
In JDK 1.2, CLASSPATH is no longer needed for system libraries.
You do want CLASSPATH to point to the directories containing any "user classes" you're using. Getting started, you will probably want at a minimum "." (the current directory) in your CLASSPATH. When CLASSPATH is wrong, javac will tell you it can't find definitions for classes you reference in the source file. For information on setting up the CLASSPATH, see #21 following.
3. Is the source correct? Here javac will emit error and warning messages.
My thanks to Peter van der Linden for this answer--you can find this FAQ answer, and other great ones, listed at; http://www.afu.com/javafaq.html
There are five common mistakes that cause your VM (java or browser) to be unable to execute your classes
1. First, did you write an applet or an application? If an applet, you must make sure that you did extend the java.applet.Applet class. Your starting code should be in the init routine. If you wrote an application, your starting code should be in a routine called main(). Don't mix applets with applications until you have a bit more experience.
2. You must declare your main class as "public". If you don't, unfortunately some systems will still run the code, while others won't. The main class is either the one with the main() method in, or in the case of an Applet, the class that extends Applet.
3. Your class name and the file name must match exactly, even letter case. If your class is HelloWorld, your source file must be HelloWorld.java and your class file will be "HelloWorld.class".
4. If an Applet, and you used ftp to transfer the classes to the server, you must ftp all the classes, and you must use BINARY transfer not ASCII.
5. Errors in setting the CLASSPATH (and/or codebase in an applet). Even seasoned programmers do this, pointing inside a package or mistyping a path delimiter. For information on setting up the CLASSPATH and codebase, see Question 1.3 If you are running an applet, you should check the following further points:
a. If your class isn't loading, recheck the HTML applet tag.
b. If you are writing to System.out, the results are displayed in the browser's java console. You'll have to create a window if you want one.
c. Make sure your browser is compatible with the Java language features you are using. Internet Explorer and older versions of Netscape's browsers have omitted some support for JDK 1.1. Try your applet in the JDK's appletviewer first.
My thanks to Peter van der Linden for this answer--you can find this FAQ answer, and other great ones, listed at; http://www.afu.com/javafaq.html
The CLASSPATH environment variable tells the VM's class loader where to find classes that are directly or indirectly invoked, including system classes. The CLASSPATH variable should o point to the directory containing the class file, for classes not in a package. o point to the package root, for classes in a package. The root is the parent directory of the highest directory of the package name. o point directly to the zip or jar file, if the classes are in an archive file. You may have to list the contents of the archive to get the correct package/path name for the class. Separate multiple paths and archives with a platform-specific separator, ";" for Windows; ":" for Solaris Also remember that o Browsers set the CLASSPATH to the directory of the HTML file, plus the codebase parameter.
For a great tutorial on updating the CLASSPATH variable, follow this link:
http://www.naviseek.com/book/java21pre/jdkhelp1.shtml
My thanks to Peter van der Linden for this answer--you can find this FAQ answer, and other great ones, listed at; http://www.afu.com/javafaq.html
Your code probably looks something like this:
class myclass {
public static void main(String
args[]) {
myMethod();
}
public void myMethod() {
//some code
}
}
The issue is this: a static method means it belongs to the class, not each individual object.
If you leave the static keyword off (the usual case) as is done here with the method "myMethod()", it means that method can only be invoked on an object. But your call from main() has not told myMethod() which object it is to be invoked on.
Inside a non-static method, you don't have to provide this information, as it assumes you mean the same object on which it was invoked. But when calling from a static method, you must provide the information, and you haven't - hence the error message.
A common fix is to instantiate a member of the class, on which to invoke myMethod(), like this:
public static void main(String args[])
{ myclass m = new myclass();
m.myMethod(); }
This problem is especially common when you are writing code that you want to run as an applet and as an application. Naturally, you call init() and start() from main. What you really need to do is:
public static void main(String[] args)
{ Applet ma = new myApplet(); ma.init(); ma.start(); }
See #18 above.
Yes, I hope to start writing some Java articles in the next month or so. Be sure to check the link for my Articles page at
http://www.johnsmiley.com/cis18/freearticles.htm
javac *.java
My thanks to Peter van der Linden for this answer--you can find this FAQ answer, and other great ones, listed at; http://www.afu.com/javafaq.html
"Deprecated" means you are using an older API, that Sun has replaced with a newer one (usually to follow more consistent naming conventions). Deprecated methods are not recommended for use. They are supported in the short term, but your code should be updated with the new. To update your code, compile your old code using javac's "-deprecation" option to list deprecated methods, then find the replacement methods in the current HTML API documentation for the old deprecated methods. As an example of a deprecated API, Component.size() was replaced by Component.getSize().
if (s1 == s2) is giving me funny results.
My thanks to Peter van der Linden for this answer--you can find this FAQ answer, and other great ones, listed at; http://www.afu.com/javafaq.html
The comparison using "==" on objects, such as Strings, is asking, "Do these two objects have the same reference?" Do they have the same address, and hence are the same object?
What you really want to do is ask, "Do these two Strings have the same *contents*?"
Compare String contents with any of the following:
if
(s1.equals(s2) )
if (s1.equalsIgnoreCase(s2) )
if (s1.startsWith(s2) )
if
(s1.endsWith(s2) )
if (s1.regionMatches(s1_offset, s2, s2_offset, length) )
if
(s1.compareTo(s2) < 0)
(There are other ways, too.)
Note that you can do this with literals: if ("apple".equals(s2) ) ...
If you compare these the
other way round, like this:
if ( s2.equals("apple") ) ... and s2 is null, you will get a null pointer exception.
Good question!
Basically, overload is used as an adjective, override as a verb.
Huh?
Let me clarify.
An overloaded method is one which has the same name as another method, but where the method signature (number and type of arguments) is different.
When we create an overloaded method, we override the first method.
Use the JDBC-ODBC bridge. It is not especially challenging to set up, but it does require painstaking attention to detail. There is a step-by-step example in the van der Linden text "Just Java" mentioned in the sponsorship section of this document. Note that the Microsoft version of the Java kit does not support JDBC-ODBC access because it uses a non-standard native code interface. The JDBC FAQ can be found at
http://java.sun.com/products/jdbc/jdbc-frequent.html
It is an abbreviation of "Got you!" It is the triumphant exclamation that a bug or programming idiom makes as it traps the unwary programmer. This section details some of the popular "gotcha's" of Java. See the list of Java Gotcha's at
http://mindprod.com/gloss.html
Dippy Bird is Java documentation in WinHelp format, which can be used directly on Windows desktops, and has a searching utility. The developer of the Dippybird project, Bill Bercik, has stopped further work on the project due to lack of time and funds. Instead you can use
http://www.confluent.fr/javadoc/JavadocE.htm
which has a more up to date Java WinHelp doc. You can get still get the Dippy Bird download at
http://www.dippybird.com/jdk111.exe (JDK 1.1).
Use the JDBC-ODBC bridge. It is not especially challenging to set up, but it does require painstaking attention to detail. There is a step-by-step example in the van der Linden text "Just Java" mentioned in the sponsorship section of this document. Note that the Microsoft version of the Java kit does not support JDBC-ODBC access because it uses a non-standard native code interface. The JDBC FAQ can be found at
http://java.sun.com/products/jdbc/jdbc-frequent.html
Both these problems are resolved by the same process.
Assuming you're running the Win95/98 command.com, then you've changed the MS-DOS Prompt options under the "Properties" menu item. In the Properties dialog, Program->Advanced gets you a dialog.
Here, make sure the "Prevent MS-DOS-based programs from detecting Windows" checkbox is UNCHECKED. If the option is checked you get exactly the kind of behavior you're seeing. The option is unchecked by default, so it must have been selected at some time in the past. Change it back to unchecked.
I just bought Learn to Program with Java. Downloaded the JDK as you've described in the book and installed it. I tried to compile "ILoveJava.java" file but it kept giving me the "name specified is not recognized as an internal or external command.." error message. I've reinstalled the JDK three times and it still not able to compile. I have windows XP. I would appreciate if you could advise me on what to do.
That error message indicates that Windows can't find the Java compiler. Check the path property in the Environment section of your PC and ensure that the location of the Java compiler is in there. You also need to ensure that you have a CLASSPATH specified. This should have been done as part of the Java setup---but for some reason, it doesn't always happen.
If you're not familiar with these settings, check out this link
http://www.naviseek.com/book/java21pre/jdkhelp1.shtml
Page 6 of that tutorial has a great illustration of what you need to do to your system to ensure that the Java compiler can be found.
If you don't feel comfortable tinkering with the inner workings of your system, then take the easiest approach.
Download Textpad (see FAQ #11 above). Textpad, which you can try for tree, will enable you to compose and compile your Java programs from within it--plus, it's setup program will place the path to the Java JDK in this environment setting for you---so even if you don't use Textpad, you should then be able to compile using Notepad.
Associates
| Books I have written | Bookstore
| C#
| Classes/Seminars/Bootcamps
| Contract
Programming/Consulting | Free Stuff
| Help for the beginner
programmer | Java |
Join Professor Smiley's
Mailing list |
Join my HelpwithVB group |
Make
a donation | News| Teaching
| TV appearances
| Visual Basic