随笔分类 -  Java之旅

正式开始学java
摘要:1 import java.util.Comparator; 2 class Student { 3 private String name; 4 private int age; 5 public Student(String name,int age){ 6 this.name=name; 7 this.age=age; 8 } 9 public boolean equals(Object obj){10 if(this==obj){11 return true;12 ... 阅读全文
posted @ 2012-03-16 21:29 谈笑风生膜法师 阅读(2450) 评论(0) 推荐(0)
摘要:1 class BinaryTree{ 2 class Node{ 3 private Comparable data; 4 private Node left; 5 private Node right; 6 public void addNode(Node newNode){ 7 if(newNode.data.compareTo(this.data)<0){ 8 if(this.left==null){ 9 this.l... 阅读全文
posted @ 2012-03-15 21:04 谈笑风生膜法师 阅读(1644) 评论(0) 推荐(0)
摘要:1 import java.util.*; 2 public class BigIntDemo { 3 public static void main(String[] args) { 4 int t[]={3,5,6,7,34,23,2}; 5 Arrays.sort(t);//数组排序 6 System.out.print("排序后的数组"); 7 System.out.println(Arrays.toString(t)); 8 int point=Arrays.binarySearch(t, 2... 阅读全文
posted @ 2012-03-15 20:37 谈笑风生膜法师 阅读(640) 评论(0) 推荐(0)
摘要:1 import java.util.Date; 2 import java.text.SimpleDateFormat; 3 class DateTime{ 4 private SimpleDateFormat sdf=null; 5 public String getDate(){ 6 this.sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); 7 return this.sdf.format(new Date()); 8 } 9 public String getDa... 阅读全文
posted @ 2012-03-15 19:52 谈笑风生膜法师 阅读(7388) 评论(0) 推荐(0)
摘要:1 import java.util.Date; 2 import java.text.ParseException; 3 import java.text.SimpleDateFormat; 4 public class systemdemo { 5 public static void main(String[] args) { 6 String strDate="2008-10-19 10:11:30.345";//定义日期时间的字符串 7 String pat1="yyyy-MM-dd HH:mm:ss.SSSS";//准备第一个模板,提取日期. 阅读全文
posted @ 2012-03-15 19:28 谈笑风生膜法师 阅读(362) 评论(0) 推荐(0)
摘要:1 import java.util.Date; 2 import java.text.DateFormat; 3 public class systemdemo { 4 public static void main(String[] args) { 5 DateFormat df1=null; 6 DateFormat df2=null; 7 df1=DateFormat.getDateInstance(); 8 df2=DateFormat.getDateTimeInstance(); 9 Syst... 阅读全文
posted @ 2012-03-15 19:02 谈笑风生膜法师 阅读(840) 评论(0) 推荐(0)
摘要:1 import java.util.Calendar; 2 import java.util.GregorianCalendar; 3 public class systemdemo { 4 public static void main(String[] args) { 5 Calendar calendar=null; 6 calendar =new GregorianCalendar();//子类实例化 7 System.out.println("年: "+calendar.get(Calendar.YEAR)); 8 ... 阅读全文
posted @ 2012-03-15 18:57 谈笑风生膜法师 阅读(8034) 评论(0) 推荐(0)
摘要:1 public class systemdemo {2 public static void main(String[] args) {3 System.out.println("系统版本为:"+System.getProperty("os.name")+System.getProperty("os.version")+System.getProperty("os.arch"));4 System.out.println("系统用户为:"+System.getProperty("us 阅读全文
posted @ 2012-03-15 18:42 谈笑风生膜法师 阅读(242) 评论(0) 推荐(0)
摘要:1 public class systemdemo { 2 public static void main(String[] args) { 3 long startTime=System.currentTimeMillis(); 4 int sum=0; 5 for(int i=0;i<999999999;i++){ 6 sum+=i; 7 } 8 long endTime=System.currentTimeMillis(); 9 System.out.prin... 阅读全文
posted @ 2012-03-15 18:30 谈笑风生膜法师 阅读(637) 评论(0) 推荐(0)
摘要:1 class Info<T,V>{ 2 private T var; 3 private V value; 4 public Info(T var,V value){ 5 this.setVar(var); 6 this.setValue(value); 7 } 8 public T getVar() { 9 return var;10 }11 public void setVar(T var) {12 this.var = var;13 }14 publ... 阅读全文
posted @ 2012-03-14 21:00 谈笑风生膜法师 阅读(2830) 评论(0) 推荐(0)
摘要:1 class Info<T>{ 2 private T var; 3 public T getVar(){ 4 return var; 5 } 6 public void setVar(T var){ 7 this.var=var; 8 } 9 public String toString(){10 return this.var.toString();11 }12 }13 public class Generics... 阅读全文
posted @ 2012-03-14 20:44 谈笑风生膜法师 阅读(361) 评论(0) 推荐(0)
摘要:1 class Demo{ 2 public <T> T fun(T t){ 3 return t; 4 } 5 } 6 public class GenericsDemo { 7 public static void main(String[] args) { 8 Demo d=new Demo(); 9 String str=d.fun("hsjkdka");10 int i=d.fun(30);11 System.out.println(str);12 System.... 阅读全文
posted @ 2012-03-14 20:21 谈笑风生膜法师 阅读(3680) 评论(0) 推荐(0)
摘要:1 interface Info<T>{ 2 public T getVar(); 3 } 4 class Infolmpl implements info<String>{ 5 private String var; 6 public Infolmpl(String Var){ 7 this.setVar(var); 8 } 9 public void setVar(String var){10 this.var=var;11 }12 public String getVar(){... 阅读全文
posted @ 2012-03-14 20:20 谈笑风生膜法师 阅读(7015) 评论(0) 推荐(0)
摘要:1 class NotePad<K,V>{ 2 private K key; 3 private V value; 4 public K getKey() { 5 return key; 6 } 7 public void setKey(K key) { 8 this.key = key; 9 }10 public V getValue() {11 return value;12 }13 public void setValue(V value) {14 ... 阅读全文
posted @ 2012-03-14 19:34 谈笑风生膜法师 阅读(7706) 评论(0) 推荐(0)
摘要:1 class MyThreadA implements Runnable{ 2 private boolean flag=true; 3 public void run(){ 4 int i=0; 5 while(this.flag){ 6 while(true){ 7 System.out.println(Thread.currentThread().getName()+"运行,i="+(i++)); 8 } 9 }10 }11 }12 ... 阅读全文
posted @ 2012-03-13 21:05 谈笑风生膜法师 阅读(292) 评论(0) 推荐(0)
摘要:1 class MyThread implements Runnable{ 2 private boolean flag=true; 3 public void run(){ 4 int i=0; 5 while(this.flag){ 6 while(true){ 7 System.out.println(Thread.currentThread().getName()+"运行,i="+(i++)); 8 } 9 }10 }11 p... 阅读全文
posted @ 2012-03-13 20:49 谈笑风生膜法师 阅读(286) 评论(0) 推荐(0)
摘要:1 class ZhangSan{ 2 public void say(){ 3 System.out.println("Zhang said:you should lend your painting to me!"); 4 } 5 public void get(){ 6 System.out.println("Zhang has got it!"); 7 } 8 } 9 class LiSi{10 public void say(){11 System.out.println("Li said:yo... 阅读全文
posted @ 2012-03-13 20:06 谈笑风生膜法师 阅读(450) 评论(0) 推荐(0)
摘要:1 class MyThread implements Runnable{ 2 private int ticket=5; 3 public void run(){ 4 for(int i=0;i<100;i++){ 5 synchronized (this){ 6 if(ticket>0){ 7 try{ 8 Thread.sleep(300); 9 }catch(Interr... 阅读全文
posted @ 2012-03-13 19:47 谈笑风生膜法师 阅读(543) 评论(4) 推荐(0)
摘要:1 class MyThread implements Runnable{ 2 public void run(){ 3 for(int i=0;i<5;i++){ 4 try { 5 Thread.sleep(500); 6 } catch (Exception e){ 7 } 8 System.out.println(Thread.currentThread().getName()+"运行,i="+i); 9 }10 }11 }12 pu... 阅读全文
posted @ 2012-03-12 20:53 谈笑风生膜法师 阅读(280) 评论(0) 推荐(0)
摘要:1 class MyThread implements Runnable{ 2 private String name; 3 public MyThread(String name){ 4 this.name=name; 5 } 6 public void run(){ 7 for(int i=0;i<10;i++){ 8 System.out.println(name+" 运行,i="+i); 9 }10 }11 }12 public class ThreadDemo {13 ... 阅读全文
posted @ 2012-03-12 19:51 谈笑风生膜法师 阅读(294) 评论(0) 推荐(0)