์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- SVN
- mysql์ํคํ ์ฒ
- effectiveJava
- builder null
- ๋ฐ์ฉ๋ ์ค๊ตญ์ด
- ์ดํํฐ๋ธ์๋ฐ
- Hikari Connection Pool
- enum ์์ฑ์ ์ ๊ทผ ์ ํ์
- hikari cp ์ค์
- ์ํฐ๋ ๋ณ์ข ๊ฐ๋ฐ์
- index full scan
- InnoDB์ํคํ ์ฒ
- ๋ฐ์ดํฐ๋ฒ ์ด์ค๊ฒฉ๋ฆฌ์์ค
- Item6
- ์๋ฐ์์์ฐ๋ ๋๋ฅผ ์ฌ์ฉํ๋ ์ด์
- ์๋ฐ
- ๋น์ผ๊ฐ์ฒด์์ฑ
- ์๋ผ์คํฑ์์น๋ฉ์ธ์ง์ฉ๋
- ์ํฐ๋ ๊ฐ๋ฐ์ํ์ฌ
- index skip scan
- ์๋ฐ๋ผ์ด๋ธ์คํฐ๋
- ์๋ฐ์์
- item15
- ์์
- ์ธ๋ฑ์คํ์ค์บ
- ์ธ๋ฑ์ค์คํต์ค์บ
- ์๋ฐ์ฐ๋ ๋
- ์์ดํ 15
- assert.notnull
- mysql
- Today
- Total
โ๐ป๊ธฐ๋กํ๋ ๋ธ๋ก๊ทธ
[ JAVA ] ๊ธฐ๋ณธํด๋์ค ( Object, String, Wrapper) ๋ณธ๋ฌธ
Object ํด๋์ค (java.lang.Object)
๋ชจ๋ ํด๋์ค์ ์ต์์ ํด๋์ค, ๋ชจ๋ ํด๋์ค๋ object ํด๋์ค๋ฅผ ์์ ๋ฐ์
-> ๋ฐ๋ก extends ํ์ง ์์๋ ์ฌ์ฉ์ด ๊ฐ๋ฅ ๋ฐ๋ก toString () ๋ฉ์๋๋ฅผ ์ธ ์ ์๋ ์ด์
์ปดํ์ผ๋ฌ๊ฐ ์๋ importํจ
์ฌ์ฉ์๊ฐ ์ง์ extendsํ์ง ์์๋ ์ปดํ์ผ๋ฌ๊ฐ ์๋์ผ๋ก ๋ฃ์ด์ค
java.langํจํค์ง๋ ์๋ฐ์์ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๋์์ ํ๋ ํด๋์ค
java.langํจํค์ง๋ ๋ฐ๋ก importํ์ง ์์๋ ํด๋์ค์ ์ด๋ฆ๋ง์ผ๋ก ์ฌ์ฉ์ด ๊ฐ๋ฅ
ex) String, Void , System
Object ํด๋์ค๋ ํ๋๋ฅผ ๊ฐ์ง์ง ์์ผ๋ฉฐ, ์ด 11๊ฐ ๋ฉ์๋๋ก๋ง ๊ตฌ์ฑ
1. toString()
์ธ์คํด์ค์ ๋ํ ์ ๋ณด๋ฅผ ๋ฌธ์์ด๋ก ๋ฐํ, ๋ฌธ์์ด์ ํด๋์ค ์ด๋ฆ@16์ง์ ํด์ฌ ์ฝ๋๋ก ์ถ๋ ฅ๋จ
package object;
class Book{
String title;
String author;
public Book(String title, String author){
this.title = title;
this.author = author;
}
}
public class ToStringTest {
public static void main(String[] args) {
Book book = new Book("testBook", "testAuthor");
System.out.println(book);
}
}
toString() ๋ฉ์๋๋ ๊ธฐ๋ณธ์ ์ผ๋ก apiํด๋์ค๋ง๋ค ์์ฒด์ ์ผ๋ก ์ค๋ฒ ๋ผ์ด๋ฉ์ ํตํด ์ฌ์ ์๋จ
@Override ์ค๋ธ์ ํธ ํด๋์ค์ toString๋ฉ์๋๋ฅผ ์ฌ์ ์ํ์ฌ ๊ฐ์ฒด์ ๋ด๊ธด ์ ๋ณด๋ฅผ ์ถ๋ ฅํจ
package object;
class Book{
String title;
String author;
public Book(String title, String author){
this.title = title;
this.author = author;
}
@Override
public String toString() {
return "Book{" +
"title='" + title + '\'' +
", author='" + author + '\'' +
'}';
}
}
public class ToStringTest {
public static void main(String[] args) {
Book book = new Book("testBook", "testAuthor");
System.out.println(book);//toString์ ๊ทธ ๊ฐ์ฒด์ ๊ธฐ๋ณธ์ ๋ณด๋ฅผ string ํํ๋ก ์ฐ์ด๋
}
}
๊ฐ์ฒด์ ์ ๋ณด๋ฅผ stringํํ๋ก ๋ฐ๊พธ์ด ์ฌ์ฉํ ๋ ์ ์ฉ
String str = new String("testBook");
System.out.println(str);
๋์ผํ๊ฒ new ์์ฑ์๋ก ์ถ๋ ฅํ์ง๋ง ๋ฌธ์์ด์ด ์ถ๋ ฅ๋จ , String ํด๋์ค ์์ ์ด๋ฏธ toString ํด๋์ค๊ฐ ์ ์๋์๊ธฐ ๋๋ฌธ
์์ ์ฝ๋๋ฅผ ์คํํ์ ๊ฒฝ์ฐ ์ค์ ๋ก ๋ถ๋ฆฌ๋ ๋ฉ์๋๋ str.toString
2. equals()
๋ ๊ฐ์ฒด์ ๋์ผํจ์ ๋ ผ๋ฆฌ์ ์ผ๋ก ์ฌ์ ์ํ ์ ์์
- ๋ฌผ๋ฆฌ์ ๋์ผํจ : ๊ฐ์ ์ฃผ์๋ฅผ ๊ฐ์ง๋ ๊ฐ์ฒด
- ๋ ผ๋ฆฌ์ ๋์ผํจ : ๊ฐ์ ํ๋ฒ์ ํ์, ๊ฐ์ ์ฃผ๋ฌธ ๋ฒํธ์ ์ฃผ๋ฌธ
- ๋ฌผ๋ฆฌ์ ์ผ๋ก ๋ค๋ฅธ ๋ฉ๋ชจ๋ฆฌ์ ์์นํ ๊ฐ์ฒด๋ผ๋ ๋ ผ๋ฆฌ์ ์ผ๋ก ๋์ผํจ์ ๊ตฌํํ๊ธฐ ์ํด ์ฌ์ฉํ๋ ๋งค์๋
2.1) String equals ์ฝ๋
str1 == str2๋ ๊ฐ์ฒด์ ์ฃผ์๋ฅผ ๋น๊ตํ๊ฒ ๋จ ๊ฐ ๊ฐ ๋ค๋ฅธ ๊ฐ์ฒด๋ฅผ ๊ฐ๋ฆฌํค๋ฏ๋ก false ๋ฆฌํด
String์ equals ๋ฉ์๋๋ String์ ๋ฌธ์์ด ๊ฐ์ด ๊ฐ์์ง ๋น๊ตํ๋ฏ๋ก true ( object ํด๋์ค์์ ์ฌ์ ์ ๋จ )
package object;
public class EqualsTest {
public static void main(String[] args) {
String str1 = new String("abc");
String str2 = new String("abc");
System.out.println(str1);
System.out.println(str2);
System.out.println(str1 == str2);
System.out.println("str1.equals(str2) ์ ๊ฒฐ๊ณผ : "+str1.equals(str2));
}
}
Object ํด๋์ค์ equals๋ฅผ ์ฌ์ ์ํ String ํด๋์ค์ equals
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = value.length;
if (n == anotherString.value.length) {
char v1[] = value;
char v2[] = anotherString.value;
int i = 0;
while (n-- != 0) {
if (v1[i] != v2[i])
return false;
i++;
}
return true;
}
}
return false;
}
2.2) ์ฌ์ ์๋ ๊ฐ์ฒด์ equals
package object;
class Student{
private int studentNum;
private String studentName;
public Student (int studentNum, String studentName){
this.studentNum = studentNum;
this.studentName = studentName;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Student){
Student std = (Student)obj;
return (this.studentNum == std.studentNum);
}
return false;
}
}
public class EqualsTest {
public static void main(String[] args) {
Student Lee = new Student(100,"์ด์์ ");
Student Lee2 = Lee;
System.out.println(Lee == Lee2);//true ๋์ผํ ์ฃผ์๊ฐ์ ๊ฐ๋ฅดํด
Student Shin = new Student(100,"์ด์์ ");
System.out.println(Lee == Shin);//false
System.out.println(Lee.equals(Shin));//Student ํด๋์ค์ ์ฌ์ ์ํ equals๋ฉ์๋์ ์ํด false ๊ฐ ๋ฆฌํด
}
}
3. hashCode()
4. clone()
5. filnalize()
6. getClass()
7. notify()
8. notifyAll()
9. wait() / wait(long timeout) / wait(long timeout, int nanos)
( ์ฐธ๊ณ )
ํจ์คํธ ์บ ํผ์ค - Java ์น ๊ฐ๋ฐ ๋ง์คํฐ ์ฌ์ธ์ ํจํค์ง
www.tcpschool.com/java/java_api_object
'Language > Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ JAVA ] ์์ (0) | 2020.12.25 |
---|---|
[ JAVA ] ์ถ์ํด๋์ค (0) | 2020.12.20 |
[ JAVA ] ๋คํ์ฑ polymorphism (0) | 2020.12.06 |
์์์์ ํด๋์ค ์์ฑ ๊ณผ์ ๊ณผ ํ ๋ณํ (0) | 2020.11.29 |
[JAVA] ์์ธ์ฒ๋ฆฌ (0) | 2020.11.22 |