- F11: Debug
- Ctrl + F11: Run.
- Ctrl + Shift + B: Toggle Breakpointer.
- Ctrl + Shift + F: Format.
- Ctrl + Mouse left click: View Source Code.
- Ctrl + /: Add Comment.
延伸閱讀
Java Interface: 1. 由於Java沒有Class多重繼承,為了讓物件具有多種型態,可以用Interface(介面)的達到多重繼承的需求。 2. 介面方法宣告預設都是"public",有沒有加public預設仍是public。 3. 介面宣告預設都是abstract,有沒有加abstract預設仍是abstract。 4. 當定義類別時,可以使用"implements"關鍵字來指定要實作哪個介面,介面中所有定義的方法都要實作。 5. 由於介面中的方法預設都是public,所以實作介面的類別中,方法必須宣告為public,否則無法通過編譯。
public interface IRequest { public abstract void execute(); // 可以用 void execute(); 省略public或abstract,其意義相同。 }
public class HelloRequest implements IRequest { private String name; public HelloRequest(String name) { this.name = name; } public void execute() { System.out.printf("Hello! %s!%n", name); } }
實作多個介面的方式: public class 類別名稱 implements 介面1, 介面2, 介面3 { // 介面實作 }
介面進行繼承的方式: public interface 名稱 extends 介面1, 介面2 { // ... }
$ gcc -v Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs Configured with: /managed/gcc-build/final-v3-bootstrap/gcc-3.4.4-999/configure --verbose --program-suffix=-3 --prefix=/usr --exec-prefix=/us r --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d ,f77,pascal,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-j ava-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registr y --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug Thread model: posix gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) $ make -v GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for i686-pc-cygwin
在最後一行後加入下面四行,然後存檔: PATH=/android-ndk-r5:${PATH} NDK_ROOT=/android-ndk-r5 NDK_Sample=/android-ndk-r5/samples export PATH NDK_ROOT NDK_Sample (NDK_Sample是指定你的JNI程式所要放置的目錄,這邊我我指定到/android-ndk-r5/samples,這個參數會在Eclipse的C編譯中使用到。)
vince_huang@VinceH-DT ~ $ cd /android-ndk-r5/samples/hello-jni/ vince_huang@VinceH-DT /android-ndk-r5/samples/hello-jni $ ndk-build Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver Gdbsetup : libs/armeabi/gdb.setup Install : libhello-jni.so => libs/armeabi/libhello-jni.so
String[] projection = new String[] { Images.ImageColumns._ID, Images.ImageColumns.BUCKET_DISPLAY_NAME, Images.ImageColumns.BUCKET_ID, Images.ImageColumns.DATE_TAKEN, Images.ImageColumns.DESCRIPTION, Images.ImageColumns.IS_PRIVATE, Images.ImageColumns.LATITUDE, Images.ImageColumns.LONGITUDE, Images.ImageColumns.MINI_THUMB_MAGIC, Images.ImageColumns.ORIENTATION, Images.ImageColumns.PICASA_ID, Images.ImageColumns.DATA, Images.ImageColumns.DATE_ADDED, Images.ImageColumns.DATE_MODIFIED, Images.ImageColumns.DISPLAY_NAME, Images.ImageColumns.MIME_TYPE, Images.ImageColumns.SIZE, Images.ImageColumns.TITLE }; // We can use the following query method to query data. //Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null); Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null); int count = cursor.getCount(); System.out.println("count = " + count); for (int i=0; i<count; i++) { cursor.moveToPosition(i); int columnSize = cursor.getColumnCount(); for (int j=0; j<columnsize; j++) { System.out.println("index = " + j + " " + cursor.getColumnName(j) + " = " + cursor.getString(j)); } }
Constructor: Creates a new ThreadPoolExecutor with the given initial parameters and default thread factory and handler. ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueueworkQueue)
import java.util.concurrent.*; import java.util.*; class MyThreadPoolExecutor { int poolSize = 2; int maxPoolSize = 2; long keepAliveTime = 10; ThreadPoolExecutor threadPool = null; final ArrayBlockingQueueReference:queue = new ArrayBlockingQueue ( 5); public MyThreadPoolExecutor() { threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, queue); } public void runTask(Runnable task) { // System.out.println("Task count.."+threadPool.getTaskCount() ); // System.out.println("Queue Size before assigning the // task.."+queue.size() ); threadPool.execute(task); // System.out.println("Queue Size after assigning the // task.."+queue.size() ); // System.out.println("Pool Size after assigning the // task.."+threadPool.getActiveCount() ); // System.out.println("Task count.."+threadPool.getTaskCount() ); System.out.println("Task count.." + queue.size()); } public void shutDown() { threadPool.shutdown(); } public static void main(String args[]) { MyThreadPoolExecutor mtpe = new MyThreadPoolExecutor(); // start first one mtpe.runTask(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { try { System.out.println("First Task"); Thread.sleep(1000); } catch (InterruptedException ie) { } } } }); // start second one /* * try{ Thread.sleep(500); }catch(InterruptedException * ie){} */ mtpe.runTask(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { try { System.out.println("Second Task"); Thread.sleep(1000); } catch (InterruptedException ie) { } } } }); // start third one /* * try{ Thread.sleep(500); }catch(InterruptedException * ie){} */ mtpe.runTask(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { try { System.out.println("Third Task"); Thread.sleep(1000); } catch (InterruptedException ie) { } } } }); // start fourth one /* * try{ Thread.sleep(500); }catch(InterruptedException * ie){} */ mtpe.runTask(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { try { System.out.println("Fourth Task"); Thread.sleep(1000); } catch (InterruptedException ie) { } } } }); // start fifth one /* * try{ Thread.sleep(500); }catch(InterruptedException * ie){} */ mtpe.runTask(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { try { System.out.println("Fifth Task"); Thread.sleep(1000); } catch (InterruptedException ie) { } } } }); // start Sixth one /* * try{ Thread.sleep(500); }catch(InterruptedException * ie){} */ mtpe.runTask(new Runnable() { public void run() { for (int i = 0; i < 10; i++) { try { System.out.println("Sixth Task"); Thread.sleep(1000); } catch (InterruptedException ie) { } } } }); mtpe.shutDown(); } }