注:因为图书馆的书到期要还了,可借来的java书都没翻过,上数据库课的时候,用了一节课翻子几十页,还倒是发现了一些以前为什么写一个程序遇到的那么多困难,看来,要学好JAVA还有漫长的路要走.只可惜现在我身在曹心在汉啊.嘎.希望这些对某人有所帮助...中等水平及高手就不要看了.
1.读取输入
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input1 = in.readLine(); //先放到String 中
double value1 = Double.valueOf(input1).doubleValue(); //类型转化
2.字符串转化成字符数组
String s = new String("ABCDE");
char[] a;
a = s.tocharArray(); //C语言倒是不用转化
3.String->int
int m; String n="123";
m = Integer.parseInt(n);
4.关于日期
导入:import java.util.Date;
Date date;
date = new Date(); //这样就可以得到当前计算机的日期了,而不用什么转化格式的.
5.小写转大写
String.toUpperCase(); //这个常用在switch 中. 输入的Y/y -> Y
6.接口相关
(1). implements InterfaceName
(2).是完全抽象类.所有方法为public abstract (?)
(3).若有成员变量必为常量.应定义为public static final[事实上默认也是如此]
7.包相关
(1)import语句放在package之后
(2)包访问控制 protected
8.抽象类
只有方法,且至少一个抽象方法,但没有常量。
9。输入输出I/O
(1)FilenameFilter接口提供了文件后缀过滤功能。
(2)写入文件
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Data.txt")));
out.writeDouble(3.1415926);
out.writeBytes("You are a good student. he..he ..");
out.close(); //居然要close(),我有点感到奇怪。。不过不close()更奇怪,文件是否会被独占?
(3)输出文件
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("Data.txt")));
BufferedReader inbr = new BufferedReader(new InputStreamReader(in));
System.out.println(in.readDouble());
System.out.println(inbr.readLine());
(4)还有FileWriter类的write()写文件。FileReader类的read()读文件。
(5)PrintWriter类在屏幕上显示文本文件内容。
(6)FileInputStream fin = new FileInputStream(new File("c:\\file.txt"));
int ch = fin.read(); //读取一个整数
10.监听
监听者类常实现ActionListener 接口的actionPerformed()方法?
PS: 有疑问的我记下问号.
浙公网安备 33010602011771号