- 博客(22)
- 收藏
- 关注
原创 JDBC
1//import java.sql.Connection;//import java.sql.DriverManager;import java.sql.*;//import javax.sql.ConnectionEvent;//import com.mysql.jdbc.Driver;/* 步骤1. 注册驱动. 告知jvm使用的是哪一个数据库的驱动2. 获得连接. 使用...
2018-02-23 23:01:07
170
原创 锁
lockimport java.util.concurrent.locks.*;/*lock*/class ProducerConsumerDemo2 { public static void main(String[] args) { Resource r = new Resource(); Producer p = new Producer(r); Consumer
2018-01-31 16:28:03
121
原创 多线程等待 唤醒
1class Res { private String sex; private String name; private boolean flag = false; public synchronized void set(String name,String sex) { if(flag) try{this.wait();} catch(Exception e) {}
2018-01-30 13:25:17
167
原创 多线程
继承Thread类方式创建多线程class ThreadDemo { public static void main(String[] args) { Demo d = new Demo("线程1"); Demo2 d1 = new Demo2("线程2"); d1.start(); d.start(); for(int x = 0; x <30; x++)
2018-01-29 19:36:13
119
原创 配置合并打印 存储对象
c配置import java.io.*;import java.util.*;/*Properties是hashtable的子类 具备map集合的特点与IO相结合的集合容器存储的是字符串的键值对配置文件*/class PropertiesDemo { public static void main(String[] args) throws IOException
2018-01-27 14:01:30
103
原创 File
1import java.io.*;class FileDemo { public static void main(String[] args) { consMethod(); } public static void consMethod() { //File.separator 跨平台分隔符 File f = new File("c:"+File.separa
2018-01-26 14:15:34
150
原创 IO2
FileOutputStream 从流中输出 对应的是FileReader 将流中的字符读取FileInputStream 输入到流里 对应的是 FileWriter 将字符写入到流import java.io.*;class OutputDemo { public static void main(String[] args) throws IOException {
2018-01-23 21:24:02
300
原创 IO
创建文件import java.io.*;class Demo2 { public static void main(String[] args) { FileWriter fw = null; try { fw = new FileWriter("demo.txt"); fw.write("xxxx"); } catch (IOException e) {
2018-01-21 20:41:35
181
原创 AWT
import java.awt.*;import static java.awt.BorderLayout.*;class BorderLayoutDemo { public static void main(String[] args) { Frame f = new Frame("第二个"); f.setLayout(new BorderLayout(30,5)); f
2018-01-07 18:39:37
144
原创 异常
异常class ExceptionDemo { public static void main(String[] args) { Demo d = new Demo(); try{ int x = d.div(4,0); System.out.println(x); } catch (Exception e){ System.out.println
2017-12-26 15:10:28
139
原创 Math类
基础及randomimport java.util.*;class Demo2 { public static void main(String[] args) { double d = Math.ceil(-111.2); //向上取整 double d1 = Math.floor(111.2); //向下取整 double i = Math.round(10.11); /
2017-12-23 15:38:49
145
原创 Calendar 类
zzzimport java.util.*;import java.text.*;class Demo { public static void main(String[] args) { Calendar c = Calendar.getInstance(); Scanner sc = new Scanner(System.in); int x = 0; whi
2017-12-23 13:46:16
108
原创 Collections工具类
import java.util.*;class CollectionsDemo { public static void main(String[] args) { List lt=new ArrayList(); lt.add("a"); lt.add("bb"); lt.add("zzzzz"); lt.add("qqq"); lt.add("ccc"
2017-12-20 14:21:59
134
原创 map3
zzzzzimport java.util.*;class Demo2 { public static void main(String[] args) { Map> mp1 =new HashMap>(); HashMap mp21=new HashMap(); HashMap mp22=new HashMap(); mp1.put(
2017-12-06 20:14:15
471
原创 map2
zzzzimport java.util.*;class Demo2 { public static void main(String[] args) { Map mp=new HashMap(); mp.put(new Student("lisi",10),"hangzhou"); mp.put(new Student("wangwu",11),"shangha
2017-12-02 17:55:09
211
原创 泛型2
import java.util.*;class Demo { public static void main(String[] args) { TreeSet ts=new TreeSet(new Comp()); ts.add(new Student("zhangsan1")); ts.add(new Student("lisi2")); ts.add(new Studen
2017-11-27 20:42:27
126
原创 泛型
泛型是一种安全机制,将运行时期的异常转移到编译时期。可以使代码更加简洁,更加健壮。在定义类,方法,接口时使用类型形参。public class Demo4 { public static void main(String[] args){ Utils u=new Utils(); u.setObject(new Worker()); Worker w=u.getObject();/
2017-11-26 14:06:40
124
原创 map
zzzzzzzzzimport java.util.*;class Demo { public static void main(String[] args) { Map m=new HashMap(); m.put("key1",1); m.put("key2",2); m.put("key3",3); sop(m.containsKey("key1"));
2017-11-22 17:29:38
143
原创 TreeSet比较器
import java.util.*;/*TreeSet是有序的 在存入对象的过程中,要定义按照什么来排序存入的类要实现一个Comparable接口 方法compareTo 大于 返回正数 小于 返回负数 等于 返回零*/public class Demo { public static void main(String[] args) { TreeS
2017-11-20 20:15:45
266
原创 TreeSet
TreeSet集合底层是二叉树数据结构,本身具有比较性,要实现Comparable接口 重写compareTo方法import java.util.*;/*TreeSet是有序的 在存入对象的过程中,要定义按照什么来排序存入的类要实现一个Comparable接口 方法compareTo 大于 返回正数 小于 返回负数 等于 返回零*/public class
2017-11-20 18:51:38
129
原创 HashSet
HashSet通过 HashSet()和equals()方法来比较对象是否相同。先比较Hash值 再用equals方法。在HashSet集合中存储对象时,需要重写这个类的HashSet()和equals()方法import java.util.*;class HashSetTest { public static void sop(Object obj) { System
2017-11-18 19:02:30
114
原创 ArrayList
import java.util.*;class Person{ private String name; private int age; Person(){}; Person(String name,int age) { this.name=name; this.age=age; } public boolean equals(Object obj) //重
2017-11-18 16:47:00
143
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人