七月5日第一节课总结初稿

7月5日第一节课总结初稿
<div class="iteye-blog-content-contain" style="font-size: 14px"></div>
7月5日第一节课总结
一、关于数据类型
1.Java的基本数据类型
Java的基本数据类型有8种
整数类型:
byte 字节型 8bit -128~127
short 短整型 16bit
int 整型 32bit
long 长整型 64bit
浮点型:
float 单精度 32bit
double 双精度 64bit
布尔
boolean 布尔类型 true和false
字符
char 字符型 16bit

2.数据类型测试代码
package ceshi_7_5;

/**
* 定义一个基本数据类型的测试
*
*/
public class DataTest {

static boolean bo;
static char c1 ;

/**
* 主函数,程序的入口
*/
public static void main(String[] args) {

//定义一个byte变量
byte b = (byte)-129;//由于byte的取值为-128~127,所以进行强制转化
System.out.println("byte b = "+b);

//定义一个char变量
char c = 'a';
System.out.println("char c = "+c);

//将c付给int变量i
int i = c;
System.out.println("int i = "+i);//输出c所代表的字母的ASC码值

long l = c;

float f = 10000.0F;

double d = f;

boolean bool = true;
System.out.println("bo = "+bo);
System.out.println("c1 = "+c1);

l = (long)f;

d = l;

}
3.运行结果:
     byte b = 127
     char c = a
     int i = 97
     bo = false
     c1 =

二、关于String类
1.一些重要的类的测试
package ceshi_7_5;

/**
* 定义一个String的使用类
* @author XiongXiangJun
*
*/
public class Ceshi{

/**
* 主函数,程序的入口
*/
public static void main(String[] args) {

//定义字符串变量
String str1 = "dasjfksduewrjckzvjzheieiojsdkjfsld";
String str2 = new String("jck");

char [] arrayC = {'a','s','j'};
String str3 = new String(arrayC);
String str4 = "abc";
String str5 = "abc";
String str6 = new String("abc");

for(int i=0;i<str1.length();i++){
//获取指定的索引位置的字符
char c = str1.charAt(i);
System.out.println("索引"+i+"位置的字符是:"+c);
}

//比较两个字符串是否相等
if(str4.equals(str5)){
System.out.println("equals相等");
}else {
System.out.println("equals不相等");
}
if(str4.equals(str6)){
System.out.println("equals相等");
}else {
System.out.println("equals不相等");
}

//判断某个字符串是否在包含在另一个字符串中
if(str1.contains(str2)){
System.out.println("包含");
//去掉包含的字符串
String temp = str1.replace(str2, "");
System.out.println("temp = "+temp);

}else{
System.out.println("不包含");
}

//根据str2拆分两个不同的字符串
String [] array = str1.split(str2);
System.out.println("array length = "+array.length);
System.out.println(array[0]);
System.out.println(array[1]);

//找到s第一次出现的位置
int index = str1.indexOf("s");
System.out.println(index);
System.out.println(str1.indexOf("s",index+1));

long l1 = 10000;
String.valueOf(l1);
}

}
2.运行结果

索引0位置的字符是:d
索引1位置的字符是:a
索引2位置的字符是:s
索引3位置的字符是:j
索引4位置的字符是:f
索引5位置的字符是:k
索引6位置的字符是:s
索引7位置的字符是:d
索引8位置的字符是:u
索引9位置的字符是:e
索引10位置的字符是:w
索引11位置的字符是:r
索引12位置的字符是:j
索引13位置的字符是:c
索引14位置的字符是:k
索引15位置的字符是:z
索引16位置的字符是:v
索引17位置的字符是:j
索引18位置的字符是:z
索引19位置的字符是:h
索引20位置的字符是:e
索引21位置的字符是:i
索引22位置的字符是:e
索引23位置的字符是:i
索引24位置的字符是:o
索引25位置的字符是:j
索引26位置的字符是:s
索引27位置的字符是:d
索引28位置的字符是:k
索引29位置的字符是:j
索引30位置的字符是:f
索引31位置的字符是:s
索引32位置的字符是:l
索引33位置的字符是:d


equals相等
equals相等


包含


temp = dasjfksduewrzvjzheieiojsdkjfsld


array length = 2
dasjfksduewr
zvjzheieiojsdkjfsld


2
6

三、上课所记部分知识要点
1.类名首字母大写;
2.长度从一,索引从零;
3.类名后面必须要加圆括号;
4.New关键字的作用是开辟内存;
5.做是否相等的判断一般不用“==”,而用equals,比较内容;