Java SE series:2. enhance your java basis! [doc chm: jdk6api Chinese reference]

本文介绍了如何使用Eclipse进行Java Web和Android开发,包括快捷键设置、创建新类、配置环境、调试方法、配置快捷键、JUnit单元测试、Java 5增强功能、增强for循环、数据结构与算法等核心知识点。

1. javaee(Web) and Android

2. how to use eclipse and break point debuging in eclipse, as to java web, use myeclipse:

  shortcut keys:  ,do not use Chinese or space in workspace path, configure JRE default, as jdk already has jre, we just configure with jdk path! but if we have a project from others, we better use myeclipse default, coz on different machines, JRE path varies.

3. create a new class, need to specify package name, super class use default, check static void main method stub and inherited abstract method when first entry.

4. right click project and select properties, then configure project properties, check java compiler and compile, so, be aware, your compiler version and your jre version should at least be the same, if we meet with version problems, we should configure project java build path, remove old default libries and add JRE system library into build_path, in this way, our compiler and jre environment can be configured the same. But the higher version will comply with lower.

the same with vs project .net framework target version.

eg: import java.io.file, we can use copy(src,dest), FileNotFoundException,FileInputStream,FileOutputStream,existFile(src), inputstream.read(buffer)>0 and io exceptions, right click project and click debug as java application to debug. F5 to step into the method, F6 to step out like F11, F7 to step out a method like F10 in vs.  remember to stop JVM and clear all breakpoints after debugging, we can watch the args while debugging.

F5: step into, F6: step over,F7: step return,drop to frame,resume

5. Ho to configure eclipse shotcut keys: window->preference, select keys under General to configure the shortcut keys and apply. use alt+/ for hints!, repeatly press ctrl+1 to repaidly restore errors. ctrl+shift+o to automatically import package. ctrl+ship+f to auto layout it, ctrl+leftclick to navigate to source, goto java path and import src.zip using file pattern, use alt+left arrow and right arrow to navigate when navigating src,ctrl+shift+/ to comment and ctrl+shift+\ to uncomment,F2 to see method description, window-> reset perspective to reset window layout same with VS.

const value should be upper case, ctrl+shift+x/y to change upper case and lower case. ctrl+alt+ down arrow to copy current line. alt+up/down arrow to toggle current and next line order, watching class hierarchy, press ctrl+t, press ctrl+shift+t to directly see the code source!

ctrl+shift+L to see all shortcut in eclipse.c

6. junit test framework:  create a test class for your src code, to use junit, just add @Test as annotation, press ctrl+1 to see hints! right click the method or the whole class, then select run as jUnit Test, see result from jUnit window. use @Before and @After when running test method to add as interceptor,@BeforeClass and @AfterClass as interceptor of the whole class[class interceptor is not so often used].  we can now use Assert. in jUnit now.

7.  About java 5 enhancements:  

 import static: eg: import static java.lang.system.out; import static java.lang.Math.*; same with vs using =, but ctrl+1 is definitely faster.

wrap and unwrap boxing; eg: Integer i=1/(new Integer(1));(jdk 5+); int j=i;

typical usage: new ArrayList().add(1/(old way in jdk 1.4) new Integer(1)), really useful.  list.iterator, it.hasNext(); int k=(Integer) it.next();

8. enhanced for loop: eg int arr[] =(1,2,3); for(int num: arr){} Map map=new HashMap(); map.put("1","aaa");Set set=map.keySet(); Iterator it=set.iterator(); while(it.hasNext()){String key=(String)it.next(); String value=(String)map.get(key); } HashMap is not sequencial! remember, when it is stored, the order is different from your storage order!  if we want the order, just use LinkedHashMap() when you need order!!!  or we can use map.entrySet() to get keyvalue collections, then iterate it to get the entry(Map.Entry as key value pair) then value of the entry. we can use for like (for..in) to iterate set! this for loop only suits reading data. but pay attention to reference type like String. ArrayList.get(0), it defines an argument to iterate. never change set data! if we want to modify data in a list, we should use traditional ways, i.e. using for(int i=0;...)

9. [07]

 

 

转载于:https://www.cnblogs.com/hualiu0/p/5373483.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值