일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- computer
- DATAPATH
- DB
- Pipelining
- javascript
- react
- for
- mysql
- MacOS
- control
- architecture
- php
- Algorithm
- while
- github
- CSS
- instruction
- python
- function
- Class
- system
- XML
- DS
- DoM
- MIPS
- data structure
- web
- html
- Java
- Linux
- Today
- Total
목록Java (58)
YYYEJI
Array란? 여러개의 같은 data type의 값(value)들을 모아놓은 리스트이고, array는 기본 타입(primitive type)은 아니지만 객체(object)도 아닙니다. Array 생성 Base_Type[] Array_Name = new Base_Type[Length]; char[] c = new char[80]; double[] d = new double[100]; String[] s = new String[120]; Array 접근은 Index로 가능합니다. c[0] = 'A'; System.out.println(c[0]); Array의 범위(range)는 length-1입니다. Array 접근은 주로 for문을 사용합니다. public static void main(String[] a..
Package란? 비슷한 성격을 가진 class를 모아놓은 디렉토리(directory)입니다. 클래스를 체계적으로 관리하기 위해서 사용합니다. 원하는 class를 사용하고 싶을 때는 .(dot)을 사용해서 상위 패키지부터 작성해서 Import를 하게 됩니다. import high_package.low_package.class_name 위와 같은 방법으로 import 해주면 됩니다. 어떤 package의 전체 class를 Improt 하고 싶을 때 혹은 정확한 class의 이름을 모를 때에는 "*"를 사용합니다. import high_package.low_package.* 이런 식으로 package를 생성하고 class를 관리해주면 class가 많아졌을 때 class를 체계적으로 관리할 수 있습니다. ◡̈
오버로딩(Overloading)이란? 동일 클래스(class)에서 동일한 이름의 메소드(method)를 여러 개 정의할 수 있음을 의미합니다. 물론 조건이 존재합니다. 매개변수(parameter)의 개수나 타입이 달라야 합니다. (Different signature) 예제를 살펴봅시다. public class main { public static void main(String[] args) { int n1 = 2; int n2 = 100; double f1 = 2.0; double f2 = 100.0; String s1 = "Hello "; String s2 = "World!"; int result_1 = adder(n1, n2); double result_2 = adder(f1, f2); String ..
Wrapper class란? Primitive type을 class type으로 포장해 주는 클래스를 말합니다. Primitive type Class type Method to convert back int Integer intValue() long Long longValue() float Float floatValue() double Double doubleValue() char Charactcer charValue() Integer class로 예제를 살펴보겠습니다. public static void main(String[] args) { Integer n = new Integer(10); System.out.println(n.intValue()); } Primitive type의 변수에 값을 할당할..
Action을 수행하기 위해 객체가 필요없는 method들도 존재합니다. 객체없이 method를 호출(invoke)할 수 있었던 이유는 static 연산자를 사용했기 때문입니다. Static Method / Class method method를 호출(invoke)하기 위해 객체의 이름이 아닌 method의 이름을 사용하면 됩니다. public class main { public static void main(String[] args) { greeting(); } public static void greeting() { System.out.println("Hello world!"); } } 위에 예제처럼 객체를 생성하지 않아도 메소드(method)를 사용할 수 있습니다. 다음은 static 연산자가 붙은 ..
Constructor란? Instance variable을 초기화 시켜주는 특별한 method입니다. Constructor의 특징 - Class와 같은 이름을 가지고 있음 - new 연산자를 통해 객체를 생성할 때 자동으로 가장 먼저 실행됨 - Parameter의 내용을 다르게 해서 1개보다 더 많이 선언될 수 있음(Different signature, overload) Constructor의 역할 instance variable의 값을 초기화 시키는 역할을 합니다. Constructor 생성 Constructor은 void, return type이 없고, Parameter의 값이 없는 constructor은 default constructor입니다. public class p { private Stri..
코드를 살펴보면서 시작하도록 하겠습니다. 아래 코드의 결과가 왜 똑같이 나오는지 하나하나 살펴봅시다! public static void main(String[] args) { p person_info_1 = new p(); p person_info_2 = new p(); person_info_1.set("Jenie", 26); person_info_2.set("Jiso", 27); person_info_2 = person_info_1; person_info_2.set("Rosie", 25); System.out.println(" "); person_info_2.writeOutput(); System.out.println("\n"); person..
Setter 란? Setter은 accessor method라고 불리며, instance variable을 읽어주는 public method입니다. getter 란? Getter은 mutator method라고 불리며, instance variable을 수정해주는 public method입니다. Setter/Getter는 왜 사용할까요? 객체의 변수(instance variable)를 객체 외부에서 직접적으로 접근하는 것을 막기 위해서 사용합니다. 객체의 외부에서는 method를 통해 변수에 접근하고 수정하도록 유도하고 있습니다. 예제를 살펴보기 위해 P class를 만들어줬습니다. public class p { private int width; private int height; public p() {..