[course02] 00 Package and Class
[course02] 00 Package and Class
Two packages used in this course
print statements
System.out.println("Rather a lot to type");import java.util.*;
import static net.mindview.util.Print.*;
public class HelloDate {
//: operators/HelloDate.java
public static void main(String[] args) {
print("Hello, it’s: ");
print(new Date());
}
}add the root directory of that code tree to your computer’s CLASSPATH environment variable.
TextIO
where is textio.TextIO
add the file to package and import the class auto.
packages
A typical Java program has user-defined classes whose objects interact with those from Java class libraries.
In Java, related classes are grouped into packages, many of which are provided with the compiler.
Basic class
A Java program must have at least one class, the one that contains the main method. The Java files that comprise your program are called source files.
A compiler converts source code into machine-readable form called bytecode.
typical java code:
All Java methods must be contained in a class.
The words class, public, static, and void are reserved words, alsocalled keywords. (This means they have specific uses in Java and may not be used as identifiers.)
The keyword public signals that the class or method is usable outside of the class, whereas private data members or methods are not.
The keyword static is used for methods that will not access any objects of a class, such as the methods in the FirstProg class in the example above. This is typically true for all methods in a source file that contains no instance variables. Most methods in Java do operate on objects and are not static. The main method, however, must always be static.
The program shown above is a Java application.
Last updated
Was this helpful?