김미썸코딩

11/13 - Java (5) : eclipse, java.lang( Object , String ) 본문

빅데이터 플랫폼 구축을 위한 자바 개발자 양성과정

11/13 - Java (5) : eclipse, java.lang( Object , String )

김미썸 2020. 11. 16. 19:04
728x90

복습 & 개념정리

 

패키지

       사용자 정의 클래스

              캡슐화

              상속

                          추상

                          다형

 

내장 패키지  -  API

       내장 클래스

내장 패키지 목록

그안의 클래스는 우리가 아는 클래스와는 별종이다.

 

 

 

 

 


 

 

 

 

 

 

 

이클립스 다운로드


 

www.eclipse.org/

 

The Community for Open Innovation and Collaboration | The Eclipse Foundation

The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 375 open source projects, including runtimes, tools and frameworks.

www.eclipse.org

설치가 아니고 다운받으면 되는거다.

 

 

 

1. 환경설정 

1-1. 워크스페이스 잡기

 

워크스페이스 만들어진거 확인가능

 

1-2. java ee -> java 화면으로 바꾸기

 

 

 

 

 

 

1-3. 기타 설정변경
window > preferences  > General  > Workspace 

 

General  > Appearance > Colors and Fonts 

basic > Text Font 눌러서 Edit




General  > Editors  > TextEditors > spelling 

 

General  > Workspace  (필수)

other체크해서 utf-8로 설정

 

 

 

 


2. 만드는 과정 


2-1. 프로젝트 생성

확인하기 : workspace에 javaEx01 파일 생성  

 

2-2. 패키지 생성




2-3. 패키지 있는 클래스 생성 



2-4. 패키지 없는 클래스 생성

src에서 오른쪽 클릭 java 에서 class 에서 패키지명 없애고 name은 javaEx01, public static void찾아서 체크 하면 패키지 없는 거 만들수 있음(패키지 선언이 없으면 디폴트 패키지)

패키지명 비워두기

 

 

 

 

2-5. 프로젝트 실행

  • ctrl + space 누르면 자동 완성으로 나온다.
  • 프로젝트폴더 안에 bin안에는 실행 클래스가 들어가는데 안보인다. src안에는 소스가 들어간다.
  • sys치고 ctrl+space하면 sysout있고 enter하면 자동완성한다.
  • 오른쪽 클릭 run as   -> java 하면실행

 

 

2-6. 프롬프트에서 실행

탐색기> Java > workspace > bin 에서 shift+오른쪽 클릭 >  powershell열기

 

  • 패키지 없는 클래스 :  java  클래스명
  • 패키지 있는 클래스 :  java  com.클래스명

이클립스는 문법검사와 자동 컴파일 다해준다. 

이클립스에서 오타치면 빨간줄 나온다. 빨간줄이면 무조건 오타다. 실행하려고 해도 할수 없게 버튼이 안눌림.

 

 

 

 

 

 

 

 

 

 

 

< 자바  API 도큐먼트 >

교재 11장.

▷p454

Java.lang,    java.util는 import없이 사용할 수 있다.

object는 override를 전제로 하여 만들어졌다.

 

 

 

 

java.lang


1. object 클래스

▷p457

  • 클래스를 선언할 때 extends키워드로 다른 클래스를 상속하지 않으면 암시적으로 java.lang.Object 클래스를 상속하게 된다.
  • 따라서 자바의 모든 클래스는 Object 클래스의 자식이거나 자손 클래스이다. 
  • Object는 자바의 최상위 부모 클래스에 해당한다.

 

 

생성하는 방법은 딱 한가지 밖에 없다.

 

1-1. 객체 비교

▷p458

1) 주소 비교 - 비교연산자

2) 내용 비교 

equales() : Object의 메소드로서 객체를 비교하는 메소드이다. 매개 타입은 Object이므로, 모든 객체가 매개값으로 대입될 수 있음을 말한다. 비교 연산자인 ==과 동일한 결과를 리턴한다.

 

 

 

1-2. 객체 문자 정보(toString())

오버라이드를 전제로 하고 만든다. 내용이 없으면 주소값을 리턴한다.

▷p464

 

 

 

 

toString()으로 객체 주소값을 불러오지 못할 때 hashCode()를 사용

 

hashCode()는 String에 정의된게 아니고 Object에 정의된 것이다. 

객체의 주소값을 toString()으로 불러오지 못할때 사용하는 것이다.

 

 

 

 

2. String 클래스

▷p496

자바스크립트의 String에서 좀더 확장된 형태 (참조형태)

배열을 이용해서 만들수 있다.

public class StringEx02{
    public static void main(String[] args){
        String str1 = "Hello World";

        System.out.println(str1.length());
        System.out.println("Hello World".length());

        // 문자열(String) -> 문자(char) : charAt()
        // 문자열 => 문자열

        // String pstr1 = str1.substring(2);
        String pstr1 = str1.substring(2,4); // 2,3 가져옴
        System.out.println(pstr1);

        // 검색
        // 위치검색
        // lastIndeOf / lastIndeOf
        int pos = str1.indexOf("ll");
        System.out.println(pos);

        // 존재검색
        // startsWith / endsWith / contains
        boolean b1 = str1.startsWith("He"); // true
        //boolean b1 = str1.startsWith("He"); // false
        System.out.println(b1);

        // 치환
        String rstr1 = str1.replaceAll("World", "세상");
        System.out.println(rstr1);

        // 문자열 +, concat
        String jstr1 = str1.concat("안녕");
        System.out.println(jstr1);

        // 대소문자 변환 
        System.out.println("hello".toUpperCase());
        System.out.println("HELLO".toLowerCase());

        // 공백제거
        // 양쪽 끝의 공백을 제거한다. 문자열 중간의 공백은 문자열의 일부분이다.
        String ostr1 = "                hello          ";
        System.out.println(ostr1 + "::"); // 문자열의 끝을 보기위함
        System.out.println(ostr1.trim() +"::");

        // 문자열 분리
        // split
        String sstr1 = "사과,딸기,수박,참외";
        String[] strarr = sstr1.split(",");
        for(String str : strarr){
            System.out.println(str);
        }

        // 분리된 문자열(=배열) 결함
        String fstr1 = String.join(",", strarr);    // static 메서드다
        System.out.println(fstr1);
    
        // 형식화된 문자열 결합
        String fstr2 = String.format("%s:%s:%s", strarr[0], strarr[1], strarr[2]);
        System.out.println(fstr2);
    
    
    }
}

 

728x90
Comments