Put your text ad here
WestNIC provides reliable web hosting services
Free software downloads and drivers download resources
Top Canadian Hotels no booking fees from Victoria BC to Nova Scotia
This FAQ is part of the Code Style Help and FAQ section. Join our premium content service for full access all FAQ answers.
Hello.java?
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.
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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 omitted
Access all premium content for $50: sign-up now.
Which class should be compiled first?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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 omitted
Access all premium content for $50: sign-up now.
What are the steps in compiling a class?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
Hello.java?
A: In the simplest case, type cmd in the Windows Run dialogue (on the Start menu) and change to the source directory then run the javac command, as below.
… premium content omitted
Access all premium content for $50: sign-up now.
What do I type at the command line to compile Hello.java?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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, as below.
… premium content omitted
Access all premium content for $50: sign-up now.
Where is my compiled class file?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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, see the exmaple below.
… premium content omitted
Access all premium content for $50: sign-up now.
How can I ensure my compiler will locate the SAX package?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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 omitted
Access all premium content for $50: sign-up now.
What does this deprecation message mean?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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 omitted
Access all premium content for $50: sign-up now.
What are undefined and undeclared variables?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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.
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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).
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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 omitted
Access all premium content for $50: sign-up now.
How do I set the compiler path?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: For Windows 2000/XP systems, the environment settings are edited in a special Control Panel applet called System.
… premium content omitted
Access all premium content for $50: sign-up now.
How do I set environment variables on Windows XP?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
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 omitted
Access all premium content for $50: sign-up now.
How do I configure EditPlus to compile Java and capture output?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
| Front-end FAQs | Back-end FAQs | Learning Java |
|---|---|---|
About us: site help, text ads and premium content FAQs.