This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Father {} | |
| class Child extends Father {} | |
| public class Test { | |
| public static void main(String args[]){ | |
| Class<Child> cClass = Child.class; | |
| Class<? super Child> fClass = cClass.getSuperclass(); | |
| // This won't compile | |
| // Class<Father> father = fClass.newInstance(); | |
| //only produces Object: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdio.h" | |
| #include "string" | |
| //宏定义方法,注意括号 | |
| #define MAX(x,y) ((x)>(y) ? (x) :(y)) | |
| #define IS_EVEN(n) ((n)%2==0) | |
| char * invalidPointer(){ | |
| char a[100]; //栈内变量,函数返回后消亡 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| long int Fib(int N){ | |
| if(N<=1) | |
| return 1; | |
| else{ | |
| return Fib(N-1)+Fib(N-2); | |
| } | |
| } | |
| /** | |
| running time of Fib(N): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdio.h" | |
| #include "math.h" | |
| #define MAX 100000000 | |
| int prime[MAX]; //在堆上,自动初始化为0 | |
| void initPrimes(){ | |
| int i, j; | |
| prime[0] = prime[1] = -1; // not prime number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.concurrent.Callable; | |
| import java.util.concurrent.ExecutionException; | |
| import java.util.concurrent.ExecutorService; | |
| import java.util.concurrent.Executors; | |
| import java.util.concurrent.Future; | |
| public class CallableAndFuture { | |
| /** | |
| * @param args |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ThreeThread { | |
| public static Long count = new Long(0); | |
| public static void main(String args[]) { | |
| for (int i = 0; i < 3; i++) { | |
| Thread t = new Thread() { | |
| @Override | |
| public void run() { | |
| int c = 3; | |
| while (c>0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mine.old.staff; | |
| public class Fib { | |
| static final int MAX = 93; | |
| static long[] f = new long[MAX]; | |
| static { | |
| f[0] = 0; | |
| f[2] = f[1] = 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int MaxSum(int* a,int n) | |
| { | |
| int i=0, maxSum=1<<31, sum=0; | |
| while(i<n){ | |
| sum += a[i++]; | |
| if(sum>maxSum) | |
| maxSum = sum; | |
| if(sum<0) | |
| sum = 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // more smarter way to solve overflow problem | |
| int StrToInt(const char* str) | |
| { | |
| //int maxAbs=((unsigned int)~0)>>1,maxAbsDiv=maxAbs/10, maxAbsRem=maxAbs%10; | |
| int maxAbs=0x7FFFFFFF,maxAbsDiv=maxAbs/10, maxAbsRem=maxAbs%10; | |
| int val=0, i=0, sign=1; | |
| while(str[i]==' ') | |
| i++; | |
| if(str[i]=='-' || str[i]=='+'){ | |
| if(str[i]=='-'){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mine.code.snippet.db; | |
| import java.io.File; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import com.sleepycat.je.Cursor; | |
| import com.sleepycat.je.Database; | |
| import com.sleepycat.je.DatabaseConfig; | |
| import com.sleepycat.je.DatabaseEntry; |