본문 바로가기

분류 전체보기

(260)
생활코딩 자바 - 클래스, 인스턴스, 객체 객체지향 이전의 코딩 클래스, 인스턴스 = 설계도, 제품 System.out.println(10 + 20); System.out.println(20 + 40); => 중복 제거 필요 -> (refactoring: 편리, 효율화) public static void sum(int left, int right) { System.out.println(left + right); } public static void main(String[] args) { sum(10, 20); sum(20, 40); } public static void avg(int left, int right) { System.out.println((left + right)/2); } public static void sum(int left, ..
생활코딩 자바 - 객체지향 프로그래밍 객체지향 프로그래밍(object oriented programming) 객체 상태(state)와 행위(behave)로 이루어짐 변수와 메소드로 이루어짐 Ex. 본문창, 댓글창 처럼 서로 연관된 변수, 메소드들을 묶는 틀 추상화 Ex. 실제 지도 -> 지하철 노선도 복잡한 현실을 단순화, 정리 부품화 연관된 로직 결합해 완제품 메소드 생성 -> 메소드들을 부품으로 하는 하나의 완제품 프로그램 생성 은닉화, 캡슐화 내부 동작 방법을 케이스(객체) 안에 숨기고, 사용자에게는 그 부품 사용방법만(메소드) 노출 Ex. 객체를 몰라도 보여지는 메소드 사용법만 알아도 객체 이용하도록 함 인터페이스 부품 서로 교환 가능할 때 연결점 접점 부품들 간 약속
생활코딩 자바 - 입력과 출력(Input &Output, IO) 입력 (앱 실행 전) public static void main(String[] args) { System.out.println(args.length); => args라는 배열이 담을 수 있는 값의 수 => 입력값의 수 } } void : 출력값 없음 main : 메소드 (String~) : 입력값 받는 매개변수(parameter) 명령 프롬프트 이용 cd C:\~ : 해당 경로로 이동 cd .. : 상위 경로로 이동 dir : 디렉토리 java -cp : 실행 ex. >java -cp bin org.opentutorials.javatutorials.io.InputDemo => 0 >java -cp bin org.opentutorials.javatutorials.io.InputDemo one two th..
생활코딩 자바 - 메소드 메소드, 객체지향.. => 웅장, 결함 없고, 유지보수 쉬운 애플리케이션 만들기 위한 기법 public static void main(String[] args) { => method 메소드의 정의, 호출 public static void numbering() { int i = 0; while (i 정의 public static void main(String[] args) { numbering(); numbering(); numbering(); numbering(); numbering(); => 호출 main 메소드 =규칙, 약속 (이해의 영역이 아님) 재활용 -> 코드 양 줄일 수 있음 -> 유지보수 쉬워짐 입력값 매개변수, 인자 public static void numbering(int limit) {..
생활코딩 자바 - 배열 배열 (array) 연관된 정보 그룹핑 cf) 변수: 반장 / 상수: a, b, c 등 개별적 학생 이름 => 변수에 상수를 대입 반 배열 정의함 -> 배열 정의한 것을 classGroup에 담음 => classGroup은 문자열 타입을 가진 데이터들의 모임 제어 한 줄로 정의 String[] classGroup = {"a", "b", "c", "d"}; => 원소(element) System.out.println(classGroup[0]); System.out.println(classGroup[1]); System.out.println(classGroup[2]); System.out.println(classGroup[3]); => 색인(index) 분할하여 정의 String[] classGroup = ..
생활코딩 자바 - 반복문 while package org.opentutorials.javatutorials.loo; public class WhileDemo { public static void main(String[] args) { while (true) { System.out.println("hello"); } }} package org.opentutorials.javatutorials.loo; public class WhileDemo2 { public static void main(String[] args) { int i = 0; while (i hello0 hello1 hello2 hello3 hello4 hello5 hello6 hello7 hello8 hello9 for for (초기화; 종료조건; 반복실행) { 반복..
생활코딩 자바 - 논리연산자 && (AND) 좌항, 우항 모두 참일 때 참 package org.opentutorials.javatutorials.condition; public class LoginDemo3 { public static void main(String[] args) { String id = args[0]; //입력값 String password = args[1]; if(id.equals("egoing") && password.equals("1111111")) { System.out.println("right"); } else { System.out.println("wrong"); } } } || (OR) 좌항, 우항 중 하나가 참일 때 참 package org.opentutorials.javatutorials.con..
생활코딩 자바 - 조건문 조건문 + 불린 => 비교 if if(true/false){ //if절 } //then절 package org.opentutorials.javatutorials.condition; public class ConditionDemo2 { public static void main(String[] args) { if(false) { System.out.println(1); System.out.println(2); System.out.println(3); System.out.println(4); } System.out.println(5); } } //5 else 절 if(true/false){ } else { } package org.opentutorials.javatutorials.condition; publ..
생활코딩 자바 - 비교와 Boolean Boolean 불린(bool) : 참과 거짓 의마하는 데이터타입 true, false 비교 연산자 == : 같다 System.out.println(1 == 2); //false System.out.println(1 == 1); //true System.out.println("one" == "two"); System.out.println("one" == "one"); // = : 대입연산자 // == : 비교연산자 != : 같지 않다 System.out.println(1 != 2); //true System.out.println(1 != 1); //false System.out.println("one" != "two"); System.out.println("one" != "one"); , = .equals..
생활코딩 자바 - 연산자 연산자 특정 작업 하기 위한 기호 ex. 대입, 산술(+, -, *, /, %(나머지)), 비교, 논리 연산자 등 형변환 package org.opentutorials.javatutorials.operator; public class DivisonDemo { public static void main(String[] args) { int a = 10; int b= 3; float c = 10.0F; float d = 3.0F; System.out.println(a/b); // 정수/정수= 3.333 => 소수점 없앰 -> 3 System.out.println(c/d); // 3.3333.. System.out.println(a/d); // 10/3.0F -> 10.0F/3.0F로 자동 형변환 -> 3.3..