learning package & import:
key points (some are different with C/C++ coding):
1. the main class name (if public) has to be consistent with the class file name:
Thus needs to rename the mainclass to be example_1_1, i.e., public class example_1_1{
2. wrong: [import java.io], correct: [import java.io.*]
3. must have ";" after "import" statements, e.g., [import java.io.*;]
4. function names/methods are all case sensitive
5. prompt to use -Xlint:unchecked for detail information if the code contains unchecked or unsafe operations (but seems actually unnecessary)
package: class container, organize, reusable, maintainability, encapsulation, modularity, defining hierarchical directory structure, up to 1 per file, reverse domain name, equate to directory structures, should be lowercase, separated by underscores.
import java.io.*;
import java.util.ArrayList;
public class example_1_1{
public static void main(String[] args){
Console console = System.console();
String planet = console.readLine("\nEnter your favorite planet:");
ArrayList planetlist = new ArrayList();
planetlist.add(planet);
planetlist.add("Gliese 581 c");
System.out.println("\nTwo cool planets:" + planetlist);
}
}

被折叠的 条评论
为什么被折叠?



