随笔分类 -  Java之旅

正式开始学java
摘要:View Code 1 class MyThread extends Thread{ 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 {... 阅读全文
posted @ 2012-03-12 19:40 谈笑风生膜法师 阅读(165) 评论(0) 推荐(0)
摘要:1 package hjwPackage; 2 3 public class hjwClass { 4 public static int add(int i,int j){ 5 return i+j; 6 } 7 public static int sub(int i,int j){ 8 return i-j; 9 }10 public static int mul(int i,int j){11 return i*j;12 }13 public static int div(int ... 阅读全文
posted @ 2012-03-11 21:01 谈笑风生膜法师 阅读(192) 评论(0) 推荐(0)
摘要:1 class MyException extends Exception{ 2 public MyException(String msg){ 3 super(msg); 4 } 5 } 6 public class ThrowsDemo { 7 public static void main(String args[]){ 8 try{ 9 throw new MyException("自定义异常"); 10 }catch (Exception e){11 ... 阅读全文
posted @ 2012-03-11 19:36 谈笑风生膜法师 阅读(250) 评论(0) 推荐(0)
摘要:1 class Math{ 2 public int div(int i,int j) throws Exception{ 3 System.out.println("========计算开始======="); 4 int temp=0; 5 try{ 6 temp=i%j; 7 } catch(Exception e){ 8 throw e; 9 } finally{10 System.out.println("=========... 阅读全文
posted @ 2012-03-11 19:29 谈笑风生膜法师 阅读(179) 评论(0) 推荐(0)
摘要:View Code 1 class Math{ 2 public int div(int i,int j) throws Exception{ 3 int t=i/j; 4 return t; 5 } 6 } 7 public class ThrowsDemo { 8 public static void main(String args[]) throws Exception{ 9 Math m=new Math();10 System.out.println("出发操作:"+m.div(10,2));... 阅读全文
posted @ 2012-03-11 19:18 谈笑风生膜法师 阅读(263) 评论(0) 推荐(0)
摘要:1 public class ObjectDemo { 2 public static void main(String[] args) { 3 String str1="30"; 4 String str2="30.3"; 5 int x=Integer.parseInt(str1); 6 float f=Float.parseFloat(str2); 7 System.out.println("整数乘方"+x+"*"+x+"="+(x*x)); 8 System.out.println... 阅读全文
posted @ 2012-03-07 21:25 谈笑风生膜法师 阅读(348) 评论(0) 推荐(0)
摘要:1 class Person{ 2 private String name; 3 private int age; 4 public Person(String name,int age){ 5 this.name=name; 6 this.age=age; 7 } 8 public boolean equals(Object obj){ 9 if(this==obj)//地址相等?10 return true;11 if(!(obj instanceof Pers... 阅读全文
posted @ 2012-03-07 21:08 谈笑风生膜法师 阅读(277) 评论(0) 推荐(0)
摘要:1 import java.util.Scanner; 2 3 interface Pet{ 4 public int getAge(); 5 public String getColor(); 6 public String getName(); 7 } 8 9 class Cat implements Pet{ 10 private String name; 11 private String color; 12 private int age; 13 public Cat(String name,String... 阅读全文
posted @ 2012-03-07 20:51 谈笑风生膜法师 阅读(457) 评论(0) 推荐(0)
摘要:View Code 1 interface USB{ 2 public void start(); 3 public void stop(); 4 } 5 class Computer{ 6 public static void plugin(USB usb){ 7 usb.start(); 8 System.out.println("=========USB device is working======"); 9 usb.stop();10 }11 };12 class Flash implements US... 阅读全文
posted @ 2012-03-06 20:55 谈笑风生膜法师 阅读(345) 评论(0) 推荐(0)
摘要:View Code 1 class A{ 2 public void fun1(){ 3 System.out.println("fun1-----"); 4 } 5 public void fun2(){ 6 this.fun1(); 7 } 8 }; 9 class B extends A{10 public void fun1(){11 System.out.println("fun1-----覆写");12 }13 public void fun3(){14 Sys... 阅读全文
posted @ 2012-03-06 20:19 谈笑风生膜法师 阅读(481) 评论(0) 推荐(0)
摘要:View Code 1 class A{ 2 public void fun1(){ 3 System.out.println("fun1-----"); 4 } 5 public void fun2(){ 6 this.fun1(); 7 } 8 }; 9 class B extends A{10 public void fun1(){11 System.out.println("fun1-----覆写");12 }13 public void fun2(){14 Sys... 阅读全文
posted @ 2012-03-06 19:42 谈笑风生膜法师 阅读(269) 评论(0) 推荐(0)
摘要:1.栈内存保存的是堆内存空间的访问地址。2.一个栈内存空间只能指向一个堆内存空间。3.匿名对象就是已经开辟了的堆内存空间的并可以直接使用的对象。4.字符串的内容不可改变。5.this调用构造方法必须放在构造方法的首行。6.非static声明的方法可以调用static类型的方法,但static类型的不能调用非static类型的方法。7.equals比较的是两个字符串的地址值。8.子类对象实例化之前必须先调用父类中的构造方法。9.接口的实际应用是指定标准,抽象类的实际应用是模板设计。10.Object类是所有对象的父类,可以接收任意的引用数据类型。11.多个线程共享同一资源需同步,但过多的同步会造 阅读全文
posted @ 2012-03-05 20:29 谈笑风生膜法师 阅读(409) 评论(0) 推荐(1)