1.在java中变量的作用域,当超出作用域后变量将失效,且每次进入作用域定义的变量都会被重新初始化。
如:
public class testscopeint{
public void static main(String args[]){
for ( int i=1;i<5;i++){
int y = 0;
System.out.println("y="+y);
y = y * i;
System.out.println("y="+y);
}
}
}
2.自动类型转换: 类型要兼容,且目标类型要大于源类型
public class varscope {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte b;
int i;
double f;
i = 265;
f = 325.323;
b = (byte)i;
System.out.println(i+" "+b);
b = (byte)f;
i = (int)f;
System.out.println(f+" "+i+" "+b);
}
}
看其结果是什么?
3.数组的定义
type 变量名,例如:int years[];
初始化:years = new int[10];
或
int years[] = new int[12];
问题:利用一个数组来计算平均数
int[] years; 这也是一种声明数组的方法
4.java中的字符串是对像 ×
5.% 模式运算符 24.32%10 = 4.32
6.位逻辑运算符:& | ^ ~ 与、或、非、异或
7.? 三值运算符 exp1?exp2:exp3;
8.switch语句
switch(exp){
case value1:
case value2:
default:
}
9.关于break跳出语句,它可以替代goto语句如下
public class breakgoto {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("这是一个测试break-goto的example");
first:{
System.out.println("first");
second:{
System.out.println("sencod");
for(int i=0;i<10;i++){
if(i>5) break second;
}
System.out.println("second after");
}
}
}
}
10.对像与类 class
class classname{
member1;
member2;
mothod1{
}
}
classname name1 = new classname();
new运算符的过程
上述解解为两步:
classname name1;
name1 = new classname();
11.给对像引用变量赋值
box mybox1;
box mybox2;
mybox1 =new box();
mybox2 = mybox1;
这里mybox1,mybox2共同指向同一个地址,但释放任何一个都不会影响对方。
mybox1.height=20;
mybox1 = null;
这时mybox2.height仍然为20
this关键字?
对像的重载,可以实现多态
12.参数是如何传递的
在java中参数有两种传递:一是按值传递 二是按引用传递
call by value call by reference
2008-09-23
类的继承
class A extends B{
}
private:继承子类不能访问,只有在类的内部成员才可以访问它。
super 必段是构造函数中的第一个条语句。
动态方法调度(dynamic method dispatch)是在运行时而不是在编译时调用重载方法的一种机制,这是java多态的重要特性(面向对像)
抽像类:abstract type classname(parameters)
2008-09-24 包和接口package and interface 的学习
包语法:package pkgname
接口:interface
access interface name{
}
access=public或没有,如果access声明为了public则接中的所有变量和方法都是public的。
实现接口:
access class classname extends superclass
implements interface1,interface2.........
{
}
当实现一个接口方法时,它必须被声明为public
如果一个类实现接口,但不实现接口中的所有方法,则必段声明为abstract类
接口也是可以扩展的
access interface int2 extends inte2{
}
对于异常处理:Exception
导常处理的5个关键字:
try,catch,throw,throws,final
Java的内置异常
1.ArithmeticException
2.ArrayIndexOutBoundsException
3.ArrayStoreException 数组元素赋值类型不兼容
4.ClassCastException
5.IllegalArgumentException
6.IllegalMonitorStateException
7.IllegalThreadStateException
8.IndexOutOfBoundsException
9.NullPointerException
10.NumberFormatException
11.SecurityException
12.StringIndexOutOfbounds
13.UnsupportedOperationException
14.ClassNotFoundException
15.CloneNotSupportedException
16.IllegalAccessException
17.InstaniationException
18.InterruptedException
19.NoSuchFieldException
20.NoSuchMethodException
异常类:Exception
2009-09-25
线程:多线程是多任务处理的一种特殊形式
线程的几种状态:running,suspend,resume,block,terminate
线程的优先级是执行何时运行一个线程的,即上下文切换context switch.
Thread类和Runnable接口。
管理线程的方法如下:
getName
getPriority
jsAlive
join
run
sleep
start
主线程:是程序一开始的线程,是创建其它子线程的开始,必段最后执行完毕,因为它负责关闭的操作。
currentThread是Thread类的公有的静态成员
创建线程:
1.实现Runnable
2.继承Thread类
2008-09-26:线程的同步
多线程运行时需要进行同步,这里涉及到一个管程的概念,即一个线程要进入管程中才能进行执行,且,其它进程必须等待.
如何同步呢,两种方法
1.在方法前加上synchronized
2.使用synchronized(Threadname){
}语句块
进程间通信机制 wait(),notify(),notifyAll()
2008-09-27 输入输出的学习
流:字节流与字符流,在java的最底层都是字节流的,在java2后才有的字符流,字符流比字节流更有效.
两个抽像类:InputStream OutputStream
字节流类:
BufferedInputStream
BufferedOutputStream
ByteArrayInputStream
ByteArrayOutputStream
DataInputStream
DataOutputStream
FileInputStream
FileOutputStream
FilterInputStream
FilterOutputStream
InputStream
OutputStream
PipedInputStream
PipedOutputStream
PrintStream
PushbackInputStream
RandomAccessFile
SequenceInputStream
方法:read(),write()
字符流类:
两个抽像类:Reader Writer
预定义的流
in,out,err
BufferedReader
InputStreamReader(InputStream inputstream)
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
对于java中String字符串的学习
构造函数:new String()如:String s = new String("hello world");
char chars[]={'a','b','c','d'};
String s = new String(chars);
字符串的长度:length()
toString()这是任何对像中都有的一个方法,可以重载
字符串的载取:
charAt();
getChars();
getBytes();
toCharArray();
比较函数:
equals和equalsIngoreCase()
regionMatches()
startsWith(),endsWidth()
equals与==的对比,它们是不同的,equals是比较内容是否相同,而==则比较的是引用的对像是否相同,示例如下:
public class equalsisequ {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "hello";
String s1 = new String("hello");
System.out.println("s equals s1 "+ s.equals(s1));
System.out.println("s == s1 "+(s==s1));
}
}
看结果:
s equals s1 true
s == s1 false
compareTo()函数
/*利用compareTo函数来比较字符串*/
public class compartString {
/**
* @param args
*/
static String s[]={
"are","one","two","ten","hello","world","china","monday"
};
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int j=0;j<s.length;j++)
for(int i=j+1;i<s.length;i++){
if(s[i].compareTo(s[j])<0){
String t = new String(s[i]);
s[i]=s[j];
s[j]=t;
}
}
for (int i=0;i<s.length;i++){
System.out.println(s[i]);
}
}
}
搜索字符 indexOf,lastIndexOf();
修改字符串:substring(),concat(),replace(),trim()
利用valueOf()方法实现数据转换
它是将数据的内部格式转换为可读的形式,它是一种静态方法,对于所有java内置的类型,在字符串(String)内被重载,以便每
一种类型都能被转换成字符串.
字符串大小写:toLowerCase(),toUpperCase()
StringBuffer这是一个可变的字符串
方法与String有些是相同的,但它可以利用append,insert等进行字符串的更改.
如:
public class testscopeint{
public void static main(String args[]){
for ( int i=1;i<5;i++){
int y = 0;
System.out.println("y="+y);
y = y * i;
System.out.println("y="+y);
}
}
}
2.自动类型转换: 类型要兼容,且目标类型要大于源类型
public class varscope {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte b;
int i;
double f;
i = 265;
f = 325.323;
b = (byte)i;
System.out.println(i+" "+b);
b = (byte)f;
i = (int)f;
System.out.println(f+" "+i+" "+b);
}
}
看其结果是什么?
3.数组的定义
type 变量名,例如:int years[];
初始化:years = new int[10];
或
int years[] = new int[12];
问题:利用一个数组来计算平均数
int[] years; 这也是一种声明数组的方法
4.java中的字符串是对像 ×
5.% 模式运算符 24.32%10 = 4.32
6.位逻辑运算符:& | ^ ~ 与、或、非、异或
7.? 三值运算符 exp1?exp2:exp3;
8.switch语句
switch(exp){
case value1:
case value2:
default:
}
9.关于break跳出语句,它可以替代goto语句如下
public class breakgoto {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("这是一个测试break-goto的example");
first:{
System.out.println("first");
second:{
System.out.println("sencod");
for(int i=0;i<10;i++){
if(i>5) break second;
}
System.out.println("second after");
}
}
}
}
10.对像与类 class
class classname{
member1;
member2;
mothod1{
}
}
classname name1 = new classname();
new运算符的过程
上述解解为两步:
classname name1;
name1 = new classname();
11.给对像引用变量赋值
box mybox1;
box mybox2;
mybox1 =new box();
mybox2 = mybox1;
这里mybox1,mybox2共同指向同一个地址,但释放任何一个都不会影响对方。
mybox1.height=20;
mybox1 = null;
这时mybox2.height仍然为20
this关键字?
对像的重载,可以实现多态
12.参数是如何传递的
在java中参数有两种传递:一是按值传递 二是按引用传递
call by value call by reference
2008-09-23
类的继承
class A extends B{
}
private:继承子类不能访问,只有在类的内部成员才可以访问它。
super 必段是构造函数中的第一个条语句。
动态方法调度(dynamic method dispatch)是在运行时而不是在编译时调用重载方法的一种机制,这是java多态的重要特性(面向对像)
抽像类:abstract type classname(parameters)
2008-09-24 包和接口package and interface 的学习
包语法:package pkgname
接口:interface
access interface name{
}
access=public或没有,如果access声明为了public则接中的所有变量和方法都是public的。
实现接口:
access class classname extends superclass
implements interface1,interface2.........
{
}
当实现一个接口方法时,它必须被声明为public
如果一个类实现接口,但不实现接口中的所有方法,则必段声明为abstract类
接口也是可以扩展的
access interface int2 extends inte2{
}
对于异常处理:Exception
导常处理的5个关键字:
try,catch,throw,throws,final
Java的内置异常
1.ArithmeticException
2.ArrayIndexOutBoundsException
3.ArrayStoreException 数组元素赋值类型不兼容
4.ClassCastException
5.IllegalArgumentException
6.IllegalMonitorStateException
7.IllegalThreadStateException
8.IndexOutOfBoundsException
9.NullPointerException
10.NumberFormatException
11.SecurityException
12.StringIndexOutOfbounds
13.UnsupportedOperationException
14.ClassNotFoundException
15.CloneNotSupportedException
16.IllegalAccessException
17.InstaniationException
18.InterruptedException
19.NoSuchFieldException
20.NoSuchMethodException
异常类:Exception
2009-09-25
线程:多线程是多任务处理的一种特殊形式
线程的几种状态:running,suspend,resume,block,terminate
线程的优先级是执行何时运行一个线程的,即上下文切换context switch.
Thread类和Runnable接口。
管理线程的方法如下:
getName
getPriority
jsAlive
join
run
sleep
start
主线程:是程序一开始的线程,是创建其它子线程的开始,必段最后执行完毕,因为它负责关闭的操作。
currentThread是Thread类的公有的静态成员
创建线程:
1.实现Runnable
2.继承Thread类
2008-09-26:线程的同步
多线程运行时需要进行同步,这里涉及到一个管程的概念,即一个线程要进入管程中才能进行执行,且,其它进程必须等待.
如何同步呢,两种方法
1.在方法前加上synchronized
2.使用synchronized(Threadname){
}语句块
进程间通信机制 wait(),notify(),notifyAll()
2008-09-27 输入输出的学习
流:字节流与字符流,在java的最底层都是字节流的,在java2后才有的字符流,字符流比字节流更有效.
两个抽像类:InputStream OutputStream
字节流类:
BufferedInputStream
BufferedOutputStream
ByteArrayInputStream
ByteArrayOutputStream
DataInputStream
DataOutputStream
FileInputStream
FileOutputStream
FilterInputStream
FilterOutputStream
InputStream
OutputStream
PipedInputStream
PipedOutputStream
PrintStream
PushbackInputStream
RandomAccessFile
SequenceInputStream
方法:read(),write()
字符流类:
两个抽像类:Reader Writer
预定义的流
in,out,err
BufferedReader
InputStreamReader(InputStream inputstream)
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
对于java中String字符串的学习
构造函数:new String()如:String s = new String("hello world");
char chars[]={'a','b','c','d'};
String s = new String(chars);
字符串的长度:length()
toString()这是任何对像中都有的一个方法,可以重载
字符串的载取:
charAt();
getChars();
getBytes();
toCharArray();
比较函数:
equals和equalsIngoreCase()
regionMatches()
startsWith(),endsWidth()
equals与==的对比,它们是不同的,equals是比较内容是否相同,而==则比较的是引用的对像是否相同,示例如下:
public class equalsisequ {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "hello";
String s1 = new String("hello");
System.out.println("s equals s1 "+ s.equals(s1));
System.out.println("s == s1 "+(s==s1));
}
}
看结果:
s equals s1 true
s == s1 false
compareTo()函数
/*利用compareTo函数来比较字符串*/
public class compartString {
/**
* @param args
*/
static String s[]={
"are","one","two","ten","hello","world","china","monday"
};
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int j=0;j<s.length;j++)
for(int i=j+1;i<s.length;i++){
if(s[i].compareTo(s[j])<0){
String t = new String(s[i]);
s[i]=s[j];
s[j]=t;
}
}
for (int i=0;i<s.length;i++){
System.out.println(s[i]);
}
}
}
搜索字符 indexOf,lastIndexOf();
修改字符串:substring(),concat(),replace(),trim()
利用valueOf()方法实现数据转换
它是将数据的内部格式转换为可读的形式,它是一种静态方法,对于所有java内置的类型,在字符串(String)内被重载,以便每
一种类型都能被转换成字符串.
字符串大小写:toLowerCase(),toUpperCase()
StringBuffer这是一个可变的字符串
方法与String有些是相同的,但它可以利用append,insert等进行字符串的更改.