Search
Relevant Links
Top 10 Articles
Jetty - Java Developers's Guide To Latest Web Server Technology
Jetty, an Open source application server from Java has been the talk of the Developers community these days
Jetty - Java Developers's Guide To Latest Web Server Technology
Advantage And Disadvantages Of String Implementation In JAVA
Advantages of the String implementation in JAVA
Advantage And Disadvantages Of String Implementation In JAVA
Hibernate Vs JDBC Performance
The Hibernate advantage over JDBC
Hibernate Vs JDBC Performance
Choosing Java Vs .Net For Web Development
Choosing Java Vs .Net For Web Development
Choosing Java Vs .Net For Web Development
How To Call Java Applet Functions From Javascript
How to Call Java Applet Functions From Javascript
How To Call Java Applet Functions From Javascript
Java 2 Platform Enterprise Edition (J2EE) Three-Tier Model
Enterprise edition of J2EE is used for developing modular enterprise request.
Java 2 Platform Enterprise Edition (J2EE) Three-Tier Model
What Is Java Virtual Machine
What is java virtual machine?
What Is Java Virtual Machine
How Does Java Handle Overriding
Overriding tactics in Java is very different from C++ as methods by default in Java can be overridden unlike C++
How Does Java Handle Overriding
Java Interface Overview
Interface: Interfaces can be used to implement the Inheritance relationship between the non-related classes that do not belongs to the same hierarchy, i.e. any Class and any where in hierarchy
Java Interface Overview
Enterprise Java Bean Application Development With A Three-Tier Architecture
Enterprise java beans is basically a server side component architecture for developing modular enterprise applications based on the java platform
Enterprise Java Bean Application Development With A Three-Tier Architecture
Use Of Hibernate With Java Persistence API
Hibernate has become immensely popular amongst the developer community as it is a free, powerful, high performance open source object
Use Of Hibernate With Java Persistence API
Java Embedded Applications
Java, or J2ME is a format for applications for mobile and PDAs. It provides software that can been added to mobile phones
Java Embedded Applications
How Does Java Handle Overriding?
Overriding tactics in Java is very different from C++ as methods by default in Java can be overridden unlike C++. In C++, the concept of overriding functions are handled by Virtual Table, VTable
How Does Java Handle Overriding?
Work With Teradata Using Java
Teradata is one of the leading vendor in data analytics and data warehousing applications and softwares.
Work With Teradata Using Java
Point To Point Video Conferencing Using Java's JMF API
When a face-to-face meeting with someone far away becomes a necessity or a compelling presentation must be given to a remote person,
Point To Point Video Conferencing Using Java's JMF API
Learning Java Programming Coding Language
There are many programming languages available and each of them is suitable for another program or application.
Learning Java Programming Coding Language
Java Hashtable
A collection allows a group of objects to be treated as a single unit.
Java Hashtable
Working With JNDI In A J2SE Application
Java Naming and Directory Interface (JNDI) allows Java objects to be published to a directory service which can be accessed by other Java applications later.
Working With JNDI In A J2SE Application
Java Games - The World Of Excitement Is Readying With Options!
Mobile phones have grown from the pedestal of a mere communication tool and with the aid of some innovative steps plus the technological up-gradation
Java Games - The World Of Excitement Is Readying With Options!
Everything You Need To Know And How To Use Java
Java is an object-oriented programming language developed by Sun Microsystems in the early 1990s
Everything You Need To Know And How To Use Java
Of CGI And Java Scripts
CGI and Java Scripts are both functional with both Netscape and Internet Explorer browsers.
Of CGI And Java Scripts
Free Java Games - Entertain Yourself In Your Leisure Time
Today, you can find cell phones having multifunctional organisational tools
Free Java Games - Entertain Yourself In Your Leisure Time
Ajax Applications Development
AJAX has not only sprouted but has got root hold in developing dynamic web applications,
Ajax Applications Development
Benefits And Pitfalls Of A Java-Based Forex Trading Platform
Many forex brokers today offer a Java-based platform to traders as opposed to the traditional software that needs to be installed on your computer.
Benefits And Pitfalls Of A Java-Based Forex Trading Platform
Point To Point Video Conferencing Using Java's JMF API
When a face-to-face meeting with someone far away becomes a necessity or a compelling presentation must be given to a remote person, video conferencing is always your best choice
Point To Point Video Conferencing Using Java's JMF API
What Is CLASSPATH
A path specifies the name and location of a file on the file system.
What Is CLASSPATH
Javascript Is Not Java
Repeat after me: JavaScript is not Java, JavaScript is not Java. . .
Javascript Is Not Java
Eclipse IDE
Eclipse is an open-source, platform-independent software framework for delivering what the project calls "rich-client applications".
Eclipse IDE
Tomcat Jsp Run Error:Unable To Find A Javac Compiler
I always get this error when I run simple jsp files in my Tomcat 5.0.19/win2000. These jsp files run on other versions of Tomcat on the same PC. Any ideas?
Tomcat Jsp Run Error:Unable To Find A Javac Compiler
Deploying Web Applications To Tomcat
In this article we are going to cover the deployment of web applications using Tomcat.
Deploying Web Applications To Tomcat
Running The Tomcat 4.0 Servlet/JSP Container
Tomcat 4.0, a server that implements the Servlet 2.3 and JSP 1.2 Specifications from Java Software. In order to install and run this container, you must do the following
Running The Tomcat 4.0 Servlet/JSP Container
SOAP Example
In the example below, a GetStockPrice request is sent to a server. The request has a StockName parameter, and a Price parameter will be returned in the response.
SOAP Example
SOAP HTTP Binding
HTTP communicates over TCP/IP. An HTTP client connects to an HTTP server using TCP. After establishing a connection, the client can send an HTTP request message to the server:
SOAP HTTP Binding
SOAP Fault Element
The optional SOAP Fault element is used to hold error and status information for a SOAP message.
SOAP Fault Element
SOAP Body Element
The mandatory SOAP Body element contains the actual SOAP message.
SOAP Body Element
Introduction To SOAP
SOAP is a simple XML based protocol to let applications exchange information over HTTP.
Introduction To SOAP
Where Did Java Come From?
In the late 1970's Bill Joy thought about doing a language that would merge the best features of MESA and C
Where Did Java Come From?
What Is Java?
Java, formerly known as oak, is an object-oriented programming language developed by Sun
What Is Java?
How Do I Format Numbers Like C's Printf()?
Java does not have any built in equivalent to C's printf/sprintf/fprintf family of functions that specify the width and precision of numbers converted into strings.
How Do I Format Numbers Like C's Printf()?
How Do I Play A Sound In An Application?
Java's audio support comes from the AppletContext class and the AudioClip interface. Since applications don't have applet contexts, they have no easy way to play audio clips
How Do I Play A Sound In An Application?
Java Interview Questions
Java Interview Questions for java programmers !
Java Interview Questions
Java Games For Your Cell Phone
Are you one of those people who get tired when standing in queue? Can't stop multitasking no matter what you do
Java Games For Your Cell Phone
Pros And Cons Of JavaScript
Javascript use is very common across the Internet; but just because it is popular, does that mean you should use it for your site
Pros And Cons Of JavaScript
Tag Libraries
JSP 1.1 introduces a method of extending JSP tags, called "tag libraries".
Tag Libraries
Beans And Form Processing
The standard way of handling forms in JSP is to define a "bean". This is not a full Java bean.
Beans And Form Processing
JSP Sessions
If you are programming the site, it is very helpful to be able to associate some data with each visitor. For this purpose, "session"s can be used in JSP
JSP Sessions
JSP Tags
Another important syntax element of JSP are tags. JSP tags do not use <%, but just the < character. A JSP tag is somewhat like an HTML tag.
JSP Tags
JSP Directives
We have been fully qualifying the java.util.Date in the examples in the previous sections. Perhaps you wondered why we don't just import java.util.*;
JSP Directives
Mixing Scriptlets And HTML
We have already seen how to use the "out" variable to generate HTML output from within a scriptlet.
Mixing Scriptlets And HTML
JSP:Scriptlets
JSP also allows you to write blocks of Java code inside the JSP. You do this by placing your Java code between <% and %> characters
JSP:Scriptlets
Categories
Related Links

 

Java4Programmers.com

Java4Programmers.com This is a high-level informational site for java programmers outside of Sun Microsystems. This is a categorized directory of information sources for Java, including sources, communities, tools, etc.

Java Programming

Java Programming : Java Common Compiler Errors

 

Compiler Problems

Common Error Messages on Microsoft Windows Systems

'javac' is not recognized as an internal or external command, operable program or batch file

If you receive this error, Windows cannot find the compiler (javac).

Here's one way to tell Windows where to find javac. Suppose you installed the JDK in C:jdk6. At the prompt you would type the following command and press Enter:

C:jdk6binjavac HelloWorldApp.java

If you choose this option, you'll have to precede your javac and java commands with C:jdk6bin each time you compile or run a program. To avoid this extra typing, consult the section Update the PATH variable in the JDK 6 installation instructions.

Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested

If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.

Common Error Messages on UNIX Systems

javac: Command not found

If you receive this error, UNIX cannot find the compiler, javac.

Here's one way to tell UNIX where to find javac. Suppose you installed the JDK in /usr/local/jdk6. At the prompt you would type the following command and press Return:

/usr/local/jdk6/javac HelloWorldApp.java

Note: If you choose this option, each time you compile or run a program, you'll have to precede your javac and java commands with /usr/local/jdk6/. To avoid this extra typing, you could add this information to your PATH variable. The steps for doing so will vary depending on which shell you are currently running.

Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested

If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac HelloWorldApp.java not javac HelloWorldApp.

Syntax Errors (All Platforms)

If you mistype part of a program, the compiler may issue a syntax error. The message usually displays the type of the error, the line number where the error was detected, the code on that line, and the position of the error within the code. Here's an error caused by omitting a semicolon (;) at the end of a statement:

testing.java:14: `;' expected.
System.out.println("Input has " + count + " chars.")
^
1 error

Sometimes the compiler can't guess your intent and prints a confusing error message or multiple error messages if the error cascades over several lines. For example, the following code snippet omits a semicolon (;) from the bold line:

while (System.in.read() != -1)
count++
System.out.println("Input has " + count + " chars.");

When processing this code, the compiler issues two error messages:

testing.java:13: Invalid type expression.
count++
^
testing.java:14: Invalid declaration.
System.out.println("Input has " + count + " chars.");
^
2 errors

The compiler issues two error messages because after it processes count++, the compiler's state indicates that it's in the middle of an expression. Without the semicolon, the compiler has no way of knowing that the statement is complete.

If you see any compiler errors, then your program did not successfully compile, and the compiler did not create a .class file. Carefully verify the program, fix any errors that you detect, and try again.

Semantic Errors

In addition to verifying that your program is syntactically correct, the compiler checks for other basic correctness. For example, the compiler warns you each time you use a variable that has not been initialized:

testing.java:13: Variable count may not have been initialized.
count++
^
testing.java:14: Variable count may not have been initialized.
System.out.println("Input has " + count + " chars.");
^
2 errors

Again, your program did not successfully compile, and the compiler did not create a .class file. Fix the error and try again.

Runtime Problems

Error Messages on Microsoft Windows Systems

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp

If you receive this error, java cannot find your bytecode file, HelloWorldApp.class.

One of the places java tries to find your .class file is your current directory. So if your .class file is in C:java, you should change your current directory to that. To change your directory, type the following command at the prompt and press Enter:

cd c:java

The prompt should change to C:java>. If you enter dir at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.

If you still have problems, you might have to change your CLASSPATH variable. To see if this is necessary, try clobbering the classpath with the following command.

set CLASSPATH=

Now enter java HelloWorldApp again. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, consult the Update the PATH variable section in the JDK 6 installation instructions. The CLASSPATH variable is set in the same manner.

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/class

A common mistake made by beginner programmers is to try and run the java launcher on the .class file that was created by the compiler. For example, you'll get this error if you try to run your program with java HelloWorldApp.class instead of java HelloWorldApp. Remember, the argument is the name of the class that you want to use, not the filename.

Exception in thread "main" java.lang.NoSuchMethodError: main

The Java VM requires that the class you execute with it have a main method at which to begin execution of your application. A Closer Look at the "Hello World!" Application discusses the main method in detail.

Error Messages on UNIX Systems

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp

If you receive this error, java cannot find your bytecode file, HelloWorldApp.class.

One of the places java tries to find your bytecode file is your current directory. So, for example, if your bytecode file is in /home/jdoe/java, you should change your current directory to that. To change your directory, type the following command at the prompt and press Return:

cd /home/jdoe/java

If you enter pwd at the prompt, you should see /home/jdoe/java. If you enter ls at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.

If you still have problems, you might have to change your CLASSPATH environment variable. To see if this is necessary, try clobbering the classpath with the following command.

unset CLASSPATH

Now enter java HelloWorldApp again. If the program works now, you'll have to change your CLASSPATH variable in the same manner as the PATH variable above.

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/class

A common mistake made by beginner programmers is to try and run the java launcher on the .class file that was created by the compiler. For example, you'll get this error if you try to run your program with java HelloWorldApp.class instead of java HelloWorldApp. Remember, the argument is the name of the class that you want to use, not the filename.

Exception in thread "main" java.lang.NoSuchMethodError: main

The Java VM requires that the class you execute with it have a main method at which to begin execution of your application.


Other Relevant Articles from this Category:
Java Hello World Program
Java Common Compiler Errors
Java Language Programming
Increment The DATE By One Day
Printing Message From Servlet To Jsp
Java Main()
JavaBeans
Decompilers - Friend Or Foe?
How Do I Format Numbers Like C's Printf()?
What Is Java?
Where Did Java Come From?
Eclipse IDE
Point To Point Video Conferencing Using Java's JMF API
Benefits And Pitfalls Of A Java-Based Forex Trading Platform
Ajax Applications Development
Everything You Need To Know And How To Use Java
Java Hashtable
Learning Java Programming Coding Language
How Does Java Handle Overriding?
Java Embedded Applications
How Does Java Handle Overriding
Choosing Java Vs .Net For Web Development
Advantage And Disadvantages Of String Implementation In JAVA

More Categories:
Java Script  
Download Java  
Java Game  
Java Programming  
Java Developer  
Java Certification  
Java Applet  
Java Sun Certification  
Java Tutorial  
Java Swing  
Java Runtime Environment  
Xml  
Install Java  
Java Network Programming  
Java Training  
J2ee  
Thinking In Java  
Java Application Server  
Java Programmer  
Java Design Pattern  
Tomcat  
Struts  
Jsp