본문 바로가기
반응형

자바(Java)64

[Java Class.10] this 키워드 [Java Class.10] this 키워드 1. this 키워드 this 키워드는 클래스 안에서 자기 자신의 object를 가리킬 때 사용합니다. [예제1] 아래 코드를 보며 this의 사용에 대해 이해해 보자. HTML 삽입 미리보기할 수 없는 소스 위 코드에서 this.name, this.email, this.phoneNumber라고 코딩한 부분은 사실 name, email, phoneNumber라고 그냥 코딩해도 되지만, "this.variable"형태로 굳이 코딩한 이유는 현재 object의 instance variable을 가리킨다는 것을 확실하게 구분하기 위해서 입니다. static method 안에서는 this, instance variable을 사용할 수 없습니다. 그 이유는 static.. 2024. 3. 26.
[자바기초.027] 변수 사용 범위(Scope & Access) [자바기초.027] 변수 사용 범위(Scope & Access) 1. 변수의 사용 범위 자바에서 변수를 만들 때, 변수의 사용 범위는 { } 로 정해진다. 자바에는 3가지 변수 범위(level of scope)가 있다. Class Level Scope for instance variables inside a class. Method Level Scope for local variables (including parameter variables) inside a method. Block Level Scope for loop variables and other local variables defined inside of blocks of code with { }. 지역 변수(Local variables)는 .. 2024. 3. 26.
[Java Class.09]Getters & Setters [Java Class.09]Getters & Setters 1. Getters / Accessors 클래스 안에 있는 instance variable(field)은 보통 private으로 선언하기 때문에, 이 intance variable에 접근하게 해주는 메소드(accessor or getter 메소드)를 public으로 만들어 주면 된다. getter 메소드의 return type은 instance variable의 type과 똑같다. [예제1-1] HTML 삽입 미리보기할 수 없는 소스 [예제1-2] HTML 삽입 미리보기할 수 없는 소스 [유제1] Try the following code. Note that it has a bug! It tries to access the private insta.. 2024. 3. 26.
AP Computer Science A Java Quick Reference AP Computer Science A Java Quick Reference (1) String Class APCSA 시험에서 자주 등장하는 Java method의 이론과 사용 방법에 대한 내용입니다. (1) String Class 자바에는 기본적으로 String 클래스가 존재합니다. String은 문자열을 의미하고, 문자열이란 문자(character)가 서로 연결된 형태("Hello")를 말합니다. String 클래스로 만든 object들은 String 클래스의 field와 method(위 표 참고)를 모두 사용할 수 있습니다. [예제1-1] 아래 코드의 실행 결과를 확인해 보세요. HTML 삽입 미리보기할 수 없는 소스 위 코드에서, greeting1, greeting2와 같이 "string lite.. 2024. 3. 25.
[자바AP연습문제]06.Arrays [자바AP연습문제]06.Arrays *06.Arrays에 대한 복습은 아래 "더보기" 클릭 더보기 An array is consecutive storage for multiple items of the same type like the top five scores in a game. You learned how to declare arrays, create them, and access array elements. Array elements are accessed using an index. The first element in an array is at index 0. Array - An array can hold many items (elements) of the same type. You can a.. 2024. 3. 24.
[자바AP연습문제]05.Writing Classes [자바AP연습문제]05.Writing Classes 문제 정답은 제일 아래 "더보기" 클릭 *05.Writing Classes 단원의 복습 내용은 아래 "더보기" 클릭 더보기 Class - A class defines a type and is used to define what all objects of that class know and can do. Compiler - Software that translates the Java source code (ends in .java) into the Java class file (ends in .class). Compile time error - An error that is found during the compilation. These are also .. 2024. 3. 24.
[자바AP.04] 반복문(Iteration) [자바AP.04] 반복문(Iteration) [문제 정답은 제일 아래 "더보기" 클릭으로 확인 가능] *04.Iteration(Loops)에 대한 복습 내용은 아래 "더보기" 클릭 더보기 In this chapter you learned about loops. Loops are used to repeat a statement or block of statements inside a pair of curly braces. Body of a Loop - The single statement or a block of statements that can be repeated (a loop may not execute at all if the condition is false to start with). In J.. 2024. 3. 24.
[자바기초.026] 문자열 비교하기(Comparing String) [자바기초.026] 문자열 비교하기(Comparing String) 1. 문자열이 같은지 비교 (String Equality) equals() 메소드는 두 개의 객체(object)가 같은지 비교하는 명령어 이다. 문자열(String)은 객체이기 때문에, 자바에서는 두 개의 문자열이 서로 같은지 비교할 때 equals() 메소드를 사용한다. 특히, 문자열을 equals()메소드로 비교하게 되면 문자열의 음절 하나씩 같은지 비교하고 또한 음절의 순서도 비교한다. 그래서 자바에서는 문자열이 서로 같은지 정확하게 비교하려면 equals()메소드를 사용하는 것이 맞다. 두 개의 객체를 비교하는 데에 연산자 == 을 사용하게 되면, ==은 두 개의 객체 변수가 같은 객체를 가리키고(refer)있는지 여부를 알려준다.. 2024. 3. 24.
[자바기초.025] Simplifying Boolean Using De Morgan's Law [자바기초.025] Simplifying Boolean Using De Morgan's Law 1. 논리 부정 연산자(negation) ! 논리 부정 연산자(negation)는 " ! " 로 사용하며, !(true) = false, !(false) = true와 같이 참과 거짓을 반대로 만든다. 그리고 이런 문장이 있다고 가정하자. "나는 고등학교에 있는 선생님이다." 이 문장에 !(negation) 논리 뷰정 연산자를 사용한다면, "나는 고등학교에 있는 선생님이 아니다" 라고 표현할 수 있다. 그런데, "나는 고등학교에 있는 선생님이 아니다"라는 말은 좀 모호한게, "나는 고등학교가 아니고 다른 중학교나 초등학교를 말하는 건지?", 또는 "나는 고등학교에 있는건 맞는데, 선생님이 아니라는 건지?" 두 .. 2024. 3. 23.
728x90
반응형