<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Dev Ex Machina</title>
        <link>https://velog.io/</link>
        <description>개인 아카이브</description>
        <lastBuildDate>Thu, 03 Aug 2023 07:52:08 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>Dev Ex Machina</title>
            <url>https://velog.velcdn.com/images/jworld_714/profile/40bae718-19a8-4ffc-b742-a7184ee7ee0d/image.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. Dev Ex Machina. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/jworld_714" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[자바 - OutputStream (미완 수정중)]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-OutputStream-%EB%AF%B8%EC%99%84-%EC%88%98%EC%A0%95%EC%A4%91</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-OutputStream-%EB%AF%B8%EC%99%84-%EC%88%98%EC%A0%95%EC%A4%91</guid>
            <pubDate>Thu, 03 Aug 2023 07:52:08 GMT</pubDate>
            <description><![CDATA[<h3 id="-outputstream-">[ OutputStream ]</h3>
<ul>
<li>java.io.OutputStream</li>
<li>OutputStream 으로 끝나는 단어들은 다 OutputStream의 자식들.
(OutputStream은 슈퍼클래스 이다.)</li>
<li><ol>
<li>바이트 기반의 출력 스트림이다. (스트림 : 출력할 때 사용하는 통로)</li>
</ol>
</li>
<li><ol start="2">
<li>출력 단위</li>
</ol>
<ul>
<li>1) int</li>
<li>2) byte[]</li>
</ul>
</li>
<li>★정리 : 출력스트림은 바이트 들을 파일로 보내어 파일 객체를 만드는 용도로 사용 된다.</li>
<li>(데이터를 내보내는 게 목적이다.)</li>
</ul>
<hr>
<h4 id="-ex01-">[ ex01 ]</h4>
<pre><code>  public static void ex01() {

   // 디렉터리를 File 객체로 만들기
    File dir = new File(&quot;C:/storage&quot;);
    if(!dir.exists()) {
      dir.mkdirs();
    }

   // 파일을 File 객체로 만들기
    File file = new File(dir, &quot;ex01.dat&quot;);

   // 파일 선언 &amp; 생성을 분리하는 이유는 &#39; 스코프 조정 &#39; 하기 위함.

   // File로 byte 데이터를 내보낼 때 사용하는 Stream : FileOutputStream
    // 파일출력스트림 선언
    FileOutputStream fout = null;

    try {

    // 출력스트림이 file 로 출력할 것이다. (file = ex01.dat);
    // 파일출력스트림 생성 (반드시 예외 처리가 필요한 코드)
    fout = new FileOutputStream(file);

    // 출력할 데이터 (파일로 보낼 데이터)
    // int 와 byte[] 만 사용가능, Character 은 아예 불가능.
    int c = &#39;A&#39;;
    String s = &quot;pple&quot;;
    byte[] b = s.getBytes();  // byte[] : String을 byte[]로 변환
    // String 을 byte[] 로 만들어주는 자동 메소드가 있음 :  .getBytes() , 
    (인코딩(UTF-8)이 필요할 때는 3개의 getBytes중 파라미터가 있는 2개중에 쓰면 됨)

    // 출력 (파일로 데이터 보내기) 
    fout.write(c);
    fout.write(b);
  } catch (IOException e) {
    e.printStackTrace();   // 예외가 어디서 발생하는 알 수 있게 printStackTrace 써줌.
  } finally {
    try {
      if(fout != null) {
        fout.close();     // 출력스트림은 반드시 닫아줘야 함 (반드시 예외 처리가 필요한 코드)
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    // 예외처리가 필요한 아이들은 try 안에 들어가 있어야 한다.(예외 처리가 필요하면 Unhandled exception type IOException 뜸)

   // file 객체 이름 가져오는 법 : .getName  |  getParent : 폴더 가져오기 | getPath() : 폴더,파일 다 가져옴.
    System.out.println(file.getPath() + &quot; 파일 크기 : &quot; + file.length() + &quot;바이트&quot;);    
  }     
  }</code></pre><hr>
<h4 id="-ex02-">[ ex02 ]</h4>
<p>  public static void ex02() {</p>
<pre><code>// C:/storage/ex02.dat 파일로 안녕하세요 보내기, 파일 크기 확인

File dir = new File(&quot;C:/storage&quot;);
if(!dir.exists()) {
  dir.mkdirs();
}

File file = new File(dir, &quot;ex02.dat&quot;);


FileOutputStream fout = null;

try {
fout = new FileOutputStream(file);

String s = &quot;안녕하세요&quot;;
byte[] b = s.getBytes(&quot;UTF-8&quot;);  // UTF-8 로 인코딩해라. 

fout.write(b);</code></pre><p>  } catch (IOException e) {
    e.printStackTrace();<br>  } finally {
    try {
      if(fout != null) {
        fout.close();<br>      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
    System.out.println(file.getPath() + &quot; 파일 크기 : &quot; + file.length() + &quot;바이트&quot;);
  }</p>
<hr>
<h4 id="-ex03-">[ ex03 ]</h4>
<p>  public static void ex03() {</p>
<pre><code>/*
 * java.io.BufferedOutputStream 클래스
 * 1. 내부 버퍼를 가지고 있는 출력스트림이다.
 * 2. 많은 데이터를 한 번에 출력하기 때문에 속도 향상을 위해서 사용한다.
 * 3. 보조스트림이므로 메인스트림과 함께 사용한다.
 * 4. 주로 BufferedOutputStream 을 사용한다. 안 쓸 이유가 없다.
 */

/*
ex03.dat

2줄로 안녕하세요
      \n
      반갑습니다
*/

File dir = new File(&quot;C:/storage&quot;);
File file = new File(dir, &quot;ex03.dat&quot;);

// 버퍼 출력스트림 선언  // 버퍼를 가지고 있어서 출력 속도가 빠름. 
// (한 번에 byte 하나씩 내보내는 게 FileOutputStream, 한 번에 여러개 byte를 내보내는 게 BufferedOutputStream 이다.)
BufferedOutputStream bout = null;

try {
// FileOutputStream 을 만들어서 file쪽으로 출력 통로를 하나 만들고, 거기에 BufferedOutputStream 를 추가해서 보낸다.
bout = new BufferedOutputStream(new FileOutputStream(file));
String s1 = &quot;안녕하세요&quot;;
String s2 = &quot;반갑습니다&quot;;
int c = &#39;\n&#39;;  // s1이나 s2에 글자에 \n 을 넣어도 상관 없다.

bout.write(s1.getBytes(&quot;UTF-8&quot;));
bout.write(c);
bout.write(s2.getBytes(StandardCharsets.UTF_8));  // getBytes(&quot;UTF-8&quot;)과 동일하다.
} catch (IOException e) {
  e.printStackTrace();
} finally {
  try {
    if(bout != null) {
      bout.close();
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
}
System.out.println(file.getPath() + &quot;파일 크기 : &quot; + file.length() + &quot;바이트&quot;);</code></pre><p>  }</p>
<hr>
<h4 id="-ex04-">[ ex04 ]</h4>
<p>  public static void ex04() {</p>
<pre><code>/*
 * java.io.DataOutputStream 클래스
 * 1. int, double, String 등의 변수를 그대로 출력하는 출력스트림
 * 2. 보조스트림이므로 메인스트림과 함께 사용한다.
 */

File dir = new File(&quot;C:/storage&quot;);
File file = new File(dir, &quot;ex04.dat&quot;);

DataOutputStream dout = null;

try {

//  데이터출력스트림 생성 (반드시 예외 처리가 필요한 코드) 
dout = new DataOutputStream(new FileOutputStream(file));

// 출력할 데이터(파일로 보낼 데이터)
String name = &quot;tom&quot;;
int age = 50;
double height = 180.5;
String school = &quot;가산대학교&quot;;

// 출력(파일로 데이터 보내기)
dout.writeChars(name);  //위에 출력데이터들을 문자열로 저장해주겠다.
dout.write(age);
dout.writeDouble(height);
dout.writeUTF(school);  // write 종류별로 쓸 수 있게 만들어 둔 게 DataOutputStream.

} catch (IOException e) {
  e.printStackTrace();
} finally {
  try {
    if(dout != null) {
      dout.close();
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
} 
System.out.println(file.getPath() + &quot;파일 크기 : &quot; + file.length() + &quot;바이트&quot;);</code></pre><p>  }</p>
<hr>
<h4 id="-ex05-">[ ex05 ]</h4>
<p>  public static void ex05() {</p>
<pre><code>/*
 * java.io.ObjectOutputStream 클래스
 * 1. 객체를 그대로 출력하는 출력스트림이다.
 * 객체는 통째로 보내는 게 불가능해서, 직렬화 과정을 통해서 보내줘야 한다(객체를 분리해서 잘게 쪼개서 보내야 한다)
 * (객체:안 자른 김밥 -&gt; 직렬화:김밥을 잘라서 하나씩 보냄)
 * 2. 직렬화(serializable)된 객체를 보낼 수 있다.
 */

File dir = new File(&quot;C:/storage&quot;);
File file = new File(dir, &quot;ex05.dat&quot;);

ObjectOutputStream oout = null;

try {

//  객체출력스트림 생성 (반드시 예외 처리가 필요한 코드) 
oout = new ObjectOutputStream(new FileOutputStream(file));

// 출력할 데이터(파일로 보낼 데이터)
String name = &quot;tom&quot;;
int age = 50;
double height = 180.5;
String school = &quot;가산대학교&quot;;
Student student = new Student(name, age, height, school);


// 출력(파일로 데이터 보내기)
oout.writeObject(student);


} catch (IOException e) {
  e.printStackTrace();
} finally {
  try {
    if(oout != null) {
      oout.close();
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
} 
System.out.println(file.getPath() + &quot;파일 크기 : &quot; + file.length() + &quot;바이트&quot;);</code></pre><p>  }</p>
<hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<p>  public static void main(String[] args) {
   ex05();
  }
}</p>
<hr>
<h4 id="-학생-클래스-">[ 학생 클래스 ]</h4>
]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - API ( Random )]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-API-Random</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-API-Random</guid>
            <pubDate>Wed, 02 Aug 2023 08:38:55 GMT</pubDate>
            <description><![CDATA[<h3 id="-math-클래스의-random-메소드-">[ Math 클래스의 random 메소드 ]</h3>
<ul>
<li>java.lang.Math 클래스의 random 메소드</li>
<li><ol>
<li>0 이상 1 미만의 난수를 반환</li>
</ol>
</li>
<li><ol start="2">
<li>클래스 메소드이므로 Math 클래스를 이용해서 호출함</li>
</ol>
</li>
</ul>
<h4 id="-ex01-">[ ex01 ]</h4>
<pre><code>public static void ex01() {
    double randomNumber = Math.random();  // 0.0 &lt;= 난수 &lt; 1.0

 // 확률 처리하기
    if(randomNumber &lt; 0.1) {
      System.out.println(&quot;대박&quot;);
    } else {
      System.out.println(&quot;꽝&quot;);
    }

  }</code></pre><h4 id="-ex02-">[ ex02 ]</h4>
<pre><code> public static void ex02() {

    /*
     *  정수 난수로 바꿔서 사용하기
     *  
     *  1단계 : Math.random()                   0.0 &lt;= n &lt; 1.0
     *  2단계 : Math.random() * 3               0.0 &lt;= n &lt; 3.0
     *  3단계 : (int)(Math.random() * 3)        0 &lt;= n &lt; 3
     *  4단계 : (int)(Math.random() * 3) + 1    1 &lt;= n &lt; 4
     *  --------------------------------------------------------
     *          (int)(Math.random() * 개수) + 시작값 
     *          (int)(Math.random() * 개수 + 시작값)  - 위 아래 괄호 상관없음.  
     */

    int randomNumber = (int)(Math.random() * 3) + 1;  // 1부터 3개의 난수 발생
    System.out.println(randomNumber);

  }</code></pre><h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code>public static void main(String[] args) {
    ex02();
  }</code></pre><hr>
<h3 id="-random-">[ Random ]</h3>
<ul>
<li>java.util.Random 클래스</li>
<li><ol>
<li>전달된 시드(seed)에 따라서 서로 다른 난수를 발생한다.</li>
</ol>
</li>
<li><ol start="2">
<li>전달된 시드(seed)가 없는 경우에는 현재 시간을 시드(seed)로 사용한다.</li>
</ol>
</li>
<li><ol start="3">
<li>동일한 시드(seed)를 사용하면 동일한 난수가 발생한다.</li>
</ol>
</li>
</ul>
<pre><code>public static void main(String[] args) {
    // Random 객체 선언 &amp; 생성
    Random random = new Random();

 // 실수
    double randomNumber1 = random.nextDouble(); // 0.0 &lt;= n &lt; 1.0

 // 정수
    int randomNumber2 = random.nextInt(); // Integer.MIN_VALUE &lt;= n &lt;= Integer.MAX_VALUE
    int randomNumber3 = random.nextInt(5);  // 0 ~ 4 (5개 난수)

    System.out.println(randomNumber1);
    System.out.println(randomNumber2);
    System.out.println(randomNumber3);
  }
</code></pre><hr>
<h3 id="-securerandom-">[ SecureRandom ]</h3>
<ul>
<li>ex) 회원가입시 인증번호</li>
<li>java.security.SecureRandom 클래스</li>
<li><ol>
<li>보안 처리된 난수를 발생한다.</li>
</ol>
</li>
<li><ol start="2">
<li>Random 클래스와 같은 사용법을 가진다.</li>
</ol>
</li>
</ul>
<pre><code> public static void main(String[] args) {

 // SecureRandom 객체 선언 &amp; 생성
    SecureRandom secureRandom = new SecureRandom();

 // 실수
    double randomNumber1 = secureRandom.nextDouble();

 // 정수
    int randomNumber2 = secureRandom.nextInt();
    int randomNumber3 = secureRandom.nextInt(5);

    System.out.println(randomNumber1);
    System.out.println(randomNumber2);
    System.out.println(randomNumber3);   
  }
}</code></pre><hr>
<h3 id="-uuid-">[ UUID ]</h3>
<ul>
<li>java.util.UUID</li>
<li><ol>
<li>전역 고유 식별자(Universal Unique IDdentifier)라는 뜻이다.</li>
</ol>
</li>
<li><ol start="2">
<li>32개의 16진수를 랜덤하게 생성한다. (하이픈(-) 4개 별도 포함)</li>
</ol>
</li>
<li><ol start="3">
<li>UUID를 이용해서 생성한 값은 중복이 없는 것으로 처리한다.</li>
</ol>
</li>
<li><ol start="4">
<li>생성된 UUID값은 String으로 바꿔서 사용한다.</li>
</ol>
</li>
</ul>
<pre><code>public static void main(String[] args) {

    UUID uuid = UUID.randomUUID();
    String str = uuid.toString();

    System.out.println(str);
  }
}
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - API (StringBuffer, StringBuilder)]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-API-StringBuffer</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-API-StringBuffer</guid>
            <pubDate>Wed, 02 Aug 2023 08:21:44 GMT</pubDate>
            <description><![CDATA[<h3 id="-stringbuffer-">[ StringBuffer ]</h3>
<ul>
<li>java.lang.StringBuffer 클래스</li>
<li>StringBuffer : String에 Buffer(저장할 수 있는 기억장치)를 달았다는 의미.</li>
<li><ol>
<li>JDK 1.0 부터 사용 가능하다.</li>
</ol>
</li>
<li><ol start="2">
<li>String을 연결하는 클래스이다. (문자열 연결 연산자 +를 대체하는 클래스)</li>
</ol>
</li>
<li><ol start="3">
<li>synchronized(동기화) 처리되어 멀티스레드 환경에서 사용할 수 있다.</li>
</ol>
</li>
<li><ol start="4">
<li>동작이 느리다.</li>
</ol>
</li>
<li><ol start="5">
<li>String 클래스에 비해서 메모리 낭비가 적다. </li>
</ol>
</li>
</ul>
<hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code>public static void main(String[] args) {
 // StringBuffer 객체 선언
     StringBuffer sb;

 // StringBuffer 객체 생성
     sb = new StringBuffer();

// append 메소드를 이용한 문자열 연결
     sb.append(&quot;ha&quot;);
     sb.append(&quot;va&quot;);
     sb.append(&quot;na&quot;);

// StringBuffer 객체에 저장된 문자열을 String으로 변환
     String str = sb.toString();
     System.out.println(str);
   }
}</code></pre><hr>
<hr>
<h3 id="-stringbuilder-">[ StringBuilder ]</h3>
<ul>
<li>java.lang.StringBuilder 클래스</li>
<li><ol>
<li>JDK 1.5 부터 사용 가능하다.</li>
</ol>
</li>
<li><ol start="2">
<li>String을 연결하는 클래스이다. (문자열 연결 연산자 +를 대체하는 클래스)</li>
</ol>
</li>
<li><ol start="3">
<li>synchronized(동기화) 처리가 되지 않아서 싱글스레드 환경에서 사용할 수 있다.</li>
</ol>
</li>
<li><ol start="4">
<li>동작이 빠르다. (StringBuffer 에 비해서 빠르다)</li>
</ol>
</li>
<li><ol start="5">
<li>String 클래스에 비해서 메모리 낭비가 적다. </li>
</ol>
</li>
</ul>
<hr>
<h4 id="-메인-메소드--1">[ 메인 메소드 ]</h4>
<pre><code> public static void main(String[] args) {
   // StringBuilder 객체 선언
      StringBuilder sb;

   // StringBuilder 객체 생성
      sb = new StringBuilder();

   // append 메소드를 이용한 문자열 연결
      sb.append(&quot;ha&quot;);
      sb.append(&quot;va&quot;);
      sb.append(&quot;na&quot;);

   // StringBuilder 객체에 저장된 문자열을 String으로 변환
      String str = sb.toString();
      System.out.println(str);   
    }
  }</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - API (String)]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-API-uv79open</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-API-uv79open</guid>
            <pubDate>Wed, 02 Aug 2023 08:16:52 GMT</pubDate>
            <description><![CDATA[<h4 id="-ex01-">[ ex01 ]</h4>
<pre><code>public static void ex01() {

    // 문자열 리터럴(Literal)
    // 문자열 표현 방법:큰 따옴표로 문자열을 묶는다.
    String name1 = &quot;tom&quot;;
    String name2 = &quot;tom&quot;;

    // 문자열 리터럴은 Java에 의해서 최적화되기 때문에
    // 동일한 리터럴이 2번 이상 나타나면 기존 리터럴을 재사용한다.
    //
    //       ┌--------------┐
    //  name1│  0x12345678  │
    //       │--------------│
    //  name2│  0x12345678  │
    //       │--------------│
    //       │      ...     │
    //       │--------------│
    //       │      tom     │0x12345678
    //       │--------------│
    //       │      ...     │
    //       └--------------┘

    // 문자열 리터럴 비교
    // name1과 name2의 참조값이 동일하다.
    boolean isEqual = name1 == name2;
    System.out.println(isEqual);
  }</code></pre><hr>
<h4 id="-ex02-">[ ex02 ]</h4>
<pre><code>public static void ex02() {

// 문자열 객체(Object)
    String name1 = new String(&quot;tom&quot;);
    String name2 = new String(&quot;tom&quot;);

//문자열 객체는 항상 새로 생성된다.
    //
    //       ┌--------------┐
    //  name1│  0x12345678  │
    //       │--------------│
    //  name2│  0x98765432  │
    //       │--------------│
    //       │      ...     │
    //       │--------------│
    //       │      tom     │0x12345678
    //       │--------------│
    //       │      ...     │
    //       │--------------│
    //       │      tom     │0x98765432
    //       │--------------│
    //       │      ...     │
    //       └--------------┘

// 문자열 객체 비교
    // name1과 name2의 참조값이 다르다.
    boolean isEqual = name1 == name2;
    System.out.println(isEqual);
  }</code></pre><hr>
<h4 id="-ex03-">[ ex03 ]</h4>
<pre><code>public static void ex03() {

   // equals 메소드
   // 문자열이 동일하면 true, 아니면 false 반환

    String name1 = new String(&quot;tom&quot;);
    String name2 = new String(&quot;tom&quot;);
    String name3 = new String(&quot;Tom&quot;);

    boolean isEqual = name1.equals(name2);
    System.out.println(isEqual);

    boolean isEqual2 = name1.equals(name3); // 대소문자도 일치해야 동일한 문자열로 인식한다.
    System.out.println(isEqual);

    boolean isEqual3 = name1.equalsIgnoreCase(name3); // 대소문자를 무시하고 문자열을 비교한다.
    System.out.println(isEqual3);
  }</code></pre><hr>
<h4 id="-ex04-">[ ex04 ]</h4>
<pre><code>public static void ex04() {

    // toUpperCase 메소드 : 모두 대문자로 변환
    // toLowerCase 메소드 : 모두 소문자로 변환

    String name = &quot;Tom&quot;;

    System.out.println(name.toUpperCase());
    System.out.println(name.toLowerCase()); 
  }</code></pre><hr>
<h4 id="-ex05-">[ ex05 ]</h4>
<pre><code>public static void ex05() {

    // length 메소드 : 문자열의 길이(글자수)를 반환

    String name = &quot;Tom cruise\n&quot;;

    int length = name.length();
    System.out.println(length);
  }</code></pre><hr>
<h4 id="-ex06-">[ ex06 ]</h4>
<pre><code> public static void ex06() {

    // charAt 메소드
    // 문자열의 특정 인덱스(Index)의 문자를 반환

    String name = &quot;tom&quot;;

    char ch1 = name.charAt(0);
    char ch2 = name.charAt(1);
    char ch3 = name.charAt(2);

    System.out.println(ch1 + &quot;,&quot; + ch2 + &quot;,&quot; + ch3);
  }</code></pre><hr>
<h4 id="-ex07-">[ ex07 ]</h4>
<pre><code>public static void ex07() {

    // substring 메소드
    // 문자열의 일부 문자열을 반환

    // substring 사용법 (중요★)
    // 1. substring(int begin) : 인덱스 begin부터 끝까지 반환
    // 2. substring(int begin, int end) : 인덱스 begin부터 end 이전까지 반환(begin &lt;= 추출범위 &lt; end)

    String name = &quot;tom cruise&quot;;

    String firstName = name.substring(0, 3);  // tom;
    String lastName  = name.substring(4); // cruise

    System.out.println(firstName);
    System.out.println(lastName); 
  }</code></pre><hr>
<h4 id="-ex08-">[ ex08 ]</h4>
<pre><code>public static void ex08() {

    // indexOf 메소드
    // 1. 특정 문자열의 인덱스를 반환
    // 2. 특정 문자열이 2개 이상 존재하는 경우 발견된 첫 번째 문자열의 인덱스를 반환
    // 3. 발견되지 않으면 -1을 반환

    // indexOf 사용법
    // 1. indexOf(String str) : 인덱스 0부터 String str을 검색
    // 2. indexOf(String str, int index) : 인덱스 index부터 String str을 검색

    String statement = &quot;걱정한다고 걱정이 없어지면 걱정이 없겠네&quot;;

    int idx1 = statement.indexOf(&quot;걱정&quot;); // 0
    int idx2 = statement.indexOf(&quot;걱정&quot;, idx1 + 1); // 6
    int idx3 = statement.indexOf(&quot;걱정&quot;, idx2 + 1); // 15
    int idx4 = statement.indexOf(&quot;tom&quot;);  // -1

    System.out.println(idx1);
    System.out.println(idx2);
    System.out.println(idx3);
    System.out.println(idx4);
  }</code></pre><hr>
<h4 id="-ex09-">[ ex09 ]</h4>
<pre><code>public static void ex09() {

    // lastIndexOf 메소드
    // 1. 발견된 마지막 문자열의 인덱스를 반환
    // 2. 나머지 특징은 indexOf와 동일함

    String statement = &quot;걱정한다고 걱정이 없어지면 걱정이 없겠네&quot;;

    int idx = statement.lastIndexOf(&quot;걱정&quot;); //15
    System.out.println(idx);
  }</code></pre><hr>
<h4 id="-ex10-">[ ex10 ]</h4>
<pre><code>public static void ex10() {

  // contains 메소드
  // 지정된 CharSequence(String, char[] 등)가 포함되어 있으면 true 반환, 아니면 false

  String email = &quot;admin@naver.com&quot;;

  // @가 포함되어 있는가?
  if(email.contains(&quot;@&quot;)) {
    System.out.println(&quot;@가 포함되어 있다.&quot;);
  } else {
    System.out.println(&quot;@가 포함되어 있지 않다.&quot;);
  }

  }</code></pre><hr>
<h4 id="-ex11-">[ ex11 ]</h4>
<pre><code>public static void ex11() {

    // isEmpty 메소드
    // 1. 빈 문자열이면 true 반환, 아니면 false 반환
    // 2. 빈 문자열 : &quot;&quot;처럼 문자열의 길이가 0인 문자열

    String name = &quot;&quot;;
    if(name.isEmpty()) {
      System.out.println(&quot;이름이 없다.&quot;);
    } else {
      System.out.println(&quot;이름이 있다.&quot;);
    }

    // isBlank 메소드
    // 1. 빈 문자열이거나, 공백 문자로 구성되었다면 true 반환, 아니면 false
    // 2. JDK 11 이후 버전에서 사용 가능
    if(name.isBlank()) {
      System.out.println(&quot;이름이 없다.&quot;);
    } else {
      System.out.println(&quot;이름이 있다.&quot;);
    }
  }</code></pre><hr>
<h4 id="-ex12-">[ ex12 ]</h4>
<pre><code>public static void ex12() {

    // format 메소드
    // 1. 문자열을 지정한 형식으로 반환
    // 2. 클래스 메소드이므로 String 클래스를 이용해서 호출함

    // 숫자 형식
    int number = 100; // 10진수 100
    System.out.println(String.format(&quot;%o&quot;, number));  // %o : 8진수로 표시
    System.out.println(String.format(&quot;%d&quot;, number));  // %d : 10진수로 표시
    System.out.println(String.format(&quot;%x&quot;, number));  // %x : 16진수로 표시(0~9, a~f)
    System.out.println(String.format(&quot;%X&quot;, number));  // %X : 16진수로 표시(0~9, A~F)

    // 문자열 형식
    String str = &quot;hello&quot;;
    System.out.println(String.format(&quot;%s&quot;, str));  // %s : 문자열로 표시

    // 출력 폭 조정
    System.out.println(String.format(&quot;%5d&quot;, number));   // 5자리 10진수로 표시, 숫자를 오른쪽 정렬.
    System.out.println(String.format(&quot;%-5d&quot;, number));  // 5자리 10진수로 표시, 숫자를 왼쪽 정렬.
    System.out.println(String.format(&quot;%05d&quot;, number));  // 5자리 10진수로 표시, 숫자를 오른쪽 정렬, 빈 자리를 0으로 채움
    System.out.println(String.format(&quot;%10s&quot;, str));   
    System.out.println(String.format(&quot;%-10s&quot;, str));    // 5자리  
  }</code></pre><hr>
<h4 id="-ex13-">[ ex13 ]</h4>
<pre><code> public static void ex13() {

    // 정규식을 활용한 메소드
    // 1. startWith  : 지정된 정규식 패턴으로 시작하면 true 반환
    // 2. endWith    : 지정된 정규식 패턴으로 끝나면 true 반환
    // 3. matCh      : 지정된 정규식 패턴을 포함하면 true 반환
    // 4. replaceAll : 지정된 정규식 패턴을 만족하는 부분을 다른 문자열로 변환.
    // 5. split      : 지정된 정규식 패턴으로 문자열을 분리하여 분리된 String 배열을 반환

    String ip = &quot;192.168.0.101&quot;;

    String str = ip.replaceAll(&quot;.&quot;, &quot;_&quot;); // 192_168_0_101 을 기대하지만 정규식 패턴에서 .는 모든 문자를 의미하므로 원하는 결과를 얻을 수 없다.
    System.out.println(str);

    // strip 메소드
    // 앞 뒤에 포함된 공백 문자 제거
    String name = &quot;\n tom \n&quot;;
    String str1 = name.strip();
    System.out.println(str1.length());  // 3

    // trim 메소드
    // 앞 뒤에 포함된 공백 문자 제거
    String str2 = name.trim();
    System.out.println(str2.length());  // 3

  }</code></pre><hr>
<h4 id="-ex14-">[ ex14 ]</h4>
<pre><code>public static void ex14() {

    // replace 메소드
    // 1. 지정된 문자열을 다른 문자열로 변환
    // 2. 발견된 모든 문자열을 변환

    String ip = &quot;192.168.0.101&quot;;
    String str = ip.replace(&quot;.&quot;, &quot;_&quot;);
    System.out.println(str);
  }</code></pre><hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code> public static void main(String[] args) {
   ex14();
  }
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - Input , Output ]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Input-Output</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Input-Output</guid>
            <pubDate>Wed, 02 Aug 2023 08:02:27 GMT</pubDate>
            <description><![CDATA[<h3 id="-javaiofile-클래스-">[ java.io.File 클래스 ]</h3>
<ul>
<li><ol>
<li>파일, 디렉터리(폴더)를 관리하는 클래스이다.</li>
</ol>
</li>
<li><ol start="2">
<li>파일, 디렉터리를 생성/삭제가 가능하다.</li>
</ol>
</li>
<li><ol start="3">
<li>파일, 디렉터리의 각종 정보(이름, 크기, 최종수정일 등)를 확인할 수 있다.</li>
</ol>
</li>
</ul>
<hr>
<h4 id="경로-작성-방법">&lt; 경로 작성 방법 &gt;</h4>
<ul>
<li><ol>
<li>윈도우 : 백슬래시(), java에서 백슬래시 입력하는 방법(\)  
(그러나 / 로도 가능하니 슬래시(/)로 쓰자.)</li>
</ol>
</li>
<li><ol start="2">
<li>리눅스 : 슬래시(/)</li>
</ol>
</li>
</ul>
<hr>
<h4 id="-ex01----★중요">[ ex01 ] - ★중요</h4>
<pre><code>public static void ex01() {

    // 디렉터리 생성/삭제

    // 경로 구분자
    String sep = File.separator;

    // File 객체 선언
    File dir;

    // File 객체 생성 (아래 구문이 공식적으로 윈도우 &amp; 리눅스에서 모두 돌아간다.
    dir = new File(&quot;C:&quot; + sep + &quot;storage&quot;);  // C드라이브 아래에 있는 storage 디렉터리

    // C:\storage 디렉터리가 없으면 만들고, 있으면 지우기
    if(dir.exists()) {
     // dir.deleteOnExit();  // Java 실행이 끝나면 지운다.
     dir.delete();  // 지금 당장 지운다.
     System.out.println(&quot;C:\\storage 디렉터리 삭제 완료&quot;);
    } else {
      dir.mkdirs(); // 폴더 안에 폴더 만들기 가능. (mk : make  , dir : directory)
      System.out.println(&quot;C:\\storage 디렉터리 생성 완료&quot;);
    }  
  }</code></pre><hr>
<h4 id="-ex02-">[ ex02 ]</h4>
<pre><code>public static void ex02() {

    // 파일 생성/삭제

    try {

    // 디렉터리를 File 객체로 생성
      File dir = new File(&quot;C:/storage&quot;); // Windows 플랫폼에서도 슬래시(/)가 인식된다.

    // 디렉터리가 없으면 만들기
      if(!dir.exists()) {
        dir.mkdirs();
      }

    // 파일을 File 객체로 생성
      File file = new File(dir, &quot;myfile.txt&quot;);


    // 파일이 있으면 지우고, 없으면 만들기
      if(file.exists()) {
        file.delete();
        System.out.println(&quot;myfile.txt 파일 삭제 완료&quot;);
      } else {
        file.createNewFile(); // 반드시 예외 처리를 해야 하는 코드
                                (Checked Exception인 IOException 발생)
        System.out.println(&quot;myfile.txt 파일 생성 완료&quot;);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }</code></pre><hr>
<h4 id="-ex03----★중요">[ ex03 ] - ★중요</h4>
<pre><code>public static void ex03() {

    // 파일, 디렉터리 정보 확인
    // listFiles()   : 모든 File 객체를 저장한 File[] 반환
    // getName()     : 이름 반환
    // getParent()   : 저장된 디렉터리 반환
    // getPath()     : getParent() + getName() 
    // lastModified  : 최종수정일을 long 타입으로 반환 (Timestamp 로 반환한다는 뜻)
    // length()      : 크기를 long 타입의 바이트 단위로 반환
    // isDirectory() : 디렉터리이면 true 반환
    // isFile()      : 파일이면 true 반환

    // 디렉터리를 File 객체로 생성
    File dir = new File(&quot;C:/Program Files/Java/jdk-11&quot;);

    // 디렉터리에 있는 모든 File 객체(파일, 디렉터리) 가져오기
    File[] files = dir.listFiles();

    // 디렉터리에 있는 모든 File 객체의 정보 확인하기
    for(int i = 0; i &lt; files.length; i++) {

     // 개별 File 객체
      File file = files[i];

    // 출력 결과 StringBuilder 생성
      StringBuilder sb = new StringBuilder();

    // File 객체 이름
      sb.append(String.format(&quot;%-15s&quot;, file.getName()));

    // File 객체 최종수정일 ( long 타입의 날짜는 Timestamp 이다.)
      long lastModified = file.lastModified();
      String strLastModified = new SimpleDateFormat(&quot;yyyy-MM-dd a 
      h:mm&quot;).format(lastModified);
      // a는 am  |  &#39;H&#39; 는 24시간제, &#39;h&#39; 는 12시간제.                 
      sb.append(String.format(&quot;%-20s&quot;, strLastModified));

    // File 객체 유형(파일, 디렉터리)
      String kind = file.isDirectory() ? &quot;파일 폴더&quot; : &quot;파일&quot;;
      sb.append(String.format(&quot;%-10s&quot;, kind));

    // File 객체 크기
      long size = file.isFile() ? file.length() : 0;  // 파일은 바이트 단위로 크    기가 저장, 디렉터리는 크기가 없으므로 0으로 저장
      long kbSize = (size / 1024) + (size % 1024 != 0 ? 1 : 0);
      if(size != 0) {
      sb.append(String.format(&quot;%10s&quot;, kbSize + &quot;KB&quot;));
      }

    // StringBuilder 객체를 String으로 변환
      String str = sb.toString();

    // 출력
      System.out.println(str);

    }       
  }</code></pre><hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code>public static void main(String[] args) {
    ex03();   
  }
}
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - Exception ( 예외 처리 )]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Exception-%EC%98%88%EC%99%B8-%EC%B2%98%EB%A6%AC</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Exception-%EC%98%88%EC%99%B8-%EC%B2%98%EB%A6%AC</guid>
            <pubDate>Tue, 01 Aug 2023 08:49:15 GMT</pubDate>
            <description><![CDATA[<h3 id="-exception-예외-처리-">[ Exception (예외 처리) ]</h3>
<ul>
<li>예외 처리는 코드 작성자가 예기치 않게 발생하는 에러들에 대응할 수 도록 사전에 방지하는 것이다. </li>
<li>예외 처리를 하면 프로그램의 비정상적인 종료를 방지하여 정상적인 실행 상태를 유지할 수 있다.</li>
</ul>
<hr>
<h4 id="프로그램에서-에러가-발생하는-이유">&lt; 프로그램에서 에러가 발생하는 이유 &gt;</h4>
<ul>
<li><p>에러가 발생하는 원인은 수없이 다양하다. 
하지만 자주 발생하는 에러의 몇 가지 예시는 다음과 같다.</p>
</li>
<li><p>사용자의 입력 실수</p>
</li>
<li><p>네트워크 연결 끊김</p>
</li>
<li><p>메모리 공간 부족</p>
</li>
<li><p>개발자의 코드 실수</p>
</li>
<li><p>유효하지 않는 파일 사용</p>
</li>
</ul>
<p>즉, 에러가 발생하는 원인은 크게 내부적인 요인과 외부적인 요인이 있다.</p>
<p>외부적인 요인에는 입력 에러, 하드웨어 문제, 네트워크 연결 에러 등이 있으며, 내부적인 요인으로는 개발자의 코드 작성에 있다.</p>
<hr>
<h4 id="에러와-예외-error-and-exception">&lt; 에러와 예외 (Error and Exception) &gt;</h4>
<ul>
<li><p>에러(Error)의 경우, 한 번 발생하면 복구하기 어려운 수준의 심각한 문제를 의미하고, 
대표적으로 메모리 부족인 OutOfMemoryError와 스택 오버플로우(StackOverflowError)가 있다.</p>
</li>
<li><p>예외(Exception)는 개발자의 잘못된 사용으로 인해 발생하는 에러는 상대적으로 약한 문제의 수준을 말한다. 즉, 개발자의 실수로 인해 발생하는 것이다. 
(이는 코드 수정을 통해 수습이 가능한 문제이다.)</p>
</li>
</ul>
<p>출처) <a href="https://ittrue.tistory.com/140">https://ittrue.tistory.com/140</a>
(글 작성자가 공부를 위해 위 주소에서 &#39;개념 부분&#39;만 퍼왔음을 알립니다.)</p>
<hr>
<h3 id="try---catch">&lt; try - catch &gt;</h3>
<h4 id="-ex01-">[ ex01 ]</h4>
<pre><code>public static void ex01() {

    try {
      String name = &quot;tom&quot;;
      Integer.parseInt(name); // 발생한 NumberFormatException을 catch 블록으로 던진    다.(throw라고 부름)
    } catch(NumberFormatException e) {  // RuntimeException, Exception 가능
      //예외 객체 이름은 일반적으로 &#39;e&#39;로 부름.
      System.out.println(&quot;예외발생&quot;);
    }
  }</code></pre><hr>
<h4 id="-ex02-">[ ex02 ]</h4>
<pre><code>public static void ex02() {

    try {
      // Scanner 는 import 필수.
      Scanner sc = new Scanner(System.in);
      System.out.println(&quot;덧셈식을 입력하세요(예 : 1+2)&quot;);
      String expr = sc.next();              // split은 배열로 만들어줌.
      String[] numbers = expr.split(&quot;[+]&quot;); // numbers = {&quot;1&quot;, &quot;2&quot;}    // 대괄호[] 를 써주면 정규식이 아닌 문자로 인식한다. 
      int number1 = Integer.parseInt(numbers[0]);
      int number2 = Integer.parseInt(numbers[1]);
      System.out.println(number1 + number2);
      sc.close();
    } catch(NumberFormatException e) {
      System.out.println(&quot;정수 연산만 가능합니다.&quot;);
    } catch(ArrayIndexOutOfBoundsException e) {
      System.out.println(&quot;덧셈식에 +를 포함해서 입력하세요.&quot;);
    } catch(Exception e) {  // NumberFormatException 과 ArrayIndexOutOfBoundsException 으로 처리못하는 예외를 마지막 Exception이 담당한다.
      System.out.println(&quot;알 수 없는 예외가 발생했습니다.&quot;);
    }
      // catch 여러 개 만드는 이유는 사용자에게 안내하기 위해서이다.
  }</code></pre><hr>
<h4 id="-ex03-">[ ex03 ]</h4>
<pre><code> public static void ex03() {

    // 반드시 try - catch가 필요한 예외를 Checked Exception이라고 한다.

    try {
      URL url = new URL(&quot;https://www.naver.com&quot;);
  } catch(Exception e) {
    System.out.println(&quot;예외 발생&quot;);
  // 예외 종류를 공부하는 건 쓸데없음 ( 다 Exception 으로 받으면 됨 )
    }
  }
  public static void main(String[] args) {
    ex02();
  }</code></pre><hr>
<h3 id="finally">&lt; finally &gt;</h3>
<ul>
<li>finally 블록</li>
<li><ol>
<li>try-catch문의 마지막 블록으로 추가할 수 있다. (생략 가능)</li>
</ol>
</li>
<li><ol start="2">
<li>예외 발생 여부와 상관 없이 &quot;항상 마지막&quot;에 실행된다.</li>
</ol>
</li>
</ul>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code> public static void main(String[] args) {

    // 나이를 입력 받아서 &quot;주류 구매 가능&quot;, &quot;주류 구매 불가능&quot; 출력하기
    // 예외 처리

    // try 블록과 finally 블록에서 모두 사용할 수 있도록 scope 조정.
    Scanner sc = null;   // 선언과 생성만 위 아래로 분리.
                         // 객체들의 초기값은 null.
  try {
    sc = new Scanner(System.in);
    System.out.println(&quot;몇 살이세요?&quot;);
    int age = sc.nextInt();   // 정수 입력 받는 것 : nextInt()
    System.out.println(age &gt;= 20 ? &quot;주류 구매 가능&quot; : &quot;주류 구매 불가능&quot;);

  } catch(Exception e) {
    System.out.println(&quot;잘 모르겠어요.&quot;);
  } finally {
    sc.close();
    }
    // finally는 주로 자원 반납용으로 사용한다.
    // close 는 항상 finally에 써준다.
    // scope : 범위 / sc가 선언된 스코프는 try 블록이다. try 블록을 벗어나면 사용 못함.
    // 선언한 곳 { } 에서만 사용할 수 있다. 
  } </code></pre><hr>
<h3 id="throw">&lt; throw &gt;</h3>
<ul>
<li><ol>
<li>예외 객체를 직접 생성(new) 해서 던질 때 사용한다.</li>
</ol>
</li>
<li><ol start="2">
<li>Java는 예외로 판단하지 않는 것들을 던질 때 사용한다.</li>
</ol>
</li>
<li><ol start="3">
<li>개발자가 직접 예외를 처리할 때 사용한다.</li>
</ol>
</li>
</ul>
<hr>
<h4 id="-메인-메소드--1">[ 메인 메소드 ]</h4>
<pre><code> public static void main(String[] args) {

    Scanner sc = null;  
    try {
      sc = new Scanner(System.in);
      System.out.println(&quot;몇 살이세요?&quot;);
      int age = sc.nextInt();   
      if(age &lt; 0 || age &gt; 100) {
        throw new RuntimeException(); // 직접 RuntimeException을 발생시켜서 던진다.
      }
      System.out.println(age &gt;= 20 ? &quot;주류 구매 가능&quot; : &quot;주류 구매 불가능&quot;);

    } catch(Exception e) {
      System.out.println(&quot;잘 모르겠어요.&quot;);
    } finally {
      sc.close();
    }
    }</code></pre><hr>
<h3 id="catch">&lt; catch &gt;</h3>
<h4 id="-ex01--1">[ ex01 ]</h4>
<pre><code>public static void ex01() {

    try {

    // 1. Java가 발생시킨 예외
      // int a = 5 / 0;
      // System.out.println(a);

    // 2. 개발자가 발생시킨 예외
      throw new RuntimeException(&quot;개발자 예외&quot;);

    } catch (Exception e) {

    // 예외 클래스 확인하기
      System.out.println(e.getClass().getName()); // Object의 메소드 활용

    // 예외 메시지 확인하기(예외가 발생한 이유)
      System.out.println(e.getMessage());    
    }  
}</code></pre><hr>
<h4 id="-ex02--1">[ ex02 ]</h4>
<pre><code> public static void ex02(String name) {

// 예외처리 : try {} catch(Exception e) { e.printStackTrace(); }
    try {
      System.out.println(name.substring(0, 1));
    } catch(Exception e) {
      e.printStackTrace();  //예외 추적 메시지를 출력하는 메소드 (개발 중에는 이것만 사용한다.)
    } 
  }

  public static void main(String[] args) {
    ex02(null);
  }</code></pre><hr>
<h3 id="throws">&lt; throws &gt;</h3>
<ul>
<li><ol>
<li>메소드에서 발생하는 모든 예외를 던질 때 사용한다.</li>
</ol>
</li>
<li><ol start="2">
<li>메소드 내부에서 try-catch를 처리하지 않고, 메소드를 호출하는 곳으로 예외를 던질 때 사용한다.</li>
</ol>
</li>
<li><ol start="3">
<li>메소드를 호출하는 곳에서 try-catch를 처리한다.</li>
</ol>
</li>
</ul>
<h4 id="-print-메소드-">[ print 메소드 ]</h4>
<pre><code>   // print 메소드 정의
   // throws NullPointerException : 메소드를 호출할 때 NullPointerException 처리가 필요하다.

   public static void print(String str) throws NullPointerException {

    System.out.println(&quot;첫 글자: &quot; + str.substring(0, 1)); // 0번인덱스 부터 ~ 1번인덱스 전까지.
     System.out.println(&quot;나머지 글자: &quot; + str.substring(1)); // 인덱스가 하나면 끝까지 전부 출력.
     }</code></pre><hr>
<h4 id="-메인-메소드--2">[ 메인 메소드 ]</h4>
<pre><code> public static void main(String[] args) {

    try {
    // print 메소드 호출
    print(&quot;홍길동&quot;);
    print(null);
    } catch (NullPointerException e) {
     System.out.println(e.getMessage());
    }
  }
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - 연습문제9]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%B0%EC%8A%B5%EB%AC%B8%EC%A0%9C9</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%B0%EC%8A%B5%EB%AC%B8%EC%A0%9C9</guid>
            <pubDate>Fri, 28 Jul 2023 05:08:42 GMT</pubDate>
            <description><![CDATA[<h3 id="-게시판제목-작성자-조회수을-저장하는-arraylist-만들기-">[ 게시판(제목, 작성자, 조회수)을 저장하는 ArrayList 만들기 ]</h3>
<hr>
<pre><code>import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

// import를 전부 사용하는 법 : import java.utl.*;  
//  ↑ 절대 사용 금지(알아만 두기)

// 중요 : import가 없을 때 import 자동생성 : Ctrl + Shift + o 


public class MainWrapper {

  public static void main(String[] args) {

    // 게시판(제목, 작성자, 조회수)을 저장하는 ArrayList 만들기
    // Map  : 게시글
    // List : 게시글 목록

    // 3개 게시글을 만들고, ArrayList에 저장하기


    Map&lt;String, Object&gt; board1 = new HashMap&lt;String, Object&gt;();
    board1.put(&quot;title&quot;, &quot;제목1&quot;);
    board1.put(&quot;writer&quot;, &quot;작성자1&quot;);
    board1.put(&quot;view&quot;, &quot;10&quot;);


    Map&lt;String, Object&gt; board2 = new HashMap&lt;String, Object&gt;();
    board2.put(&quot;title&quot;, &quot;제목2&quot;);
    board2.put(&quot;writer&quot;, &quot;작성자2&quot;);
    board2.put(&quot;view&quot;, &quot;20&quot;);


    Map&lt;String, Object&gt; board3 = new HashMap&lt;String, Object&gt;();
    board3.put(&quot;title&quot;, &quot;제목3&quot;);
    board3.put(&quot;writer&quot;, &quot;작성자3&quot;);
    board3.put(&quot;view&quot;, &quot;30&quot;);

    // ArrayList 선언 &amp; 생성
    List&lt;Map&lt;String, Object&gt;&gt; boardList = new ArrayList&lt;Map&lt;String, Object&gt;&gt;();

    // ArrayList에 저장
    boardList.add(board1);
    boardList.add(board2);
    boardList.add(board3);

    // 게시글 정보 확인
    for(int i=0, length = boardList.size(); i&lt;length; i++) {

     Map&lt;String, Object&gt; board = boardList.get(i);
     System.out.println(&quot;title: &quot; + board.get(&quot;title&quot;));
     System.out.println(&quot;writer: &quot; + board.get(&quot;writer&quot;));
     System.out.println(&quot;view: &quot; + board.get(&quot;view&quot;));


     //for(Entry&lt;String, Object&gt; entry : board.entrySet()) {
     //System.out.println(entry.getKey() + &quot;: &quot; + entry.getValue());
     // }

    }

  }
}
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - 연습문제8]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%B0%EC%8A%B5%EB%AC%B8%EC%A0%9C7</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%B0%EC%8A%B5%EB%AC%B8%EC%A0%9C7</guid>
            <pubDate>Fri, 28 Jul 2023 03:14:36 GMT</pubDate>
            <description><![CDATA[<h3 id="-교실의-학생-정보를-저장하는-hashmap-만들기-">[ 교실의 학생 정보를 저장하는 HashMap 만들기 ]</h3>
<hr>
<pre><code> public static void main(String[] args) {

    // 교실의 학생 정보를 저장하는 HashMap 만들기
    // Key   : 학번(예: 10101)
    // Value : Student 객체

    // HashMap 선언 &amp; 생성
    Map&lt;Integer, Student&gt; clazz = new HashMap&lt;Integer, Student&gt;();

    // Entry 저장
    clazz.put(10101, new Student(&quot;가길동&quot;, new Exam(100, 100, 100)));
    clazz.put(10102, new Student(&quot;나길동&quot;, new Exam(90, 90, 90)));

    Integer[] stuNo = {10101, 10102};
    for(int i = 0; i &lt; stuNo.length; i++) {
      Student student = clazz.get(stuNo[i]);
      System.out.println(&quot;이름: &quot; + student.getName());
      System.out.println(&quot;시험: &quot; + student.getName());
    }
  }</code></pre><hr>
<h4 id="-시험-클래스-">[ 시험 클래스 ]</h4>
<pre><code>public class Exam {

    private int kro;
    private int eng;
    private int math;

    // new Exam(100, 100, 100)
    public Exam(int kro, int eng, int math) {
      super();
      this.kro = kro;
      this.eng = eng;
      this.math = math;
    }

    public int getKro() {
      return kro;
    }

    public void setKro(int kro) {
      this.kro = kro;
    }

    public int getEng() {
      return eng;
    }

    public void setEng(int eng) {
      this.eng = eng;
    }

    public int getMath() {
      return math;
    }

    public void setMath(int math) {
      this.math = math;
    }

    @Override
    public String toString() {
      return &quot;Exam [kro=&quot; + kro + &quot;, eng=&quot; + eng + &quot;, math=&quot; + math + &quot;]&quot;;
    }</code></pre><hr>
<h4 id="-학생-클래스-">[ 학생 클래스 ]</h4>
<pre><code>public class Student {

  private String name;
  private Exam exam;

  public Student() {
  }

  public Student(String name, Exam exam) {
    super();
    this.name = name;
    this.exam = exam;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Exam getExam() {
    return exam;
  }

  public void setExam(Exam exam) {
    this.exam = exam;
  } </code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - Map, HashMap]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Map-HashMap</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Map-HashMap</guid>
            <pubDate>Fri, 28 Jul 2023 01:56:46 GMT</pubDate>
            <description><![CDATA[<h3 id="-hashmap-">[ HashMap ]</h3>
<ul>
<li><ol>
<li>Map 인터페이스를 구현한 클래스</li>
</ol>
</li>
<li><ol start="2">
<li>객체(Object)/인스턴스(Instance)를 대신할 수 있는 자료구조이다.</li>
</ol>
</li>
<li><ol start="3">
<li>용어</li>
</ol>
<ul>
<li>1) Entry : Key + Value를 합쳐서 부르는 말</li>
<li>2) Key   : 데이터를 식별하는 식별자( 변수명, ex: name ) </li>
<li>3) Value : 데이터 자체( 변수에 저장된 값, ex: 홍길동 )</li>
</ul>
</li>
<li><ol start="4">
<li>특징</li>
</ol>
<ul>
<li><p>1) Key는 중복이 불가능하다. (HashSet 구조로 되어 있다.)</p>
</li>
<li><p>2) Value는 중복이 가능하다.</p>
</li>
<li><p>3) Key와 Value 모두 Generic 처리한다. 
(Key의 타입과 Value의 타입을 따로따로 잡아주어야 한다는 말)  </p>
</li>
<li><p>Key 만 저장하는 건 Set 이다.</p>
</li>
</ul>
</li>
</ul>
<hr>
<h4 id="-ex01-">[ ex01 ]</h4>
<pre><code> public static void ex01() {

    // Map 인터페이스 타입으로 HashMap 선언
    //Map&lt;K(Key), V(value)&gt;
    Map&lt;String, String&gt; dict;

    // HashMap 생성
    dict = new HashMap&lt;String, String&gt;();

    // Entry 저장(Key, Value) : key와 value 를 합쳐서 entry라고 부른다. 
    실제 데이    터는 밸류임.
    dict.put(&quot;봄&quot;, &quot;spring&quot;);    // 봄이라는 키를 전달하면, spring이라는 밸류가 나옴.
    dict.put(&quot;여름&quot;, &quot;summer&quot;);
    dict.put(&quot;가을&quot;, &quot;autumn&quot;);
    dict.put(&quot;겨울&quot;, &quot;winter&quot;);

    // Value 확인(Key를 전달한다.)
    System.out.println(dict.get(&quot;봄&quot;));
    System.out.println(dict.get(&quot;여름&quot;));
    System.out.println(dict.get(&quot;가을&quot;));
    System.out.println(dict.get(&quot;겨울&quot;));
  }</code></pre><hr>
<h4 id="-ex02-">[ ex02 ]</h4>
<pre><code>public static void ex02() {

    // HashMap 선언 &amp; 생성
    // Object는 전부 저장할 수 있는 만능 타입.
    Map&lt;String, Object&gt; person = new HashMap&lt;String, Object&gt;();

    // Entry 저장(Key는 변수명으로, Value는 변수값으로 저장)
    person.put(&quot;name&quot;, &quot;홍길동&quot;);
    person.put(&quot;age&quot;, 30);

    // Entry 수정(기존의 key를 사용하면 해당 키의 Value가 수정되는 방식.
    person.put(&quot;name&quot;, &quot;제시카&quot;);
    person.put(&quot;age&quot;, 40);   

    // Value 확인
    System.out.println(person.get(&quot;name&quot;)); // 홍길동
    System.out.println(person.get(&quot;age&quot;));  // 30
  }</code></pre><hr>
<h4 id="-ex03-">[ ex03 ]</h4>
<pre><code>public static void ex03() {

    // HashMap 선언 &amp; 생성
    Map&lt;String, Object&gt; map = new HashMap();

    // Entry 저장
    map.put(&quot;top&quot;, 10);
    map.put(&quot;bottom&quot;, 20);
    map.put(&quot;left&quot;, 30);
    map.put(&quot;right&quot;, 40);

    // 반복자(Iterator)를 이용한 순회
    // 1. Key만 모두 꺼내서 Set에 저장한다. (keySet 메소드)
    // 2. Set에 반복자(Iterator)를 붙여서 Key를 하나씩 꺼낸다.
    // 3. get() 메소드에 key를 전달하면 Value가 나온다.
    Set&lt;String&gt; keySet = map.keySet();       
    Iterator&lt;String&gt; arm = keySet.iterator();
    while(arm.hasNext()) {                  
      String key = arm.next();
      Object value = map.get(key);
      System.out.println(key + &quot;: &quot; + value);
    }
  }</code></pre><hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code>public static void main(String[] args) {
    //ex01();
    //ex02();
    ex03();
  }</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[객체, 인스턴스, 클래스]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EA%B0%9D%EC%B2%B4-%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4-%ED%81%B4%EB%9E%98%EC%8A%A4</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EA%B0%9D%EC%B2%B4-%EC%9D%B8%EC%8A%A4%ED%84%B4%EC%8A%A4-%ED%81%B4%EB%9E%98%EC%8A%A4</guid>
            <pubDate>Fri, 28 Jul 2023 01:19:12 GMT</pubDate>
            <description><![CDATA[<h3 id="-클래스-객체-인스턴스의-개념-">[ 클래스, 객체, 인스턴스의 개념 ]</h3>
<p>출처 ) <a href="https://gmlwjd9405.github.io/2018/09/17/class-object-instance.html">https://gmlwjd9405.github.io/2018/09/17/class-object-instance.html</a>  </p>
<ul>
<li>해당 글은 위 출처에서 본문 그대로 퍼왔음을 알립니다.</li>
<li>아래는 작성자가 공부용으로 보기 편하게 정리해놓은 것임을 참고하시기 바랍니다.</li>
</ul>
<hr>
<h4 id="-클래스class-">[ 클래스(Class) ]</h4>
<ul>
<li>개념 : <ul>
<li>객체를 만들어 내기 위한 설계도 혹은 틀</li>
<li>연관되어 있는 변수와 메서드의 집합</li>
</ul>
</li>
</ul>
<h4 id="-객체object-">[ 객체(Object) ]</h4>
<ul>
<li>개념 : <ul>
<li>소프트웨어 세계에 구현할 대상</li>
<li>클래스에 선언된 모양 그대로 생성된 실체</li>
</ul>
</li>
</ul>
<h4 id="-특징-">[ 특징 ]</h4>
<ul>
<li>‘클래스의 인스턴스(instance)’ 라고도 부른다.</li>
<li>객체는 모든 인스턴스를 대표하는 포괄적인 의미를 갖는다.</li>
<li>oop의 관점에서 클래스의 타입으로 선언되었을 때 ‘객체’라고 부른다.</li>
</ul>
<h4 id="-인스턴스instance-">[ 인스턴스(Instance) ]</h4>
<ul>
<li>개념 :<ul>
<li>설계도를 바탕으로 소프트웨어 세계에 구현된 구체적인 실체
즉, 객체를 소프트웨어에 실체화 하면 그것을 ‘인스턴스’라고 부른다.</li>
<li>실체화된 인스턴스는 메모리에 할당된다.</li>
</ul>
</li>
</ul>
<h4 id="-특징--1">[ 특징 ]</h4>
<ul>
<li><p>인스턴스는 객체에 포함된다고 볼 수 있다.</p>
</li>
<li><p>oop의 관점에서 객체가 메모리에 할당되어 실제 사용될 때 ‘인스턴스’라고 부른다.</p>
</li>
<li><p>추상적인 개념(또는 명세)과 구체적인 객체 사이의 관계 에 초점을 맞출 경우에 사용한다.
( ‘~의 인스턴스’ ) 의 형태로 사용된다.</p>
</li>
<li><p>객체는 클래스의 인스턴스다.</p>
</li>
<li><p>객체 간의 링크는 클래스 간의 연관 관계의 인스턴스다.</p>
</li>
<li><p>실행 프로세스는 프로그램의 인스턴스다.</p>
</li>
<li><p>즉, 인스턴스라는 용어는 반드시 클래스와 객체 사이의 관계로 한정지어서 사용할 필요는 없다.</p>
</li>
<li><p>인스턴스는 어떤 원본(추상적인 개념)으로부터 ‘생성된 복제본’을 의미한다.</p>
</li>
</ul>
<hr>
<h4 id="-예시-">[ 예시 ]</h4>
<pre><code>[ 클래스 ]
public class Animal {
  ...
}

[ 객체와 인스턴스 ]
public class Main {
  public static void main(String[] args) {
    Animal cat, dog; // &#39;객체&#39;

[ 인스턴스화 ]
    cat = new Animal(); // cat은 Animal 클래스의 &#39;인스턴스&#39;(객체를 메모리에 할당)
    dog = new Animal(); // dog은 Animal 클래스의 &#39;인스턴스&#39;(객체를 메모리에 할당)
  }
}</code></pre><hr>
<h3 id="-클래스-객체-인스턴스의-차이-">[ 클래스, 객체, 인스턴스의 차이 ]</h3>
<h4 id="클래스class-vs-객체object">클래스(Class) VS 객체(Object)</h4>
<ul>
<li>클래스는 ‘설계도’, 객체는 ‘설계도로 구현한 모든 대상’을 의미한다.</li>
</ul>
<h4 id="객체object-vs-인스턴스instance">객체(Object) VS 인스턴스(Instance)</h4>
<ul>
<li><p>클래스의 타입으로 선언되었을 때 객체라고 부르고, 
그 객체가 메모리에 할당되어 실제 사용될 때 인스턴스라고 부른다.</p>
</li>
<li><p>객체는 현실 세계에 가깝고, 인스턴스는 소프트웨어 세계에 가깝다.</p>
</li>
<li><p>객체는 ‘실체’, 인스턴스는 ‘관계’에 초점을 맞춘다.</p>
</li>
<li><p>객체를 ‘클래스의 인스턴스’라고도 부른다.</p>
</li>
<li><p>‘방금 인스턴스화하여 레퍼런스를 할당한’ 객체를 인스턴스라고 말하지만, 
이는 원본(추상적인 개념)으로부터 생성되었다는 것에 의미를 부여하는 것일 뿐 
엄격하게 객체와 인스턴스를 나누긴 어렵다.</p>
</li>
</ul>
<hr>
<p>[ 참고 ]</p>
<p>추상화 기법
분류(Classification)
객체 -&gt; 클래스
실재하는 객체들을 공통적인 속성을 공유하는 범부 또는 추상적인 개념으로 묶는 것
인스턴스화(Instantiation)
클래스 -&gt; 인스턴스
분류의 반대 개념. 범주나 개념으로부터 실재하는 객체를 만드는 과정
구체적으로 클래스 내의 객체에 대해 특정한 변형을 정의하고, 이름을 붙인 다음, 그것을 물리적인 어떤 장소에 위치시키는 등의 작업을 통해 인스턴스를 만드는 것을 말한다.
‘예시(Exemplification)’라고도 부른다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - Set , 반복자( Iterator ) , hash]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Set</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Set</guid>
            <pubDate>Thu, 27 Jul 2023 06:22:23 GMT</pubDate>
            <description><![CDATA[<h3 id="-set-">[ Set ]</h3>
<ul>
<li><ol>
<li>인덱스가 없다. 저장 순서가 없다.</li>
</ol>
</li>
<li><ol start="2">
<li>중복 저장이 되지 않는다.</li>
</ol>
</li>
<li><ol start="3">
<li>ArrayList 랑 사용법이 같다.
( ArrayList 를 주로 사용)</li>
</ol>
</li>
</ul>
<hr>
<h4 id="-hash-">[ hash ]</h4>
<ul>
<li>사용목적 : 빠른 검색을 위해서.</li>
<li>hash 와 equals 는 같이 다닌다.</li>
</ul>
<hr>
<h4 id="-iterator-">[ Iterator ]</h4>
<ul>
<li>인덱스 없이 순회를 돌릴 수 있다.</li>
</ul>
<hr>
<h4 id="-ex01-">[ ex01 ]</h4>
<pre><code>public static void ex01() {

    // Set 인터페이스 타입 선언
    Set&lt;String&gt; season;

    // HashSet 클래스 객체 생성
    season = new HashSet&lt;String&gt;();

    // 요소 추가하기
    season.add(&quot;봄&quot;);
    season.add(&quot;여름&quot;);
    season.add(&quot;가을&quot;);
    season.add(&quot;겨울&quot;);
    season.add(&quot;봄&quot;);

    // 전체 확인
    System.out.println(season);
  }</code></pre><hr>
<h4 id="-ex02-">[ ex02 ]</h4>
<pre><code> public static void ex02() {

    // HashSet 선언 &amp; 생성
    Set&lt;String&gt; hobbies = new HashSet&lt;String&gt;();

    // 요소 저장하기
    hobbies.add(&quot;독서&quot;);
    hobbies.add(&quot;요리&quot;);
    hobbies.add(&quot;운동&quot;);
    hobbies.add(&quot;체스&quot;);

    // for문 활용하기 (인덱스가 없으므로 향상된 for문)
    //for(변수 : 세트)
    for(String hobby : hobbies) {
    System.out.println(hobby);
    }
  }</code></pre><hr>
<h4 id="-ex03-">[ ex03 ]</h4>
<pre><code> public static void ex03() {

    // HashSet 선언 &amp; 생성
    Set&lt;String&gt; flower = new HashSet&lt;String&gt;();

    // 요소 저장하기
    flower.add(&quot;국화&quot;);
    flower.add(&quot;튤립&quot;);
    flower.add(&quot;프리지마&quot;);
    flower.add(&quot;물망초&quot;);

    // 반복자 Iterator를 이용한 Set 순회 ( for문 대신 사용한다.)
    Iterator&lt;String&gt; arm = flower.iterator();

    // 조건 : arm.hasNext()
    // 실행 : System.out.println(arm.next());
    while(arm.hasNext()) {
      System.out.println(arm.next());      
    } 
  }</code></pre><ul>
<li>객체.hasNext 는 &quot;잡을 수 있는 게 있는지 확인해라&quot;</li>
<li>객체.next 는 &#39;다음&#39;의 의미가 아니고, &quot;요소를 잡아서 꺼내라&quot;.</li>
</ul>
<hr>
<h4 id="-ex04-">[ ex04 ]</h4>
<pre><code> public static void ex04() {

    // 동일한 객체 2개
    Person p1 = new Person(&quot;이순신&quot;, 30);
    Person p2 = new Person(&quot;이순신&quot;, 30);

    // HashSet 선언 &amp; 생성
    Set&lt;Person&gt; people = new HashSet&lt;Person&gt;();

    // 요소 추가
    people.add(p1);
    people.add(p2);

    // 확인
    System.out.println(people);
  }</code></pre><hr>
<h4 id="-ex05-">[ ex05 ]</h4>
<pre><code> public static void ex05() {

    // ArrayList 선언 &amp; 생성
    List&lt;Integer&gt; numbers1 = Arrays.asList(1, 2, 3, 4, 5);
    List&lt;Integer&gt; numbers2 = Arrays.asList(6, 7, 3, 4, 5);

    // ArrayList를 이용해서 HashSet 생성
    Set&lt;Integer&gt; set1 = new HashSet&lt;Integer&gt;(numbers1);
    Set&lt;Integer&gt; set2 = new HashSet&lt;Integer&gt;(numbers2);

    // 교집합
    set1.retainAll(set2);  // 교집합 결과는 set1에 저장된다.

    System.out.println(set1);  // [3, 4, 5]

  }</code></pre><hr>
<h4 id="-ex06-">[ ex06 ]</h4>
<pre><code>  public static void ex06() {

    // ArrayList 선언 &amp; 생성
    List&lt;Integer&gt; numbers1 = Arrays.asList(1, 2, 3, 4, 5);
    List&lt;Integer&gt; numbers2 = Arrays.asList(6, 7, 3, 4, 5);

    // ArrayList를 이용해서 HashSet 생성
    Set&lt;Integer&gt; set1 = new HashSet&lt;Integer&gt;(numbers1);
    Set&lt;Integer&gt; set2 = new HashSet&lt;Integer&gt;(numbers2);

    // 합집합
    set1.addAll(set2);  // 합집합 결과는 set1에 저장된다.

    System.out.println(set1);  // [1, 2, 3, 4, 5, 6, 7]
  }</code></pre><hr>
<h4 id="-ex07-">[ ex07 ]</h4>
<pre><code>  public static void ex07() {

    // ArrayList 선언 &amp; 생성
    List&lt;Integer&gt; numbers1 = Arrays.asList(1, 2, 3, 4, 5);
    List&lt;Integer&gt; numbers2 = Arrays.asList(6, 7, 3, 4, 5);

    // ArrayList를 이용해서 HashSet 생성
    Set&lt;Integer&gt; set1 = new HashSet&lt;Integer&gt;(numbers1);
    Set&lt;Integer&gt; set2 = new HashSet&lt;Integer&gt;(numbers2);

    // 차집합
    set1.removeAll(set2);  // 차집합 결과는 set1에 저장된다.

    System.out.println(set1);  // [1, 2]
  }</code></pre><hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code> public static void main(String[] args) {
   //ex01();
   //ex02();
   //ex03();
   ex04();
  }</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - 연습문제7]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%B0%EC%8A%B5%EB%AC%B8%EC%A0%9C-gdz40b06</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%B0%EC%8A%B5%EB%AC%B8%EC%A0%9C-gdz40b06</guid>
            <pubDate>Thu, 27 Jul 2023 02:53:06 GMT</pubDate>
            <description><![CDATA[<h4 id="-person-타입을-전달해서-값을-넣기-">[ Person 타입을 전달해서 값을 넣기 ]</h4>
<pre><code>public class MainWrapper {

  public static void main(String[] args) {

    List&lt;Person&gt; family = new ArrayList&lt;Person&gt;();

    //문제 : 가족 모두 저장하고 for문으로 확인하기

    // 배열 요소 추가
    // 두 번째 생성자를 바로 전달하는 구문.
    family.add(new Person(&quot;엄마&quot;, 30));
    family.add(new Person(&quot;아빠&quot;, 34));
    family.add(new Person(&quot;누나&quot;, 20));
    family.add(new Person(&quot;나&quot;, 17));

    // 배열 요소 확인
    System.out.println(family.get(0));
    System.out.println(family.get(1));
    System.out.println(family.get(2));
    System.out.println(family.get(3));

    // 배열 길이 확인
    System.out.println(family.size());


    // for문
    for(int i=0, length=family.size(); i&lt;length; i++) {
      System.out.println(family.get(i));
      System.out.println(&quot;이름: &quot; + family.get(i).getName());
      System.out.println(&quot;나이: &quot; + family.get(i).getAge());
    }
  }
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - List ( ArrayList )]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-List-ArrayList</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-List-ArrayList</guid>
            <pubDate>Thu, 27 Jul 2023 02:50:46 GMT</pubDate>
            <description><![CDATA[<h3 id="-arraylist-">[ ArrayList ]</h3>
<ul>
<li><p>ArrayList란 Collection 프레임워크의 일부이며 
java.util 패키지에 소속되어 있습니다</p>
</li>
<li><p>표준 배열보다는 느리지만 배열에서 많은 조작이 필요한 경우 유용하게 사용할 수 있습니다</p>
</li>
<li><p>List 인터페이스에서 상속받아 사용이 됩니다</p>
</li>
<li><p>ArrayList는 객체가 추가되어 용량을 초과하면 자동으로 부족한 크기만큼 용량이 늘어납니다</p>
</li>
</ul>
<p>↑ 내용 펌) <a href="https://crazykim2.tistory.com/558">https://crazykim2.tistory.com/558</a></p>
<ul>
<li>객체를 새로 만들 때 아니면, 변경시에는 new를 적지 않는다.</li>
</ul>
<hr>
<ul>
<li><p>배열 요소 추가 : 객체.add(&quot;스카이다이빙&quot;);</p>
</li>
<li><p>배열 요소 수정 : 객체.set(0, &quot;백일홍&quot;);</p>
</li>
<li><p>배열 요소 삭제 : 객체.remove(1);</p>
</li>
<li><p>배열 요소 확인 : 객체.get(0)
ex) System.out.println(객체.get(0));</p>
</li>
<li><p>배열 길이 확인 : 객체.size()</p>
</li>
<li><p>배열 마지막 인덱스 확인 : 배열 길이 - 1</p>
<pre><code>: hobbies.get(hobbies.size() - 1)</code></pre><p>ex) System.out.println(hobbies.get(hobbies.size() - 1));</p>
</li>
<li><p>배열 요소 전체 확인 :
for(int i = 0, length = 객체.size(); i &lt; length; i++) {</p>
<pre><code>System.out.println(객체.get(i));</code></pre></li>
<li><p>배열의 각 필드값 확인
System.out.println(&quot;이름: &quot; + 객체.get(i).getName());
System.out.println(&quot;나이: &quot; + 객체.get(i).getAge());</p>
</li>
</ul>
<hr>
<h4 id="-관계-">[ 관계 ]</h4>
<pre><code>/*
 *  ┌--------------┐
 *  │     List     │ List 인터페이스
 *  │--------------│
 *  │   add();     │
 *  │   get();     │
 *  │   size();    │
 *  │   set();     │
 *  │   remove();  │
 *  └--------------┘
 *          ▲
 *          │
 *          │
 *  ┌--------------┐
 *  │   ArrayList  │ ArrayList 클래스
 *  │--------------│
 *  │   add(){}    │ 요소 추가하기
 *  │   get(){}    │ 요소 가져오기
 *  │   size(){}   │ 요소 개수 반환하기
 *  │   set(){}    │ 요소 수정하기
 *  │   remove(){} │ 요소 삭제하기
 *  └--------------┘
 */</code></pre><h4 id="-ex01-">[ ex01 ]</h4>
<pre><code> public static void ex01() {

  // java.util.List. 
  // 자동완성 : Ctrl+Space 하면 util.java 뜸.
  // ArrayList의 인터페이스 List 타입 선언
    List&lt;String&gt; season;

    // ArrayList 생성
    // ArrayList 자동완성 util 선택.
    season = new ArrayList&lt;String&gt;();
    //부모타입으로 자식타입에 저장할 수 있는거랑 같음.

    // 배열 요소 추가하기
    season.add(&quot;여름&quot;);
    season.add(&quot;가을&quot;);
    season.add(&quot;겨울&quot;);
    season.add(0, &quot;봄&quot;); // 인덱스 0에 &quot;봄&quot;이 들어감.

    // 배열 요소 확인하기
    // 배열.get 메소드 쓰는 거 주의
    System.out.println(season.get(0));
    System.out.println(season.get(1));
    System.out.println(season.get(2));
    System.out.println(season.get(3));

  }</code></pre><hr>
<h4 id="-ex02-">[ ex02 ]</h4>
<pre><code>public static void ex02() {

 // ArrayList의 선언 &amp; 생성
    List&lt;String&gt; hobbies = new ArrayList&lt;String&gt;();

    // 배열 요소 추가하기
    hobbies.add(&quot;번지점프&quot;);
    hobbies.add(&quot;스노쿨링&quot;);
    hobbies.add(&quot;스카이다이빙&quot;);

    // 배열 길이 확인 (저장된 요소의 갯수)
    // 객체.size() : 배열 길이 확인.
    System.out.println(hobbies.size());
    // 처음에 배열의 길이를 잡지 않아도 됨.

    // 배열 길이 관련 (마지막 요소 꺼내기)
    System.out.println(hobbies.get(hobbies.size() - 1));

    // 배열 for문 적용하기 (동일한 메소드를 여러 번 불러서 사용하면 성능저하가 발생한다.)
    // 여기에서는 hobbies.length 가 아님.
    for(int i=0; i &lt; hobbies.size(); i++) {
      System.out.println(hobbies.get(i));
    }  
    // 배열 for문 적용하기 (리팩토링 : hobbies.size() 메소드가 여러 번 호출되는 문제 해결)
    // 변수 length를 만들어서 hobbies 길이 넣고 돌림
      for(int i = 0, length = hobbies.size(); i &lt; length; i++) {
        System.out.println(hobbies.get(i));
      }
}</code></pre><hr>
<h4 id="-ex03---내용-겹쳐서-생략">[ ex03 ] : 내용 겹쳐서 생략</h4>
<hr>
<h4 id="-ex04-">[ ex04 ]</h4>
<pre><code>public static void ex04() {
 // 배열을 ArrayList로 바꾸기
    Integer[] a = {10, 20, 30, 40, 50};
    List&lt;Integer&gt; numbers = Arrays.asList(a);
    // int[] a 로 하면 안되고, 레퍼런스타입 Integer로 해야 한다.

    // 주의!!!!! 초기화된 ArrayList는 길이를 변경할 수 없다.
    // numbers.add(60); 불가능
    // numbers.remove(0); 불가능

    // for문
    for(int i=0, length=numbers.size(); i &lt; length; i++) {
      System.out.println(numbers.get(i));
    }
  }</code></pre><hr>
<h4 id="-ex05-">[ ex05 ]</h4>
<pre><code>
public static void ex05() {

    // ArrayList 초기화
    // 자동완성시 asList(T...a) 는 말줄임표로 요소의 개수 상관 없이 원하는 만큼 넣을 수 있다.(말줄임표는 사실 배열이다.)
    List&lt;Integer&gt; numbers = Arrays.asList(10,20,30,40,50);

    // for문
    for(int i=0, length=numbers.size(); i&lt;length; i++) {
      System.out.println(numbers.get(i));
    }
  }</code></pre><hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code> public static void main(String[] args) {
   //ex01();
    ex02();
  }</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - Generic]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Generic</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Generic</guid>
            <pubDate>Thu, 27 Jul 2023 01:18:07 GMT</pubDate>
            <description><![CDATA[<h3 id="-generic---포괄적인-일반적인">[ Generic ] : 포괄적인, 일반적인.</h3>
<ul>
<li><p>데이터 형식에 의존하지 않고,
하나의 값이 여러 다른 데이터 타입들을 가질 수 있도록 하는 방법</p>
</li>
<li><p>&lt;&gt; 괄호 안에 들어가는 타입을 지정해준다.</p>
</li>
<li><p>객체&lt;타입&gt; 객체명 = new 객체&lt;타입&gt;(); 이렇게 쓰지 않는가? 즉, 아래와 같이 여러 생성방식이 있다.</p>
</li>
<li><p>사용 이유 : 만약에 우리가 어떤 자료구조를 만들어 배포하려고 한다. 그런데 String 타입도 지원하고싶고 Integer타입도 지원하고 싶고 많은 타입을 지원하고 싶다. 그러면 String에 대한 클래스, Integer에 대한 클래스 등 하나하나 타입에 따라 만들 것인가? 그건 너무 비효율적이다. 이러한 문제를 해결하기 위해 우리는 제네릭이라는 것을 사용한다.</p>
</li>
<li><p>이렇듯 제네릭(Generic)은 클래스 내부에서 지정하는 것이 아닌 외부에서 사용자에 의해 지정되는 것을 의미한다. 한마디로 특정(Specific) 타입을 미리 지정해주는 것이 아닌 필요에 의해 지정할 수 있도록 하는 일반(Generic) 타입이라는 것이다.</p>
</li>
</ul>
<p>(정확히 말하자면 지정된다는 것 보다는 타입의 경계를 지정하고, 컴파일 때 해당 타입으로 캐스팅하여 매개변수화 된 유형을 삭제하는 것이다.</p>
<p>[ 장점 ]</p>
<ul>
<li><p>제네릭을 사용하면 잘못된 타입이 들어올 수 있는 것을 컴파일 단계에서 방지할 수 있다.</p>
</li>
<li><p>클래스 외부에서 타입을 지정해주기 때문에 따로 타입을 체크하고 변환해줄 필요가 없다. 즉, 관리하기가 편하다.</p>
</li>
<li><p>비슷한 기능을 지원하는 경우 코드의 재사용성이 높아진다.</p>
</li>
</ul>
<p>↑ 글 펌) <a href="https://st-lab.tistory.com/153">https://st-lab.tistory.com/153</a></p>
<hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code>public static void main(String[] args) {

    // String(문자열)을 저장하는 박스.
    Box&lt;String&gt; box1 = new Box&lt;String&gt;();
    box1.setItem(&quot;Hello world&quot;);
    System.out.println(box1.getItem());

    // int(정수)를 저장하는 box2
    // 오직 &quot;참조타입&quot;만 Generic 처리에서 사용할 수 있다.
    // int의 참조타입인 Integer를 사용한다.
    Box&lt;Integer&gt; box2 = new Box&lt;Integer&gt;();
    box2.setItem(10);
    System.out.println(box2.getItem());
    // Wrapper Class (기본형의 참조타입)
    // Boolean, Byte, Character, Integer, Long, Double

    // Person을 저장하는 box3
    Box&lt;Person&gt; box3 = new Box&lt;Person&gt;();
    box3.setItem(new Person(&quot;홍길동&quot;));
    System.out.println(box3.getItem());

  }
</code></pre><hr>
<h4 id="-box-클래스-">[ Box 클래스 ]</h4>
<ul>
<li><p>generic 사용 : Box&lt; String 타입의 이름 입력 &gt;</p>
<pre><code>public class Box&lt;T&gt; {

private T item;

public T getItem() {
  return item;
}
public void setItem(T item) {
  this.item = item;
}
</code></pre></li>
</ul>
<p>}</p>
<pre><code></code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - 연습문제6]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%B0%EC%8A%B5%EB%AC%B8%EC%A0%9C-gn5chdmu</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%B0%EC%8A%B5%EB%AC%B8%EC%A0%9C-gn5chdmu</guid>
            <pubDate>Wed, 26 Jul 2023 03:40:06 GMT</pubDate>
            <description><![CDATA[<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<ul>
<li>메인 메소드를 보고 출력되도록 만들기.</li>
</ul>
<pre><code>public class MainWrapper {

  public static void main(String[] args) {

    TourGuide guide1 = new TourGuide();
    guide1.setTour(new HawaiiTour());
    guide1.sightseeing();
    guide1.leisure();
    guide1.meal();

    TourGuide guide2 = new TourGuide();
    guide2.setTour(new JapanTour());
    guide2.sightseeing();
    guide2.leisure();
    guide2.meal();

  }</code></pre><hr>
<h4 id="-여행-인터페이스-">[ 여행 인터페이스 ]</h4>
<pre><code>//인터페이스를 만들면 무조건 인터페이스(Tour)를 타입으로 쓴다.
public interface Tour {
  void sightseeing();
  void leisure();
  void meal();

}</code></pre><hr>
<h4 id="-여행-가이드-클래스-">[ 여행 가이드 클래스 ]</h4>
<pre><code>public class TourGuide implements Tour {

  // Field
  private Tour tour;

  // Method
  public Tour getTour() {
    return tour;
  }

  public void setTour(Tour tour) {
    this.tour = tour;
  }

  public void sightseeing() {
    tour.sightseeing();
  }

  public void leisure() {
    tour.leisure();
  }

  public void meal() {
    tour.meal();
  }
}
</code></pre><hr>
<h4 id="-하와이-여행-클래스-">[ 하와이 여행 클래스 ]</h4>
<pre><code>public class HawaiiTour implements Tour {

  @Override
  public void sightseeing() {
    System.out.println(&quot;와이키키해변&quot;);

  }

  @Override
  public void leisure() {
    System.out.println(&quot;헬기투어&quot;);

  }

  @Override
  public void meal() {
    System.out.println(&quot;파인애플피자&quot;);

  }
}
</code></pre><hr>
<h4 id="-일본-여행-클래스-">[ 일본 여행 클래스 ]</h4>
<pre><code>public class JapanTour implements Tour {

  @Override
  public void sightseeing() {
    System.out.println(&quot;돈키호테&quot;);

  }

  @Override
  public void leisure() {
    System.out.println(&quot;온천&quot;);

  }

  @Override
  public void meal() {
    System.out.println(&quot;스시&quot;);

  }
}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - 인터페이스 ( Interface )]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%9D%B8%ED%84%B0%ED%8E%98%EC%9D%B4%EC%8A%A4-Interface</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%9D%B8%ED%84%B0%ED%8E%98%EC%9D%B4%EC%8A%A4-Interface</guid>
            <pubDate>Wed, 26 Jul 2023 02:45:55 GMT</pubDate>
            <description><![CDATA[<h3 id="-인터페이스-">[ 인터페이스 ]</h3>
<ul>
<li><ol>
<li>JDK 1.7 이전에는 &quot;추상 메소드 + final 상수&quot; 로만 구성된 추상 클래스를 의미한다.</li>
</ol>
</li>
<li><ol start="2">
<li>JDK 1.8 이후로는 &quot;추상 메소드 + default 메소드 + static 메소드 + final 상수&quot; 로 구성된다.</li>
</ol>
<ul>
<li>1) 추상 메소드    : 본문이 없는 메소드 (대부분은 추상 메소드로 구성됨)</li>
<li>2) default 메소드 : 본문이 있는 메소드</li>
<li>3) static  메소드 : 클래스 메소드 (본문 있음)</li>
</ul>
</li>
<li><ol start="3">
<li>인터페이스의 추상 메소드는 public abstract를 생략할 수 있다.    </li>
</ol>
</li>
</ul>
<hr>
<h4 id="-모양-인터페이스-">[ 모양 인터페이스 ]</h4>
<pre><code>public interface Shape {

  // final 상수
  public static final double PI = 3.14;

  // 추상 메소드
  // 추상 메소드는 중괄호대신 세미콜론(;)이 들어간다.
  double getArea();   // public abstract 가 생략된 모습

  // defalut 메소드
  // defalut 로 만들면 객체로 호출할 것 ( 객체.info1() )
  public default void info1() {
    System.out.println(&quot;나는 도형이다.&quot;);
  }

  // static 메소드
  // static 로 만들면 클래스로 호출할 것 ( Shape.info2() )
  public static void info2() {
    System.out.println(&quot;나는 도형이다.&quot;);
  }
}</code></pre><hr>
<h4 id="-클래스-상속-vs-인터페이스-구현-">[ 클래스 상속 vs 인터페이스 구현 ]</h4>
<ul>
<li><ol>
<li>클래스를 상속 받는다.</li>
</ol>
</li>
<li>public class Person { }</li>
<li>public class student extends Person { }</li>
<li></li>
<li><ol start="2">
<li>인터페이스를 구현한다.</li>
</ol>
</li>
<li>public interface Shape { }</li>
<li>public class Rectangle implements Shape { }</li>
<li></li>
<li>클래스와 인터페이스는 사실상 같은 것(상속받는 것),</li>
<li>말만 다르고(extends 와 implements) 같은 뜻.</li>
</ul>
<hr>
<h4 id="-사각형-클래스-">[ 사각형 클래스 ]</h4>
<pre><code>public class Rectangle implements Shape {

  private int width;
  private int height;

  public Rectangle(int width, int height) {
    this.width = width;
    this.height = height;
  }

  // 인터페이스를 구현한 클래스는 &quot;반드시&quot; 추상 메소드를 오버라이드 해야 한다.
  @Override
  // int 를 double로 바꾸는 건 자동(promotion)으로 바뀌니 에러안남.
  public double getArea() {
    return width * height;
  }</code></pre><h4 id="-원-클래스-">[ 원 클래스 ]</h4>
<pre><code>public class Circle implements Shape {

  private double radius;

  public Circle(double radius) {
    this.radius = radius;
  }

  @Override
  public double getArea() {
    return PI * radius * radius;
  }

}</code></pre><hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code>public class MainWrapper {

  public static void main(String[] args) {

    Shape s1 = new Rectangle(3, 4);
    System.out.println(s1.getArea());
    s1.info1();
    Shape.info2();

    Shape s2 = new Circle(1.5);
    System.out.println(s2.getArea());
    s2.info1();
    Shape.info2();

  }

}
</code></pre><hr>
<hr>
<h4 id="-추가-내용-">[ 추가 내용 ]</h4>
<ul>
<li>인터페이스를 만들고 클래스에 인터페이스를 구현한다.</li>
<li>인터페이스는 다중 인터페이스 구현이 가능하다(Phone, Computer 동시호출)
클래스 상속과 인터페이스 구현을 동시에 할 수 있다.
(상속 먼저 적고, 구현 나중 적기)</li>
</ul>
<pre><code>public class SmartPhone extends Camera implements Phone, Computer { }</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - abstract ( 추상 )]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-abstract-%EC%B6%94%EC%83%81-%ED%81%B4%EB%9E%98%EC%8A%A4</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-abstract-%EC%B6%94%EC%83%81-%ED%81%B4%EB%9E%98%EC%8A%A4</guid>
            <pubDate>Wed, 26 Jul 2023 01:40:45 GMT</pubDate>
            <description><![CDATA[<h3 id="-추상-클래스-">[ 추상 클래스 ]</h3>
<h4 id="추상--형태가-없는-것">[추상 : 형태가 없는 것]</h4>
<p> (강아지는 형태가 있으니 추상x, 동물은 추상)</p>
<ul>
<li><ol>
<li>추상 메소드를 1개 이상 가지고 있는 클래스이다.
  (추상 메소드가 하나라도 생기면, 클래스도 추상 클래스가 된다.)</li>
</ol>
</li>
<li><ol start="2">
<li>abstract 키워드를 추가한다.</li>
</ol>
</li>
<li><ol start="3">
<li>★ 추상 클래스는 객체를 생성할 수 없다. </li>
</ol>
</li>
<li>(미완성 된 클래스이기 때문이다. = 본문이 없는 메소드가 있기 때문에 미완성 클래스.)</li>
<li><ol start="4">
<li>★ 추상 클래스의 서브 클래스는 &quot;반드시&quot; 추상 메소드를 오버라이드 해야 한다.</li>
</ol>
</li>
<li>(추상 메소드만 오버라이드 하면 된다.)</li>
</ul>
<hr>
<h4 id="-사람-클래스-">[ 사람 클래스 ]</h4>
<pre><code>public abstract class Person {

  public void eat() {
    System.out.println(&quot;냠냠&quot;);
  }

  public void sleep() {
    System.out.println(&quot;쿨쿨&quot;);
  }

  // 호출을 위해서 생성한 study 메소드
  // 본문이 필요 없기 때문에 본문이 없는 메소드로 만들 수 있다.
  // 본문이 없는 메소드를 &quot;추상 메소드&quot;라고 한다.
  // abstract 키워드를 추가하고 본문({})을 제거한다.
  public abstract void study();

}</code></pre><h4 id="-학생-클래스-">[ 학생 클래스 ]</h4>
<pre><code>public class Student extends Person {

  public void study() {
    System.out.println(&quot;공부&quot;);
  }

}
</code></pre><hr>
<h4 id="-메인-메소드-">[ 메인 메소드 ]</h4>
<pre><code>public class MainWrapper {

  public static void main(String[] args) {

    // 추상 클래스 Person은 객체를 생성할 수 없다.
    // Person p1 = new Person();  --&gt; 불가능함.
    p1.eat();
    p1.sleep();

    Person p2 = new Student();
    p2.eat();
    p2.sleep();
    // study 메소드를 만들었지만, Person타입이기에 Person메소드만 호출 가능.
    // Person 에 빈 study 메소드를 만들어줘서 오버라이드 함.
  }

}</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - Object 클래스 , equals , toString]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Object-%ED%81%B4%EB%9E%98%EC%8A%A4</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-Object-%ED%81%B4%EB%9E%98%EC%8A%A4</guid>
            <pubDate>Tue, 25 Jul 2023 08:49:22 GMT</pubDate>
            <description><![CDATA[<h3 id="-object-클래스-">[ Object 클래스 ]</h3>
<ul>
<li>Java.lang.Object 클래스  (클래스 이름 앞에 붙는 이름은 패키지이다.) 
&#39; Java.lang &#39; = 패키지 이름, Object = 클래스</li>
<li><ol>
<li>모든 클래스의 최상위 슈퍼 클래스이다.</li>
</ol>
</li>
<li><ol start="2">
<li>별도의 슈퍼 클래스를 명시하지 않은 클래스들은(extends가 없는 클래스) 
모두 Object 클래스의 서브 클래스이다.</li>
</ol>
</li>
<li><ol start="3">
<li>모든 것을 저장할 수 있는 Java의 만능 타입이다.</li>
</ol>
</li>
<li><ol start="4">
<li>Object 타입으로 저장하면 Object 클래스의 메소드만 호출할 수 있다. 
이를 해결하기 위해서 &quot;반드시&quot; 다운캐스팅을 해야 한다. 
(object 클래스 코드를 건들지 못하기 때문에 Override는 불가능)</li>
</ol>
</li>
</ul>
<pre><code>/*
 *  ┌--------------┐
 *  │  Object      │ 슈퍼 클래스
 *  │--------------│
 *  │  equals()    │ 두 객체의 참조값을 비교해서 같으면 true, 아니면 false 반환
 *  │  getClass()  │ 어떤 클래스인지 반환
 *  │  hashCode()  │ int 타입의 해시코드값, Object 클래스는 객체의 참조값을 해시코드값으로 사용함
 *  │  toString()  │ &quot;클래스이름@참조값&quot; 형식의 문자열을 반환
 *  │  notify()    │ 스레드(thread) 관련 메소드
 *  │  wait()      │ 스레드(thread) 관련 메소드
 *  └--------------┘
 *          ▲
 *          │
 *          │
 *  ┌--------------┐
 *  │  Person      │ 서브 클래스
 *  │--------------│
 *  │  @Override   │
 *  │  equals()    │ 이름과 나이가 같으면 true, 아니면 false 반환 (하드코딩하지 않고, 자동완성한다.)
 *  │              │
 *  │  @Override   │
 *  │  toString()  │ 이름과 나이를 확인할 수 있는 문자열 반환 (하드코딩하지 않고, 자동완성한다.)
 *  └--------------┘
 */</code></pre><hr>
<h4 id="-사람-클래스-">[ 사람 클래스 ]</h4>
<ul>
<li><p>equals() : 모든 객체 비교는 equals()를 사용.
이클립스 메뉴 - Source - Generate hashcode() and equals()... 클릭
=&gt; 자동으로 비교하는 equals 를 만들어줌.</p>
</li>
<li><p>toString() : 객체 출력, 참조값에 들어있는 값 확인하고 싶을 때. 
이클립스 메뉴 - Source - Generate toString()... 클릭
=&gt; 실제 들어있는 값을 출력.</p>
</li>
</ul>
<pre><code>public class Person {

  // Field
  private String name;
  private int age;

  // Constructor
    // new Person()
    public Person() {

    }
  // new Person(&quot;홍길동&quot;, 20)
    public Person(String name, int age) {
      this.name = name;
      this.age = age;
    }


  // Method
   @Override
    public int hashCode() {
      return Objects.hash(age, name);
    }
    @Override
    public boolean equals(Object obj) {
      if (this == obj)  // p1.equals(p1)
        return true;
      if (obj == null)  // p1.equals(null)
        return false;
      if (getClass() != obj.getClass()) // p1.equals(s1)
        return false;
      Person other = (Person) obj;
      return age == other.age &amp;&amp; Objects.equals(name, other.name);
    }

    //참조값에 들어있는 값 확인하고 싶을 때. 
      @Override
    public String toString() {
      return &quot;Person [name=&quot; + name + &quot;, age=&quot; + age + &quot;]&quot;;
    }



  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public int getAge() {
    return age;
  }
  public void setAge(int age) {
    this.age = age;
  }</code></pre><hr>
<h4 id="-ex01-메서드-">[ ex01 메서드 ]</h4>
<pre><code>
  public static void ex01() {

    // Object 타입으로 모든 객체를 저장할 수 있다.
    // Object 타입으로 저장한 객체를 사용할 때는 캐스팅 해야 한다.

  }

  public static void ex02() {

    // 동일한 객체 2개
    Person p1 = new Person(&quot;홍길동&quot;, 20);
    Person p2 = new Person(&quot;홍길동&quot;, 20);

    // 동일한 객체인지 판단
    boolean same = p1.equals(p2);
    // p1 과 p2 는 주소가 다른, 서로 다른 객체이다.
    // equals(); 는 주소 번지 수가 다르니, 다른 객체라고 출력된다.
    // equals 를 오버라이드 해서 주소값말고 주소 안에 있는 실제 값을 비교할 수 있도록 해주면 된다.  

    // 결과 확인
    System.out.println(same ? &quot;동일한 객체&quot; : &quot;다른 객체&quot;);

  }</code></pre><hr>
<h4 id="-ex01-메서드--1">[ ex01 메서드 ]</h4>
<pre><code>public static void main(String[] args) {

Object obj = new Person();
    ((Person) obj).setName(&quot;홍길동&quot;);
    ((Person) obj).setAge(20);
    System.out.println(((Person) obj).getName());
    System.out.println(((Person) obj).getAge());
  }
  // 위와 같이 다운캐스팅으로 바꿔 사용 가능.
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - 다운캐스팅 ( downCasting )]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EB%8B%A4%EC%9A%B4%EC%BA%90%EC%8A%A4%ED%8C%85-downCasting</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EB%8B%A4%EC%9A%B4%EC%BA%90%EC%8A%A4%ED%8C%85-downCasting</guid>
            <pubDate>Tue, 25 Jul 2023 08:46:27 GMT</pubDate>
            <description><![CDATA[<h3 id="-다운-캐스팅--downcasting-">[ 다운 캐스팅 : downCasting ]</h3>
<ul>
<li>슈퍼 클래스 타입을 서브 클래스 타입으로 변경(다운캐스팅)
=&gt; 업캐스팅과 반대. ( Object 클래스를 사용할 때 다운캐스팅을 많이 사용함 )</li>
</ul>
<hr>
<h4 id="-메인-메서드-">[ 메인 메서드 ]</h4>
<pre><code>public class MainWrapper {

  public static void ex01() {
    Person p = new Student();
    p.eat();
    p.sleep();
    ((Student)p).study();  // 슈퍼 클래스 타입 -&gt; 서브 클래스 타입으로 변경(다운캐스팅)
    ((Worker)p).work();    // 잘못된 캐스팅을 막고 싶다!    
  }

  public static void ex02() {

    Person p = new Student();
    System.out.println(p instanceof Person);  // p가 Person  타입이면 true, 아니면 false
    System.out.println(p instanceof Student); // p가 Student 타입이면 true, 아니면 false
    System.out.println(p instanceof Worker);  // p가 Worker  타입이면 true, 아니면 false

  }

  public static void ex03() {

    Person p1 = new Student();
    if(p1 instanceof Student) {
      ((Student) p1).study();     // p1. 찍고 study()를 고르면 이클립스에서 자동으로 다운캐스팅 해준다.
    }

    Person p2 = new Worker();
    if(p2 instanceof Worker) {
      ((Worker) p2).work();
    }

  }

  public static void main(String[] args) {
    ex02();
  }
}</code></pre><hr>
<h4 id="-사람-클래스-">[ 사람 클래스 ]</h4>
<pre><code>public class Person {

  public void eat() {
    System.out.println(&quot;냠냠&quot;);
  }

  public void sleep() {
    System.out.println(&quot;쿨쿨&quot;);
  }
}</code></pre><hr>
<h4 id="-학생-클래스-">[ 학생 클래스 ]</h4>
<pre><code>public class Student extends Person {

  public void study() {
    System.out.println(&quot;공부&quot;);
  }
}

</code></pre><hr>
<h4 id="-직장인-클래스-">[ 직장인 클래스 ]</h4>
<pre><code>public class Worker extends Person {

  public void work() {
    System.out.println(&quot;일함&quot;);
  }

}
</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[자바 - 업캐스팅( upCasting )]]></title>
            <link>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%85%EC%BA%90%EC%8A%A4%ED%8C%85-upCasting</link>
            <guid>https://velog.io/@jworld_714/%EC%9E%90%EB%B0%94-%EC%97%85%EC%BA%90%EC%8A%A4%ED%8C%85-upCasting</guid>
            <pubDate>Tue, 25 Jul 2023 08:40:32 GMT</pubDate>
            <description><![CDATA[<h3 id="-upcasting-">[ upcasting ]</h3>
<ul>
<li><ol>
<li>서브 클래스 객체를 슈퍼 클래스 타입으로 저장할 수 있다.</li>
</ol>
</li>
<li><ol start="2">
<li>강제로 캐스팅(형변환)할 필요가 없다. 자동으로 변환된다.</li>
</ol>
</li>
<li><ol start="3">
<li>장점</li>
</ol>
<ul>
<li>1) 슈퍼 클래스 타입으로 모든 서브 클래스 객체를 저장할 수 있다.</li>
<li>2) 서로 다른 타입의 객체를 하나의 타입으로 관리할 수 있다.</li>
</ul>
</li>
<li><ol start="4">
<li>단점</li>
</ol>
<ul>
<li>1) 슈퍼 클래스 타입으로 저장하기 때문에 슈퍼 클래스의 메소드만 호출할 수 있다.
(서브 클래스가 가지고 있는 메소드는 호출이 안 된다는 뜻).</li>
<li>2) 이 단점을 해결하기 위해서 메소드 오버라이드(Method Override)를 이용할 수 있다.</li>
</ul>
</li>
</ul>
<hr>
<h4 id="-메인-메서드-">[ 메인 메서드 ]</h4>
<pre><code> public static void main(String[] args) {

Student s1 = new Student();
    s1.setName(&quot;홍길동&quot;);
    s1.setSchool(&quot;가산대학교&quot;);
    s1.eat();
    s1.sleep();
    s1.study();

System.out.println(s1.getName());
    System.out.println(s1.getSchool());
    s1.info();

// set을 쓰지 않고 생성자 객체에 바로 저장.
    Student s2 = new Student(&quot;홍길동&quot;, &quot;가산대학교&quot;);
    s2.eat();
    s2.sleep();
    s2.study();
    System.out.println(s2.getName());
    System.out.println(s2.getSchool());

// upcasting (자식 객체를 부모 타입으로 저장시키는 것)
    Person p1 = new Student(&quot;고길동&quot;, &quot;강원대학교&quot;);
    Person p2 = new Alba(&quot;홍길동&quot;, &quot;가산대학교&quot;, &quot;투썸&quot;);
    //자식들을 모두 부모인 Person타입으로 관리 가능하다.(여러 객체를 관리하기 편해지는 장점.)

    p1.eat();
    p1.sleep();
    p1.study();
 // eat 과 sleep 은 슈퍼 클래스에 있는 메소드여서 호출가능.
 // study 는 슈퍼 클래스 메소드가 아니기 때문에 호출 불가능.
 // 호출은 Person에서 하지만 실제 실행은 Student에서 실행됨.

    p2.eat();
    p2.sleep();
    p2.study();
    p2.working();
 // working 도 Person에 빈메소드로 만들어줌(오버라이드)
 // 호출은 Person에서 하지만 실제 실행은 Alba에서 실행됨.
  }</code></pre><hr>
<h4 id="-알바-클래스-">[ 알바 클래스 ]</h4>
<pre><code>public class Alba extends Student {

  // Field
  private String work;

  // Constructor
    // new Alba()
    public Alba() {
      // super(); &lt;-- 없어도 그만, 있어도 그만. Java가 자동 호출.
    }

// new Alba(&quot;홍길동&quot;, &quot;가산대학교&quot;, &quot;투썸)
    public Alba(String name, String school, String work) {
      super(name, school);  // Alba 입장에서 슈퍼는 Person이 아닌 Student 이다.
    this.work = work;
    }

  // Getter &amp; Setter
    //생성자에서 파라미터 쓰는데 Getter, Setter 쓰는 이유는
    //메소드들을 호출 하기 위함이다.
    public String getWork() {
      return work;
    }

    public void setWork(String work) {
      this.work = work;
    }

  // Method
    @Override
    public void working() {
      System.out.println(&quot;일함&quot;);
    }

    @Override
    public void info() {
      System.out.println(&quot;이름: &quot; + getName());
      System.out.println(&quot;학교: &quot; + getSchool());
      System.out.println(&quot;직장: &quot; + work);
      // 이름과 학교는 슈퍼클래스에서 가져오니 get으로 가져와줌.
      // 직장은 자기가 필드값으로 가지고 있으니 바로 적어줌.
      // @Overrid 자동완성 : @Ov + Ctrl + Space
    }</code></pre><hr>
<h4 id="-학생-클래스-">[ 학생 클래스 ]</h4>
<pre><code>// Student     is a    Person  (is a 상속관계)
// 서브 클래스 is a 슈퍼 클래스(부모)
// super.eat() 같이 메소드들은 다 super로 호출할 수 있다.

public class Student extends Person {

  // Field
  private String school;

  // Constructor
    //new Student()
    public Student() {
      // 반드시 슈퍼 클래스의 생성자 호출이 있어야 하기 때문에,
      // 개발자가 슈퍼 클래스의 생성자를 호출하지 않으면 Java가 직접 슈퍼 클래스의 생성자를 호출한다.
      // Java가 호출하는 슈퍼 클래스의 생성자는 &quot;디폴트 생성자&quot;만 가능하다.
      super(); // 개발자가 작성하지 않아도 자동으로 호출되는 슈퍼 클래스의 디폴트 생성자.
  }

    // new Student(&quot;홍길동&quot;, &quot;가산대학교&quot;)
    public Student(String name, String school) {
    // new Student(&quot;홍길동&quot;) 호출을 위한 코드
    super(name);  // &lt;- person의 해당 생성자 호출이 됨.
    this.school = school;
  }

    // Method
    public String getSchool() {
      return school;
    }

    public void setSchool(String school) {
      this.school = school;
    }

    @Override
    public void study() {
      System.out.println(&quot;공부&quot;);
    }

    // 오버라이드 : 부모가 가진 메소드를 자식이 한 번 더 만들어서 덮어쓰기 하는 것
    @Override
    public void info() {
      System.out.println(&quot;이름: &quot; + getName());
      System.out.println(&quot;학교: &quot; + school);
      // 슈퍼클래스에서 가져오니 getName() 적는거고,
      // Student 자신이 가지고 있으니 school 필드값만 바로 적어도 된다.
    }</code></pre><hr>
<h4 id="-사람-클래스-">[ 사람 클래스 ]</h4>
<pre><code>public class Person {

  // Field
  private String name;

  // Constructor
    // new Person()
  public Person() {

  }

    // new Person(&quot;홍길동&quot;)
  public Person(String name) {
    this.name = name;
  }


  // Method
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public void eat() {
    System.out.println(&quot;쿰척쿰척&quot;);
  }

  public void sleep() {
    System.out.println(&quot;드르렁&quot;);
  }

  public void info() {
    System.out.println(&quot;이름: &quot; + name);
  }

  // 실행이 목적이 아닌 호출이 목적인 메소드(오버라이드용)
  public void study() {
  }

  //실행이 목적이 아닌 호출이 목적인 메소드(오버라이드용)
  public void working() {
  }</code></pre>]]></description>
        </item>
    </channel>
</rss>