简答

环境变量:
java_home:
在后续的学习过程当中,会涉及到使用服务器。在使用服务器,如tomcat的过程当中,
它需要根据指定的java根目录来确定运行。

true1()||true2() |
以程序来代替基础的数据类型。
public boolean true1(){
return true;
}

public boolean true2(){
return true;
}

public boolean false1(){
return false;
}




public boolean false2(){
return false;
}


public static void main(String[] args){
for(int i=1; i<10;i++){
System.out.print("■");
for(int t=0; t<10000000;t++){
System.out.print("");
}
}

for(int i=0;i<10;i++){
for(int t=0; t<10000000;t++){
System.out.print("");
}
for(int k=0;k<=i+1;k++){
System.out.print("\b");

}

for(int s=0;s<=i;s++){
System.out.print(" ");
}


}
}
}




class student{
//构造方法无返回值。当定义了一个显式的构造方法之后,默认的那个构造方法不再执行。

public student(){
System.out.println("create a student");
}
//带参数的构造方法。
public student(String name,int age){
https://www.360docs.net/doc/9b5489973.html, = name;
this.age = age;
}
/*
this:它的作用是:代表当前对象的引用。
多数情况下:在一个对象的内部,有多次某一名称变量重复出现,但是这些出现
的变量不是同一变量,如局部变量与全局变量名称重复。
在这种情况下,this.变量名代表的是:全局变量。

*/

private String name;
private int age;

public void setName(String name){
https://www.360docs.net/doc/9b5489973.html, = name;
}
public String getName(){
return name;
}

public void setAge(int age){
this.age = age;
}

public int getAge(){
return age;
}

public static void main(String[] args){
student s1 = new student();//没有通过显式构造方法的方式。
s1.setName("aobama");
s1.setAge(51);
System.out.println(s1.getName());
/*
构造方法的作用:在对象创建的初始时期,通过外界性的参数注入,来达到
间接初始化的目的。不需要在创建对象之后再进行初始化的操作了。
使用构造方法,适合于类或对象不需要太多属性的条件下。
对象的创建肯定通过了构造方法,只是默认的构造方法不可见。

*/
student s2 = new student("jackie",55);
System.out.println(s2.getName());
}
}

/*
相等测试:比较两个对象是否相等。
*/

class equalTest{
int count;
/*
equals()方法:比较两个对象是否相等。
student1.equals(student2);
obj : student2
this: student1
如果内存当中的student1,也就是this指向的位置和student2指向的位置相同,那么它们肯定是同一个元素或对象。
如果此条件成立,那这种应该是:
student1.equals(student1);
相等测试不限制规则,但有原则:
对称性:
如果 s1.equals(s2)成立,则s2.

equals(s1)也要成立。
自反性:
s1.equals(s1);
传递性:
如果s1.equals(s2)成立,s2.equals(s3)成立,那么s1.equals(s3)也成立。

*/
public boolean equals(Object obj){
if(this == obj){
return true;
}
if(obj != null && obj.getClass() == equalTest.class){
equalTest st = (equalTest)obj;
if(st.count == this.count){
return true;
}
}

return false;
}
}

class testInt{

public static void main(String[] args){
/*想要使用Integer.parsetInt()的时候,一定是需要被转换的字符串具有
数值的特征,一看就是一个数值。只不过是数值被""引起来了。
Integer.parseInt它得到的是一个整数。

*/
System.out.println(Integer.parseInt("123"));
if(Integer.parseInt("123")>12){
System.out.println("这是一个比较大的整数");
}

int i1 = 12;
Integer i2 = new Integer(12);
System.out.println(i1 == i2);
int i3 = 556;
Integer i4 = new Integer(556);
System.out.println(i3 == i4);

System.out.println(Integer.MAX_VALUE);

}
}


class teacher{
String name;
int age;
student st;

}

class student{
String name;
int age;
teacher te;
}

class test{
public static void main(String[] args){
student s1 = new student();
https://www.360docs.net/doc/9b5489973.html,="student 1";
s1.age = 22;
teacher t1 = new teacher();
https://www.360docs.net/doc/9b5489973.html, = "teacher 1";
s1.te = t1;
t1.st = s1;

System.out.println("Teacher:" + https://www.360docs.net/doc/9b5489973.html, + "的学生是:" + https://www.360docs.net/doc/9b5489973.html,);
System.out.println("Student:" + https://www.360docs.net/doc/9b5489973.html, + "的年龄是:" + s1.te.st.age);
}
}




/*
java当中,集合是这样一种元素:它能够对数据或是对象进行多数量的封装。
它能够对很多属性进行封装,从而方便使用。
List Collection
接口---》实现类。
interface name = new implements();
它不会去考虑想要处理的具体类型是什么。它是以一种通用的方式来进行处理。
存在这样一种情况:对集合而言,它是不了解其内部的相关数据信息的。包括数据类型。
注意:testList.java 使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用 -Xlint:unchecked 重新编译。
*/
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.*;

class test1{

public static void main(String[] args){
//这就是一个集合。在操作集合的过程当中,如果真正使用,一定要为其进行初始化。

List list = new ArrayList();
student s1 = new student();
s1.setName("学生1");
student s2 = new student();
s2.setName("学生2");

list.add(s1);//向集合当中添加元素。
list.add(s2);

//查看一下集合当中的数据的数量。
System.out.println(list.size());
}
}

class student{
String name;
int age;
String addr;
public void setName(String name){
https://www.360docs.net/doc/9b5489973.html, = name;
}

public String getName(){
return

name;
}
}
/*
让集合能够封装固定的数据类型

*/

class myList{
List list = new ArrayList();
public void add(String tem){
list.add(tem);
}

public int size(){
return list.size();
}
}

class teacher{
String name;
int age;
}
/*
任何时候使用集合,它都应该封装同一种数据类型的元素。
对于不同种类的元素处理,该如何进行。

*/
class test3{
public static void main(String[] args){
teacher t1 = new teacher();
student s1 = new student();
student s2 = new student();
List list = new ArrayList();
list.add(s2);
list.add(s1);
System.out.println("集合的大小是:" + list.size());

/*使用for循环来对集合进行遍历*/
for(int i=0;i< list.size();i++){
//从0开始,每一次对集合当中的元素获取,使用get(index)方法。
//index 索引位置。取得元素之后需要进行相应的类型转换。
}
//for..each..循环 它不具有具体元素位置的可控性。可以通过另外的方式进行运行过程当中的监控。

int count = 0;
for(Object obj:list){
student st = (student)obj;
System.out.println(https://www.360docs.net/doc/9b5489973.html,);
}
System.out.println("=============Iterator=============");
//对集合的另一种遍历方式,迭代,在进行迭代的过程当中,涉及到迭代器。
Iterator it = list.iterator();
/*
迭代器:Iterator
通过迭代器自身的特性:判断元素,取得元素。
hasNext():判断元素是否存在,也就是是否含有下一个元素。
如果含有下一个元素,则将当前元素取出。
*/
while(it.hasNext()){//while(true)
System.out.println("ok");
student st = (student)it.next();//取得想要的元素。触发元素位置的移动。
System.out.println(https://www.360docs.net/doc/9b5489973.html,);
}




}
}

/*
遍历集合当中的元素,也就是一个一个的使用。
*/
class test2{
public static void main(String[] args){
student s1 = new student();
https://www.360docs.net/doc/9b5489973.html, = "student1";

student s2 = new student();
https://www.360docs.net/doc/9b5489973.html, = "student2";

List list = new ArrayList();
list.add(s2);
list.add(s1);
System.out.println("集合的大小是:" + list.size());

Iterator it = list.iterator();

while(it.hasNext()){
student st = (student)it.next();
if(https://www.360docs.net/doc/9b5489973.html,.equals("student2")){
it.remove();//直接托管
}
}
/*
while(it.hasNext()){
System.out.println("---------");
student st = (student)it.next();//取得想要的元素。触发元素位置的移动。
System.out.println("**********");
if(https://www.360docs.net/doc/9b5489973.html,.equals("student2")){
list.remove(st);
}
}
通过索引进行集合的元素获取的时候,完全可以直接按照索引位置进行元素提取。
不是一定会出现在循环当中。
student s = (student)list.get(0);
System.out.println("username:" + https://www.360docs.net/doc/9b5489973.html,);
System.out.println(list);
*/

}
}
/*
如果以集合

的方式对数据进行遍历性的删除,建议,不要正顺删除,要反顺。

for(int i=start;i<=rows;i++){
table.del(i);
}
在对迭代的元素进行操作的过程当中,尽量不要发生更新。尤其是进行Iterator操作的时候。
默认在java当中不欢迎使用非迭代器的方式进行数据的删除。
使用迭代器的时候,要尽量将所有的操作都托管给迭代器,而不要人工干预。

*/

class A{
public boolean equals(Object obj){
return true;
}
}

class B{
public int hashCode(){
return 2;
}
}

class C{
public boolean equals(Object obj){
return true;
}

public int hashCode(){
return 2;
}
}
class test4{
/*
在HashSet当中,所存储的元素,它是没有顺序的。
不一定会按照添加的顺序显示。
HashSet在使用的过程当中,需要注意:
A:equals() B:hashCode() C:equals()和hashCode()
equals()用来判断对象的值是否相等。
hashCode()可以理解为对象在集合当中的存储的位置。
当两个创建出来的对象它们拥有共同的hashCode()的时候,意味着它们在
HashSet这个集合当中存储的位置是一致的。也就是说,HashSet是按照hashCode()
的值来计算对象或元素的存储位置的。
当找到这个共同的位置之后,会进行equals()判断。
此时,hashSet只存储了一个元素。
当equals()不一致的时候,会出现什么情况。
当出现这种情况的时候,就会以链表的方式对数据进行保存。只是这种保存会消耗性能。
HashSet的要求:
如果两个对象的hashCode()计算结果一致,则也要让它们的equals()方法计算结果一致。
在HashSet当中,hashcode()与equals()有一种行为上的一致性。

*/
public static void main(String[] args){
HashSet set = new HashSet();
A a1 = new A();
A a2 = new A();
B b1 = new B();
B b2 = new B();
C c1 = new C();
C c2 = new C();


set.add(c1);
set.add(c2);
System.out.println(set);
System.out.println(set.size());

System.out.println(set.isEmpty());
}
}


class t{
public static void main(String[] args){
String info="我爱你中国\b";
System.out.println(info);
info="我爱你中国\b我爱你世界";
System.out.println(info);
}
}

相关主题
相关文档
最新文档