<
> 84
java文件名需保持与类名一致(包括大小写)
You need to make the file name for the source code the same as the name of the public class, with the extension .java appended. Thus, you must store this code in a file called FirstSample.java. (Again, case is important—don’t use firstsample.java.) java ClassName
常量定义用final
关键字
In Java, you use the keyword final to denote a constant.
Build-in的类方法和静态方法
There is a subtle difference between the println method and the sqrt method. The println method operates on an object, System.out, defined in the System class. But the sqrt method in the Math class does not operate on any object. Such a method is called a static method. You can learn more about static methods in
引用静态方法需使用import static
import static java.lang.Math.*;
Import
at the beginning of the program. The Scanner class is defined in the java.util package. Whenever you use a class that is not defined in the basic java.lang package, you need to use an import directive
The Scanner class is not suitable for reading a password from a console since the input is plainly visible to anyone. Java SE 6 introduces a Console class specifically for this purpose. To read a password, use the following code:
Console cons = System.console();
String username = cons.readLine("User name: ");
char[] passwd = cons.readPassword("Password: ");
System.console()
returns a Console object for interacting with the user through a console window if such an interaction is possible, null otherwise. A Console object is available for any program that is launched in a console window. Otherwise, the availability is systemdependent.
注意
- sysout syserr main Alt+/
- java中import的是类, 而不是命名空间
Auto activation 智能提示 (Alt+/)
Preferences -> Java -> Editor -> Content Assist -> Auto activation triggers for Java
Preferences -> Java -> Editor -> Templates