World class Hard Drive Recovery and renowned raid recovery services

WestNIC provides reliable web hosting services

Site navigation below

This FAQ is part of the Code Style Help and FAQ section. Use the help request form below if your question is not answered here, but make sure you are asking the right question first.

Subscribe to this FAQ: RSS news feed

FAQ search

Compiler concepts

Q: What is the source code for the compiler?

A: The source code for a Java program is also known as a compilation unit, which contains the code for a top level Java class or interface. A Java compilation unit is usually created in the form of a file with a .java extension and is passed to the compiler as a file path reference.

The Java source file contains a header that declares the type of class or interface, its "visibility" with respect to other classes, its name and any superclass it may extend, or interface it implements. The body of the class contains variable declarations and methods that define the behaviour of the class, and any constructors used to create an instance of the class. A compilation unit may also contain nested inner classes.

Q: Why is the source file named after the class?

A: The Java source file naming convention is not a standard specified by the Java language but is a common feature of Java compilers, such as javac, to help locate source code. The source content of a Java class is known as a compilation unit. By storing the compilation unit in a file that is named after the class, the compiler can locate any supporting classes by name and compile those too.

This convention also extends to package names. Most Java compilers expect source code to be stored in directories whose names match their package hierarchy. Thus the source code for a class named Example in the package com.domain.util might be stored in a file with the path c:\src\com\domain\util\Example.java

Q: Which class should be compiled first?

A: Sometimes you will find that trial and error will give you the answer you need. If you are using the Sun compiler, javac, the compiler will compile any other classes that your target class depends on, provided the other source files are in the same directory hierarchy as the first and the sub-directory names reflect the package hierarchy of the classes.

Premium Content: Follow this link for subscription information More details available to subscribers:
Which class should be compiled first?

Compiler commands

Q: What are the steps in compiling a class?

A: Once you have written the Java source code file, there is only one step required to compile it. To compile the class from the command line, you need to give the path to the compiler program, such as Sun javac, and the path of the source code file, like this:

Premium Content: Follow this link for subscription information More details available to subscribers:
What are the steps in compiling a class?

Q: Where is my compiled class file?

A: If you are sure your class is being compiled, then the class file should be output somewhere! Without any directory argument, your compiler should place the class file in the same directory as your source file. Use the output directory argument to specify where the class files are generated.

Premium Content: Follow this link for subscription information More details available to subscribers:
Where is my compiled class file?

Q: How can I ensure my compiler will locate the SAX package?

A: One way to ensure your compiler can locate any package it may require is to pass its path to the compiler explicitly using the -classpath argument.

Premium Content: Follow this link for subscription information More details available to subscribers:
How can I ensure my compiler will locate the SAX package?

Compiler diagnostics

Q: What does this deprecation message mean?

A: The deprecation message you have seen means that the methods you are calling have been marked with a JavaDoc deprecation comment. When a method or class is marked deprecated it is only advisory, not mandatory, but the advice is given for good reason and should be followed. So long as deprecated methods remain in the public API it is possible to use them, so this approach supports legacy code and gives developers time to amend their applications as necessary.

Premium Content: Follow this link for subscription information More details available to subscribers:
What does this deprecation message mean?

Q: What are undefined and undeclared variables?

A: One gets warning messages about undefined and undeclared variables when compiling Java classes that have programming errors, as in the example below.

Premium Content: Follow this link for subscription information More details available to subscribers:
What are undefined and undeclared variables?

Q: Why doesn't the compiler warn about stack overflow problems?

A: There are many cases of poor runtime programming that could potentially be identified at compile time, but the number and subtlety of the cases gets increasingly difficult to address. The main purpose of a compiler is to produce executable byte code that is valid according to the rules of the programming language, not to guard against poor programming. Hence most compilers only validate the syntax of the language and the most obvious logical errors in the code at compile time.

Development environment

Q: What Java compilers are there?

A: There are many Java compiler implementations. The one most developers start with is that provided with the Sun Java Software Development Kit (JSDK), named javac. Alternative implementations include the free open source GNU Compiler for Java (GCJ) and the Eclipse Compiler for Java, which is part of the Eclipse integrated development environment (IDE).

Q: How do I set the compiler path?

A: The Java compiler is a program like any other and your operating system needs to know where to find the executable file. The simplest way to do this is to give the full path to the Java compiler in the command, as below for Windows...

Premium Content: Follow this link for subscription information More details available to subscribers:
How do I set the compiler path?

Q: How do I set environment variables on Windows XP?

A: For Windows 2000/XP systems, the environment settings are edited in a special Control Panel applet called System.

Premium Content: Follow this link for subscription information More details available to subscribers:
How do I set environment variables on Windows XP?

Q: How do I configure EditPlus to compile Java and capture output?

A: These instructions on configuring the NSGMLS markup validator for EditPlus will help you get started. For Java, the Command field will be the path to your javac.exe program (or java.exe to run). The Argument should contain any parameters you want to pass to the compiler and should end with the $(FilePath) variable that substitutes the current file name. Check the Capture output box to get feedback from the compiler.

Premium Content: Follow this link for subscription information More details available to subscribers:
How do I configure EditPlus to compile Java and capture output?

Help request

Use the form below to submit a help request or general enquiry about the Code Style Web site. Read our guidelines on asking the right questions first.

Information: Your email address will not be mis-used. If you include your address you may be sent a personal reply, you will not be added to any mailing list unless you request it. Read the site privacy statement for details.

Add this page to your chosen social bookmarking service

Style warning - please read

Home · CSS · Java · Javascript · HTML · Help · Log