Your browser has JavaScript turned off. This page is best viewed with Javascript enabled. Certain functions on this site will not work, and some style sheets will not load. Check your browser preferences to enable JavaScript.

Teach Yourself Java

Frequently Asked Questions

General Compiler Errors Applet Problems *** Remember each problem is unique. We can't debug your program for you, we can just give you advice and point out common mistakes. In other words if our suggestions don't work, don't give up hope. You might want to check our Other Resources page or post your question on our Message Board.


General Questions

"What is this 'Java'?"

Java is a high-level, object-oriented computer programming language. Java can be used to make Applets that run over the Internet.

To learn more, read our What is Java Page.

"What is the difference between a Java Applet and a Java Application?"

Basically, the difference is that an Applet is meant to be viewed on a web page, while an Application is run from the command line.

For a more in depth explanation, see the What is an Applet page.

"What can an Applet do?"

Applets can do just about anything that a Java application can do. Of course, this may mean absolutely nothing to you if you are not familiar with Java applications either. You can use applets to make your websites interactive. Applets can be used for games, animations, quizzes, tutorials, and millions of other things as well.The best way to understand what applets are capable of is to look at some examples.

Check out our Other Resources page for a list of sites with good Applet examples.

"How do I make a webpage?"

Writing a webpage is easy. Websites are written in the HyperText Markup Language (HTML). HTML is quite simple and easy to learn.

Just follow our simple Basic HTML guide.

"Ok, I made a website and compiled my java program, now how do I put the Applet onto my webpage?"

Once your website is written (in HTML), you just need to add an applet tag within the body section of the HTML. The applet tag looks like this
    <applet code="myCompiledCode.class" width="400px" height="400px"></applet>

For more complete instructions on adding your applet, see the Adding an Applet section of our Basic HTML guide.

"How do I get started?" or "How do I use this website?"

Teach Yourself Java is designed to be easy to use. Basically, you should follow these steps:
  1. Background - Check out our Background Info Section. This will give you the general knowledge that you need to understand the lessons.

  2. Lessons - Follow our Lesson Plan. Start with the first lesson and work your way through all of them.

  3. HELP - Whenever you need help, our Help Section offers plenty of resources to you. If you don't understand the terminology, check out the Java Glossary. If you have a question, you have three options:

    1. Check out Frequently Asked Questions.
    2. Post your question on our Message Board or just look through answers to past questions.
    3. Use our list of Other Resources if you can't find the answer on this site.

  4. Further Information - If you found this tutorial interesting and would like to learn more about the Java language, check out our Other Resources page. This contains links to more tutorials that go beyond the material covered here.



Compiling Errors

Understanding Compiler Errors

Compiling is going to be the most frustrating part of computer programming. There will be plenty of times that you believe you have written a perfect program and it won’t work for hours because the compiler will tell you that you have errors and that it can’t run your program. When you compile your program, one of two things will happen. Either the compiler will tell you compilation complete or it will give you a list of errors. Each of the errors that it lists will be associated with a line number which you can use to find exactly where the error is. It will also tell you what was wrong. A few of the common errors are listed below. However, it is essential to look at exactly what the compiler says the error is and try to figure out how it applies to the line that it occurred on.

If necessary, you can post on our forum or check out this great guide to fixing common compiler errors.

javac: Command not found

This error message means that the computer cannot find the compiler.

Follow these steps:
  1. Make sure that Java has been properly installed - for instructions see Installing Java


  2. Check your PATH. []

';' expected

This error message means that there is a semicolon missing from the end of a line.

Variable x may not have been initialized

This error message means that you used a variable before explicitly initializing it.

Type expected {public method variable}

This error message means that you forgot to specify a return type for your function.

public class class_name must be defined in 'class_name.java'

This error message means that you saved your sourcecode file as "class_name.java" but that file doesn't contain the class definition for "class_name."

Invalid Declaration

This error message means that you are probably trying to assign a value to a variable when you originally declare it and not doing it the right way. You might either be assigning a value of the wrong type or assigning it using two equals signs instead of one.

Invalid Type Expression

This error message means that you probably forgot to end the previous line with a semicolon. It may also occur if you spell a command wrong, such as if with a capital I instead of a lower case i.



Applet Problems

"Why can't I see my Applet on my website?"

There may be a number of problems: 
  • First, you want to make sure that Java has been correctly installed on your computer. See our Guide to Installing Java.
  • Second, you want to make sure that you have compiled your program into a class and that the class has been put on the web page you are attempting to view (check the Basic HTML section again.
  • Finally, you may have to check your code to ensure that you have written the code properly and haven’t missed any steps (forgetting to set the Content Pane is sometimes a problem).
If all of these problems are not causing the problem, you may want to post on our forum or check our Other Resources page.

"My changes didn't take effect?!?"

Most often, the reason that your changes have not taken place is that you forgot to recompile your program before running it again. If you open your web browser to run an Applet before that program has been recompiled, it will not reflect the changes you made. Another idea is to clear the cache associated with your Java program – if you installed the Java version that we suggested, there will be a window that pops up that has an option of pressing ‘x’ to clear the cache. If the changes still do not show up, check your code to make sure you know exactly what the changes do, and as a last resort, save everything, close all your directories and internet browser, and then reopen them.

Again, if nothing works, post on thepost on our forum or check our Other Resources page.

.