死锁的应用

public class TestDeadLock{ public static void main(String args[]){ StringBuffer sb = new StringBuffer("ABCD"); MyThread t = new MyThread(sb); t.start(); synchronized(sb){ try{ t.join(); }catch(InterruptedException e){ ...
线程 | 2010-05-23 20:06 | 阅读 954 次 | 评论 0 条

栈的实用实例

class Stack{ int idx=0; char[ ] data = new char[6]; public void push(char c){ data[idx] = c; System.out.print("压入字符" + c + "->"); //p1 idx++; System.out.println("->压入" + c + "操作完成!"); } public char pop(){ idx--; return data[idx];...
线程 | 2010-05-23 19:53 | 阅读 985 次 | 评论 1 条

挂起和恢复的实例

import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Date;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JButton;public class TestSuspend{ public static void main(String[] args){ JFrame jf = new JFrame("T...
线程 | 2010-05-23 19:48 | 阅读 900 次 | 评论 0 条

yeild的应用实例

import java.util.Date;public class TestYield{ public static void main(String[] args){ Thread t1 = new MyThread(false); Thread t2 = new MyThread(true); Thread t3 = new MyThread(false); t1.start(); t2.start(); t3.start(); } }class MyThread extend...
线程 | 2010-05-23 19:36 | 阅读 952 次 | 评论 0 条

Calendar 获得当前时间

public String getTime(){ Calendar c = new GregorianCalendar(); String time = c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DATE) + " " ; int h = c.get(Calendar.HOUR_OF_DAY); int m = c.g...
专业文章 | 2010-05-23 19:30 | 阅读 1066 次 | 评论 0 条

线程的串行化

public class TestJoin { public static void main(String args[]){ MyRunner r = new MyRunner(); Thread t = new Thread(r); t.start(); try{ t.join(); }catch(InterruptedException e){ e.printStackTrace(); } for(int i=0;i<50;...
线程 | 2010-05-23 19:24 | 阅读 801 次 | 评论 0 条

线程优先级实例

public class TestPriority { public static void main(String args[]){ System.out.println("线程名\t优先级"); Thread current = Thread.currentThread(); System.out.print(current.getName() + "\t"); System.out.println(current.getPriority()); Thread t1 = new R...
线程 | 2010-05-23 19:19 | 阅读 961 次 | 评论 0 条

GUI实例

import java.awt.*;import java.awt.event.*;public class TestGUIThread { public static void main(String args[]) throws Exception{ Frame f = new Frame(); Button b = new Button("Press Me!"); MyMonitor mm = new MyMonitor(); b.addActionListener(mm); f...
线程 | 2010-05-23 19:10 | 阅读 957 次 | 评论 0 条

后台线程实例

public class TestDaemonThread { public static void main(String args[]){ Thread t1 = new MyRunner(10); t1.setName("用户线程t1"); t1.start(); Thread t2 = new MyRunner(100); t2.setDaemon(true); t2.setName("后台线程t2"); t2.start(); ...
线程 | 2010-05-23 19:03 | 阅读 894 次 | 评论 0 条

线程实例1(如何创建和启动线程)

public class Test1 {//创建和启动线程 public static void main(String[] args) { //启动线程1 Thread1 t1=new Thread1(); t1.start(); //启动线程2 Thread2 t2=new Thread2(); Thread t2i=new Thread(t2); t2i.start(); }}//创建一个线程的第一种方式class Thread1 extends Thread{ public void run(){ ...
线程 | 2010-05-23 18:43 | 阅读 768 次 | 评论 0 条

java数据结构(集合)java数据结构内容整理

关键字: 数据结构 Collection:List、Set Map:HashMap、HashTable 如何在它们之间选择 一、Array , Arrays Java所有“存储及随机访问一连串对象”的做法,array是最有效率的一种。 1、 效率高,但容量固定且无法动态改变。 array还有一个缺点是,无法判断其中实际存有多少元素,length只是告诉我们array的容量。 2、Java中有一个Arrays类,专门用来操作array。 arrays中拥有一组static函数, equals():比较两个array是否相等。array拥有相同元素个数,且所有对应元素两两相等。...
集合 | 2010-05-23 00:16 | 阅读 1430 次 | 评论 0 条

ArrayList和LinkedList的用法区别

关键字: jdk 1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构。 2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList要移动指针。 3.对于新增和删除操作add和remove,LinedList比较占优势,因为ArrayList要移动数据。 这一点要看实际情况的。若只对单条数据插入或删除,ArrayList的速度反而优于LinkedList。但若是批量随机的插入删除数据,LinkedList的速度大大优于ArrayList. 因为ArrayList每插入一条数据,要移动插...
集合 | 2010-05-22 23:52 | 阅读 1388 次 | 评论 0 条

(转)Struts 2 + Spring 2.0 + Hibernate 3.0整合笔记

Struts 2 + Spring 2.0 + Hibernate 3.0整合笔记1. 添加Spring 2.0的Libraries选择以下4个jar,并配置到/WEB-INF/lib下Spring2.0 AOP LibrariesSpring2.0 Core LibrariesSpring2.0 Persistence Core LibrariesSpring2.0 WEb Libraries同时,将applicationContext.xml配置到WEB/INF下面。2. 添加Hibernate 3.0的Libraries选择以下2个jar,并配置到/WEB-INF/lib下Hibe...

I/O理论编

本次复习的是I/O(输入/出)(总体的复习) InputStream输入流/OutputStream输出流 Node Stream节点流 /Processing Stream处理流 Character Stream 字符流/Byte Stream字节流按照数据流动的方法:有输入流和输出流 输入流只能读取数据,不能写出数据 输出流只能写出数据,不能读入数据 除了RandomAccessFile类(即可读也可写)按照数据流所关联的...
I/O编 | 2010-05-21 20:07 | 阅读 1012 次 | 评论 0 条

TempFile临时文件的创建

import java.io.*;import java.awt.event.*;import javax.swing.*; public class TestTempFile implements ActionListener{ private File tempPath; public static void main(String args[]){ TestTempFile ttf = new TestTempFile(); ttf.init(); ttf.createUI(); } public void createUI(){ JFrame frame = new ...
集合 | 2010-05-21 16:01 | 阅读 869 次 | 评论 0 条

RadomAccessFile的应用

import java.io.File;import java.io.IOException;import java.io.RandomAccessFile;public class TestRandomAccessFile{ private File file; public static void main(String[] args){ TestRandomAccessFile traf = new TestRandomAccessFile(); traf.init(); traf.record("Billy",22); ...
I/O编 | 2010-05-21 15:55 | 阅读 1062 次 | 评论 0 条

错误信息和输出信息写到文件

import java.io.*;import java.util.Date;public class TestSetOutput{ public static void main(String[] args){ PrintStream ps = null; PrintStream ps_error = null; try{ ps = new PrintStream(new FileOutputStream("output.txt",true)); System.setOut(ps);//设置...
I/O编 | 2010-05-21 15:38 | 阅读 996 次 | 评论 0 条

重定向文件实例

import java.io.*;public class TestSetInput{ public static void main(String[] args){ try{ //FileInputStream fis = new FileInputStream("source.txt"); //System.setIn(fis); 如果取消了这里的,将在下面的System.io是文件中的内容 int avg = 0; int total = 0; ...
I/O编 | 2010-05-21 15:26 | 阅读 968 次 | 评论 0 条

CharArrayReader和CharArrayWriter实例

import java.io.*;public class TestCharArrayReader{ public static void main(String[] args){ char[] b = {'I',' ','a','m',' ','S','a','i','l','i','n','g','!'}; CharArrayReader car = new CharArrayReader(b); MyReader mr = new MyReader(); mr.getInfo(car); } }~...
I/O编 | 2010-05-21 15:19 | 阅读 1382 次 | 评论 0 条

DataInputStream和DataOutputStream实例

import java.io.*;public class Test{ public static void main(String args[]){ try{ FileOutputStream fos; DataOutputStream dos; FileInputStream fis; DataInputStream dis; fos = new FileOutputStream("myfile.data"); dos = new...
I/O编 | 2010-05-21 15:05 | 阅读 1002 次 | 评论 0 条
浏览274689次