概述
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);
}
}
最后
以上就是默默小白菜为你收集整理的The 3rd day learning Java的全部内容,希望文章能够帮你解决The 3rd day learning Java所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复