1.chaine de developpement
programme source(.java)->programme binaire(.class)->machine virtuelle
2.types
type primitif基本类型:
byte(1) short(2) int(4) long(8)
float(4) double(8)
boolean(1)
char(1)
特点:可直接建立,不需要调用new方法。可以在内存里直接表示
type complexe复杂类型:
table
特点:间接获取数据
type construit
String
特点:数据+工具
3.结构
if(condition)
{
}else
{
}
switch (variable)
{
case n:
break;
....
default:
}
while(condition)
{
//条件为真,运行
}
do
{
}while(condition)
//条件为真,继续往下走
for(int i=0; i<n; i++)
{
}
4.String
初始化:
String chaine=new String("Windows a encore plante");
char[] T={'W','i','n','d','o','w','s',' ','a'};
String chaine1=new String(T);
String chaine2="Windows";
常用方法
string.length() return int
string.charAt(n) return 第n位字母
string.substring(n,m) return String截取n位与n位后m位前的字符串
sting.equals(String ) return boolean
string.indexOf('char') return int
string.lastIndexOf('char') return int
string.replace('char1','char2') return String char2替换char1
String chaine3=chaine2+chaine1
String.valueOf(valeur) return String 其他类型转字符串(static)
This method has followings variants, which depend on the passed parameters. This method returns the string representation of the passed argument.
-
valueOf(boolean b): Returns the string representation of the boolean argument.
-
valueOf(char c): Returns the string representation of the char argument.
-
valueOf(char[] data): Returns the string representation of the char array argument.
-
valueOf(char[] data, int offset, int count): Returns the string representation of a specific subarray of the char array argument.
-
valueOf(double d): Returns the string representation of the double argument.
-
valueOf(float f): Returns the string representation of the float argument.
-
valueOf(int i): Returns the string representation of the int argument.
-
valueOf(long l): Returns the string representation of the long argument.
-
valueOf(Object obj): Returns the string representation of the Object argument
int[] Table;
Table=new int[10];
int[] T2={12,-33,44,0,12225}
abstract抽象类 boolean break byte case
catch char class continue default
do double else extends false
final finally float for if
implements import instanceof int interface
long native new null package
private protected public return short
static super switch synchronized this
throw throws transient true try
void volatile while
保留字
const,goto
所有的关键字都是小写
class Point
{
<span style="white-space:pre"> </span>public Point(int x, int y) throws ErrConst//throws修饰方法,加一个由Exception构造的class
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>if((x<0) || (y<0)) throw new ErrConst();//throw 是指令
<span style="white-space:pre"> </span>this.x=x;
<span style="white-space:pre"> </span>this.y=y;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public void affiche()
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>System.out.println("coordonnees: "+x+" "+y);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>private int x,y;
}
class ErrConst extends Exception
{}
public class Except1
{
<span style="white-space:pre"> </span>public static void main(String args[])
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>try
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>Point a= new Point(1,4);
<span style="white-space:pre"> </span>a.affiche();
<span style="white-space:pre"> </span>a=new Point(-3,5);
<span style="white-space:pre"> </span>a.affiche();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>catch(ErrConst e)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>System.out.println("Erreur construction");
<span style="white-space:pre"> </span>System.exit(-1);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
}