JVM,JRE,Java Compiler FAQs-2
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.
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
might be stored in a file with the path
A: Sometimes you will find that trial and error will give you the answer you need. If you are using the Sun compiler,
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.
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:
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.
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
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.
A: One gets warning messages about undefined and undeclared variables when compiling Java classes that have programming errors,
as in the example below.
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.
A: For Windows 2000/XP systems, the environment settings are edited in a special Control Panel applet called System.
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…
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.
Latest posts by Krishna Srinivasan (see all)
- 5 New Features in HTML5 - November 29, 2013
- How To Set Tomcat JVM Heap Size in Eclipse? - November 28, 2013
- How To Resolve “Resource Is Out Of Sync With The Filesystem” Error in Eclipse? - November 28, 2013
Pages: 1 2