package test;
public class Student {
String name;
int number;
public Student(String name,int number ) {
this.name=name;
this.number=number;
}
@Override
public String toString() {
return "Student [name=" + name + ", number=" + number + "]";
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Student) {
Student student=(Student)obj;
if(this.number == student.number) {
return true;
}else {
return false;
}
} return false;
}
@Override
public int hashCode() {
return number;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
package test;
public class Test1 {
public static void main(String[] args) throws CloneNotSupportedException{
String str1=new String("abc");
String str2=new String("abc");
System.out.println(str1.hashCode());
System.out.println(str2.hashCode());
Integer int1 = new Integer(100);
Integer int2 = new Integer(100);
System.out.println(int1.hashCode());
System.out.println(int2.hashCode());
Student s1 = new Student("홍길동", 1);
Student s2 = new Student("홍길동", 1);
System.out.println(s1.hashCode());
System.out.println(s2.hashCode());
Student copys1 =(Student)s1.clone();
}
}
package test;
public class Test2 {
public static void main(String[] args) {
String str1 = new String("abc");
String str2 = new String("abc");
System.out.println(str1==str2);
System.out.println(str1.equals(str2));
String str3 = "test";
String str4 = "test";
System.out.println(str3==str4);
System.out.println(str3.equals(str4));
System.out.println("======================");
String javaStr = new String("java");
String jspStr = new String("jsp");
System.out.println(javaStr);
System.out.println("기억장소 주소:"+ System.identityHashCode(javaStr));
javaStr = javaStr.concat(jspStr);
System.out.println(javaStr);
System.out.println("기억장소 주소:"+ System.identityHashCode(javaStr));
String str = "Java Programming";
System.out.println(str.substring(0,1));
System.out.println(str.substring(5,16));
System.out.println(str.charAt(5));
System.out.println(str.equals("jsp"));
System.out.println(str.indexOf('P'));
System.out.println(str.length());
str=str.replace("Java", "jsp");
System.out.println(str);
String strSplit[] = str.split(" ");
System.out.println(strSplit[0]);
System.out.println(strSplit[1]);
}
}
package test;
public class Test3 {
public static void main(String[] args) {
String javaStr = new String("java");
System.out.println("기억장소 주소 : "+ System.identityHashCode(javaStr));
StringBuffer buffer = new StringBuffer(javaStr);
System.out.println("buffer 기억장소 주소 : " + System.identityHashCode(buffer));
buffer.append(" and");
buffer.append(" jsp");
buffer.append(" Programming is fun");
System.out.println(buffer);
System.out.println("buffer 기억장소 주소 : " + System.identityHashCode(buffer));
javaStr = buffer.toString();
System.out.println(javaStr);
}
}
package test;
public class Test4 {
public static void main(String[] args) {
int i1 = 100;
Integer i2 = new Integer(100);
int i3 = i2.intValue();
int num = Integer.parseInt("100");
Integer num1 = new Integer(200);
int num2 = 300;
int sum = num1 + num2 ;
int sum2 = num1.intValue()+num2;
System.out.println(sum);
Integer num3 = num2;
}
}
package test;
public class Test5 {
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Student s = new Student("홍길동",1);
Class c = s.getClass();
System.out.println(c.getName());
Class c2 = Student.class;
System.out.println(c2.getName());
Class c3 = Class.forName("test.Student");
System.out.println(c3.getName());
Student ss = (Student)c3.newInstance();
System.out.println(ss);
Class.forName("com.mysql.cj.jdbc.Driver");
}
}