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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14import 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内容请搜索靠谱客的其他文章。
发表评论 取消回复