Java代码大全,求Java的程序代码

1,求Java的程序代码public class Test extend Threadpublic static void main(String[] args)int i=0;while(i<Integer.MAX_VALUE)System.out.println("第“+i+”秒");i++;sleep(1000);}}}我来翻译下嘿嘿public class Testpublic static void main(String[] args)System.out.println("Hello word!!!");//输出语句嘿嘿 }}public class Testpublic static void main(String[] args)System.out.println("Hello word!!!"); }}
2,java线程的经典代码package threadgroup;class ThreadDemo3 extends Threadprivate String name; private int delay; public ThreadDemo3(String sname, int i_delay)name = sname; delay = i_delay; } public void run()trysleep(delay); } catch (InterruptedException e)} System.out.println("多线程测试!\n" + name + "\n" + delay); } } public class testMyThreadpublic static void main(String[] args)ThreadDemo3 th1,th2,th3; th1 = new ThreadDemo3("线程1", (int) (Math.random() * 900)); th2 = new ThreadDemo3("线程2", (int) (Math.random() * 900)); th3 = new ThreadDemo3("线程3", (int) (Math.random() * 900)); th1.start(); th2.start(); th3.start(); } } package threadgroup;public class threadDemopublic static void main(String[] args)Thread t = Thread.currentThread(); t.setName("你好吗?"); System.out.println("正在进行的Thread是:" + t); tryfor (int i = 0; i &lt; 5; i++)System.out.println("我不叫穆继超" + i); Thread.sleep(3000); } } catch (Exception e)// TODO: handle exception System.out.println("Thread has wrong" + e.getMessage()); } }}package threadgroup;public class threadDemo2 implements Runnablepublic threadDemo2()Thread t1 = Thread.currentThread(); t1.setName("第一个主进程"); System.out.println("正在运行" + t1); Thread t2 = new Thread(this, ""); System.out.println("在创建一个进程"); t2.start(); trySystem.out.println("使他进入第一个睡眠状态"); Thread.sleep(2000); } catch (InterruptedException e)System.out.println("Thread has wrong" + e.getMessage()); } System.out.println("退出第一个进程"); } public void run()tryfor (int i = 0; i &lt; 5; i++)System.out.println("进程" + i); Thread.sleep(3000); } } catch (InterruptedException e)// TODO: handle exception System.out.println("Thread has wrong" + e.getMessage()); } System.out.println("退出第二个进程"); } public static void main(String[] args)new threadDemo2(); }}【Java代码大全,求Java的程序代码】
3 , 求Java程序代码// 反射import java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;public class TTpublic void sayHelloWorld()System.out.println("hello word");}public static void main(String[] args)Class c = TT.class;tryObject obj = c.newInstance();Method m = c.getMethod("sayHelloWorld");m.invoke(obj,null);} catch (Exception e)e.printStackTrace();}}}// 动态代理import java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;import java.lang.reflect.Proxy;public class HelloWord implements IHWpublic void sayHelloWorld()}public static void main(String[] args)HelloWord hw = new HelloWord();InvocationHandler handler = new HelloWordHandler(hw);IHW proxy = (IHW) Proxy.newProxyInstance(hw.getClass().getClassLoader(), hw.getClass().getInterfaces(),handler);proxy.sayHelloWorld();}}interface IHWvoid sayHelloWorld();}class HelloWordHandler implements InvocationHandlerprivate Object objOriginal;public HelloWordHandler(Object obj)this.objOriginal = obj;}public Object invoke(Object proxy, Method method, Object[] args)throws ThrowableObject result;doBefore();result = method.invoke(this.objOriginal, args);return result;}private void doBefore()System.out.println("hello word");}}/// 还有一个就是用EJB去写 , 这个我不会 。public class Testpublic static void main(String[] args)String[] s=new String[] StringBuffer str=new StringBuffer(); for(int i=0;i<s.length;i++) str.append(s[i]); } System.out.println(str); }}---------------------------------------------------------------------------------------------------------------------------package test;import java.util.HashMap;import java.util.Set;public class Testpublic static void main(String[] args)HashMap<Integer, String> map=new HashMap<Integer, String>(); map.put(1, "H"); map.put(2, "e"); map.put(3, "l"); map.put(4, "l"); map.put(5, "o"); map.put(6, " "); map.put(7, "W"); map.put(8, "o"); map.put(9, "r"); map.put(10, "d"); Set<Integer> set=map.keySet(); for(Integer key:set) System.out.print(map.get(key)); } }}-----------------------------------------------------------------------------------------------//先写个hello.txt文件,放在某个文件夹下 , 比如F:\下面,里面的内容为Hello Wordpackage test;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;public class Testpublic static void main(String[] args)FileInputStream fis = null; BufferedReader br = null; tryfis = new FileInputStream("F:/hello.txt"); br = new BufferedReader(new InputStreamReader(fis)); String str = null; trywhile ((str = br.readLine()) != null)System.out.println(str); } } catch (IOException e)e.printStackTrace(); } } catch (FileNotFoundException e)e.printStackTrace(); } }}瞎写了3种,这种题目变态这是什么变态题目,出题目的脑子有问题 。。

    推荐阅读