07 2012 档案
摘要:网络编程基础 (Socket套接字) 在包java.net.*里面1.import java.net.*; //创建服务器端 import java.io.*; public class Helloworld1 {public static void main(String args[]) throws Exception { //创建服务器端和连接时,都会报异常 ServerSocket ss = new ServerSocket(6666); //创建服务器端,并且定义端口号为6666 (每个程序只能占用一个端口号) Boolean flag =true; //定义一个变量以便控制服务器.
阅读全文
摘要:写多线程的两种方法 (多线程) 之前写的程序都是单线程的(只有一条执行路径)1.public class Helloworld1 { //第一种方法(实现Runnable接口)更好,能继承,又能实现尽量实现(实现了之后,还能继承)public static void main(String args[]) { Thread t1 = new Thread(new T("t1")); Thread t2 = new Thread(new T("t2")); t1.start(); //只有Thread里面的start()方法,才叫做开启线程 t2.star
阅读全文
摘要:字节流的先输出后输入 (io流)import java.io.*;public class Helloworld1 {public static void main(String args[]) throws Exception { FileOutputStream fos = new FileOutputStream("d:/java/a.txt"); //new一个输出字节流对象,后面加上文件的路径 FileInputStream fis = new FileInputStream("d:/java/a.txt"); //new一个输入字节流对象,从
阅读全文
摘要:import java.util.*;public class Helloworld1 {public static void main(String args[]) {Set<String> set = new HashSet<String>(); //不加上<String>泛型会报不安全List<String> list = new ArrayList<String>();set.add("my"); //add()添加容器的内容set.add("name");set.add("i
阅读全文
摘要:打印文件的目录 (io下的File类)import java.io.*;public class Helloworld1 {public static void main(String args[]) {File file = new File("d:/aa");Helloworld1.show(file,1); //静态方法,类名调用}public static void show(File file,int level) {String str = ""; for(int i=1;i<level;i++) {str = str +"
阅读全文
摘要:打印1-10之间的随机数 (lang包底下的math类)1.public class Helloworld1 { //lang包里面的math类的random()方法public static void main(String args[]) { System.out.println(Math.floor(Math.random()*10)+1); //也可以(int)(Math.random()*10)+1或Math.ceil(Math.random()*10)}}2.import java.util.*; //util包里面的Random类的nextInt()方法 public class
阅读全文
摘要://一个字符串,大写字母个数,小写字母个数,其他字符个数(String类)public class Helloworld1 {public static void main(String args[]) { String str = "360 dazhan QQ"; int num2[] = new int[13]; for(int j=0;j<str.length();j++) { num2[j] = str.codePointAt(j); //将转化后的ASCII值,传给数组 } int a = 0; int b = 0; int c = 0; for(int k
阅读全文
摘要://数组的冒泡法排序 (数组)public class Helloworld1 {public static void main(String args[]) {int nums[] = new int[]{4,8,1,3,6,5,7,9,2};for(int j=0;j<nums.length-1;j++) { //j到j<nums.length-1结束,最后一个不需要比较for(int i=j+1;i<nums.length;i++) { //i从j+1开始循环if(nums[j]<nums[i]) {int temp = nums[i];nums[i] = num
阅读全文
摘要:接口(特殊的抽象类,里面只能有静态常量和抽象的方法,定义interface car)。public class Helloworld1 {public static void main(String args[]) { Bmw bmw = new Bmw(); bmw.stop(); bmw.run(); bmw.m(); bmw.n(); System.out.println(Car.name); //car的name是静态常量,只要用类名调用 }}interface A {public void m();}interface B {public void n();}interface Ca
阅读全文
摘要:抽象类(不需要创建他的对象),和抽象方法(不能有方法体,就是给别人重写的)注:抽象类既可以有抽象的方法,也可以有非抽象的方法。而有抽象方法的类,一定是抽象类。public class Helloworld1 {public static void main(String args[]) {Cat cat = new Cat();cat.name = "tom"; cat.enjoy();}}abstract class Animal { //加上abstract,抽象类String name;public void sleep() {System.out.println(n
阅读全文
摘要:父类的引用指向子类的对象(向上转型)的作用:良好的可扩展行(在给我们的软件增加一块功能或者删除一块功能的时候,应该不用修改程序的主体代码).也就是多态,实现代码的复用 (多态)public class Helloworld1 {public static void main(String args[]) {Cat cat = new Cat();cat.name = "tom";Dog dog = new Dog();dog.name = "jack";Person p = new Person();p.playWithAnimal(dog); //这里
阅读全文
摘要:父类的引用指向子类的对象,但是cat属于父类,所以Animal cat = new Cat()的cat对象,不能调用子类多出来的内容,比如这里的enjoy方法 (向上转型)public class Helloworld1 {public static void main(String args[]) {Animal cat = new Cat();cat.name = "tom";cat.sleep();}}class Animal {String name;public void sleep() {System.out.println(name+" is sle
阅读全文
摘要:所有的类都默认继承了Object类,但是如果是自己定义的类,建议重写里面的toString方法,不重写的话,打印的是类名+@+哈西码。String类自身重写了tostring(Object类)public class Helloworld1 {public static void main(String args[]) {Animal c = new Animal("jacky",20); System.out.println(c);}}class Animal {String name;int age = 10;public Animal(String name,int
阅读全文
摘要:1.super关键字,用于成员变量super.age 用于调用父类的方法super.d()public class Helloworld1 {public static void main(String args[]) {Cat c = new Cat("jacky",20);int m = c.m();System.out.println(m);}}class Animal {String name;int age = 10;public Animal(String name,int age) { this.name = name; this.age = age; } p
阅读全文
摘要:4.构造器还有一个作用,初始化成员变量public class Helloworld7 { public static void main(String args[]) { Person p1 = new Person("张三",19); Person p2 = new Person("李四",29); p1.m(p2); } } class Person { String name; int age; public Person(String name,int age) { this.name = name; this.age = age; } pub
阅读全文
摘要:public class Helloworld7 { public static void main(String args[]) { Person p1 = new Person("张三",19); Person p2 = new Person("李四",29); Hair h = new Hair("李四的一根头发"); p2.h = h; p1.m(p2.h); } } class Person { String name; int age; Hair h; public Person(String name,int age)
阅读全文
摘要:<html> <head> <title>注册页面表单</title> </head> <body> <form method="post" action=""> <table border="1" align="center" width="600" bgcolor="ffb7dd"> <tr align="center" bgcolor="#
阅读全文
摘要:条件查询:1.查询出工资大于1500的所有有雇员的信息select * from emp where sal>1500;2.查询每月可以拿到奖金的雇员的信息select * from emp where comm is not null;3.查询工资大于1500,并且可以拿到奖金的雇员的信息select * from emp where sal>1500 and comm is not null;4.查询工资不大于1500,并且不能拿到奖金的雇员的信息select * from emp where not(sal>1500 or comm is not null);5.查询基
阅读全文
摘要://先创主表,再创从表 先删从表,再删主表//论坛用户表create table bbs_user(user_id integer primary key, //没有id的,给他创建一个iduser_name varchar2(15) not null,user_password number(12) not null,user_email varchar2(20) check (user_email like '%@%'), //检查约束,%代表任意长度字符串,_代表一个字符,用likeuser_birthday Date,user_sex varchar2(3) check
阅读全文
浙公网安备 33010602011771号