diff --git a/firstSeminar/.gitignore b/firstSeminar/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/firstSeminar/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/firstSeminar/build.gradle b/firstSeminar/build.gradle new file mode 100644 index 0000000..cf38b23 --- /dev/null +++ b/firstSeminar/build.gradle @@ -0,0 +1,22 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '2.7.10' + id 'io.spring.dependency-management' version '1.0.15.RELEASE' +} + +group = 'sopt.org' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '11' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/firstSeminar/gradle/wrapper/gradle-wrapper.jar b/firstSeminar/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/firstSeminar/gradle/wrapper/gradle-wrapper.jar differ diff --git a/firstSeminar/gradlew b/firstSeminar/gradlew new file mode 100755 index 0000000..a69d9cb --- /dev/null +++ b/firstSeminar/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/firstSeminar/gradlew.bat b/firstSeminar/gradlew.bat new file mode 100644 index 0000000..f127cfd --- /dev/null +++ b/firstSeminar/gradlew.bat @@ -0,0 +1,91 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/firstSeminar/settings.gradle b/firstSeminar/settings.gradle new file mode 100644 index 0000000..3519758 --- /dev/null +++ b/firstSeminar/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'firstSeminar' diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/FirstSeminarApplication.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/FirstSeminarApplication.java new file mode 100644 index 0000000..1513216 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/FirstSeminarApplication.java @@ -0,0 +1,14 @@ +package sopt.org.firstSeminar; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FirstSeminarApplication { + + public static void main(String[] args) { + + SpringApplication.run(FirstSeminarApplication.class, args); + } + +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/Creature.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/Creature.java new file mode 100644 index 0000000..fec1579 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/Creature.java @@ -0,0 +1,36 @@ +package sopt.org.firstSeminar.OOP.abstraction; + +// 추상 클래스 : 클래스 내 추상 메소드가 하나이상 포함되거나 abstract로 정의된 경우 +// 특징 +// 1. 상속을 통해 자식 클래스에서 추상 메소드를 구현해 완성을 유도하는 클래스 +// 2. 추상메소드와 일반 메소드 둘다 가질 수 있다. +// 3. 추상클래스는 인스턴스를 만들수 없지만 추상클래스를 상속받은 클래스를 통하면 인스턴스화가 가능 ex. 추상클래스명 ab = new 클래스명( ) + + +public abstract class Creature { + private String species; + private String name; + private int age; + + public Creature(int age, String name, String species){ + this.age = age; + this.species=species; + this.name=name; + } + + public void age(){ + age++; + } + + public String getSpecies(){ + return this.species; + } + + public String getName(){ + return this.name; + } + + public abstract void move(); + public abstract void communicate(); + +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/Person.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/Person.java new file mode 100644 index 0000000..f1a39b4 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/Person.java @@ -0,0 +1,87 @@ +package sopt.org.firstSeminar.OOP.abstraction; + +import sopt.org.firstSeminar.OOP.abstraction.Creature; + +//추상화 : 불필요한 세부사항을 제거한후 필요한 정보에 따라 본질적이고 "공통적인" 부분만을 추출하여 표현 +// 넓은 의미에서 현실세계의 객체를 필요한 부분만을 따와 클래스로 제작하는 것도 추상화 +public class Person extends Creature implements livingThing{ + private String gender; + private boolean isMarried; + + public Person(int age, String name, String species,String gender, boolean isMarried){ + super(age,name,species); + this.gender=gender; + this.isMarried=isMarried; + } + public void work(){ + System.out.println("사람이 노동한다."); + } + + + @Override + public void move(){ + System.out.println("사람은 걷습니다."); + } + + @Override + public void communicate(){ + System.out.println("사람은 말합니다."); + } + + @Override + public void eat(){ + System.out.println("사람은 밥을 먹는다"); + } + + public static void main(String[] args){ + Creature c = new Person(3,"jiji","인간", "여자", false); + c.move(); + c.communicate(); + //c.work() + // c.eat(); Person의 인스턴스지만 Creature에 없는 메소드나 변수는 접근 못함 + Person p = new Person(2,"ji","인간", "여자", true); + p.move(); + p.communicate(); + p.eat(); + p.work(); + + + } +} + +// 좁은 의미에서 공통되는 부분을 뽑아 상위클래스(부모클래스)와 인터페이스로 정의하는것도 추상화 +// 이때 추상클래스, 인터페이스로 구현가능하다 + + +//인터페이스 : 함수의 껍데기만 있어 해당 함수의 구현을 강제하기위한 목적, 함수의 구현을 강제하기 떄문에 인터페이스를 구현한 객체의 동작을 보장 할 수 있다. +//특징 +// 1. 인터페이스가 인터페이스를 상속가능 +// 2. 인터페이스여러개를 하나의 클래스가 다중 구현 가능 +// 3. 인터페이스 멤버는 반드시 public : 인터페이스는 그 인터페이스를 구현한 클래스를 어떻게 조작할 것인가를 규정-> 그렇기 때문에 외부에서 제어 할 수 있는 가장 개방적인 접근 제어자인 public만을 허용 +// 4. (자바 8 이전에는) 인터페이스는 구체적인 로직이나 상태를 가지고 있을 수 없음 : 모든 메소드가 추상 메소드, 상수와 추상메소드만 가짐 +// -> //그래서 인터페이스를 구현하는 클래스는 같은 기능이여도 중복으로 기능을 구현해야하는 경우 생김 +// (자바 8이후부터는) 인터페이스에 default 메소드가 추가되어 구체적인 로직을 가진 메소드가 가능해짐. -> 그리고 인터페이스를 구현하는 클래스는 default 메소드를 오버라이딩 가능 +// 인터페이스에 static 메소드가 추각되어 구체적인 로직을 구현할 수 있다. 정적 메소드는 오버라이딩이 불가능하다. +// 5. 인터페이스는 인스턴스를 만들수 없지만 인터페이스를 구현한 클래스를 통하면 인스턴스화가 가능 ex. 인터페이스명 ab = new 클래스명( ) + + +// 그럼 인터페이스에 같은 추상메소드가 있을때 확장받은 오버라이딩은 무엇을 오버라이딩 -> 어차피 인터페이스에는 추상메소드 즉 구현되지 안은 메소드 임으로 무엇을 오버라이딩 했든 상관없음 + + + + +// 추상 클래스 : 클래스 내 추상 메소드가 하나이상 포함되거나 abstract로 정의된 경우 +// 특징 +// 1. 상속을 통해 자식 클래스에서 추상 메소드를 구현해 완성을 유도하는 클래스 +// 2. 추상메소드와 일반 메소드 둘다 가질 수 있다. +// 3. 추상클래스는 인스턴스를 만들수 없지만 추상클래스를 상속받은 클래스를 통하면 인스턴스화가 가능 ex. 추상클래스명 ab = new 클래스명( ) + + + +// 추상클래스와 인터페이스의 차이 +// 1. 사용 목적 +// : 인터페이스는 구체적인 로직이나 상태를 가지고 있을 수 없고, 추상클래스는 추상메소드 이외에 구체적인 로직이나 상태를 가지고 있기에 +// 추상클래스는 기능을 확장시키는데 초점, 인터페이스는 함수의 구현만을 강제 +// 2. 추상화정도 : 인터페이스가 추상화정도가 훨씬 높다. 추상클래스는 구체적인로직과 구현을 가질수 았가 때문 + + diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/livingThing.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/livingThing.java new file mode 100644 index 0000000..0df6535 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/abstraction/livingThing.java @@ -0,0 +1,23 @@ +package sopt.org.firstSeminar.OOP.abstraction; + +//인터페이스 : 함수의 껍데기만 있어 해당 함수의 구현을 강제하기위한 목적, 함수의 구현을 강제하기 떄문에 인터페이스를 구현한 객체의 동작을 보장 할 수 있다. +//특징 +// 1. 인터페이스가 인터페이스를 상속가능 +// 2. 인터페이스여러개를 하나의 클래스가 다중 구현 가능 +// 3. 인터페이스 멤버는 반드시 public : 인터페이스는 그 인터페이스를 구현한 클래스를 어떻게 조작할 것인가를 규정-> 그렇기 때문에 외부에서 제어 할 수 있는 가장 개방적인 접근 제어자인 public만을 허용 +// 4. (자바 8 이전에는) 인터페이스는 구체적인 로직이나 상태를 가지고 있을 수 없음 : 모든 메소드가 추상 메소드, 상수와 추상메소드만 가짐 +// -> //그래서 인터페이스를 구현하는 클래스는 같은 기능이여도 중복으로 기능을 구현해야하는 경우 생김 +// (자바 8이후부터는) 인터페이스에 default 메소드가 추가되어 구체적인 로직을 가진 메소드가 가능해짐. -> 그리고 인터페이스를 구현하는 클래스는 default 메소드를 오버라이딩 가능 +// 인터페이스에 static 메소드가 추각되어 구체적인 로직을 구현할 수 있다. 정적 메소드는 오버라이딩이 불가능하다. +// 5. 인터페이스는 인스턴스를 만들수 없지만 인터페이스를 구현한 클래스를 통하면 인스턴스화가 가능 ex. 인터페이스명 ab = new 클래스명( ) + + +// 그럼 인터페이스에 같은 추상메소드가 있을때 확장받은 오버라이딩은 무엇을 오버라이딩? + +public interface livingThing { + public abstract void move(); + + public abstract void communicate(); + + public abstract void eat(); +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/Animal.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/Animal.java new file mode 100644 index 0000000..7381a37 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/Animal.java @@ -0,0 +1,26 @@ +package sopt.org.firstSeminar.OOP.classAndInstance; + +// class : 하나의 역할(관심)을 가지는 단위. 해당 역할(관심)의 수행에 필요한 속성(멤버 변수) 과 행위(메소드)를 가진다 : ex. 쿠키틀 +// instance : 클래스를 토대로 실제 메모리를 할당받아 데이터화 된 객체 : ex. 쿠키 +public class Animal { + private String species; + private String name; + private int age; + + public void speak(){ + System.out.println("동물이 소리를 냅니다."); + } + + public void drink(){ + System.out.println("동물이 물을 마십니다."); + } + + + + public static void main(String[] args) { + //new키워드로 객체 인스턴스 생성 + Animal animal = new Animal(); + animal.speak(); + animal.drink(); + } +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/ConvenienceStore.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/ConvenienceStore.java new file mode 100644 index 0000000..f06072f --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/ConvenienceStore.java @@ -0,0 +1,139 @@ +package sopt.org.firstSeminar.OOP.classAndInstance; + +//생성자를 사용하지 않는 편의점 객체예시 + +/* +public class ConvenienceStore { + //브랜드 + private String brand; + //주소 + private String address; + //직원수 + private int staffCount; + + //총 매출 + private int totalSales; + + public void addStaffCount(){ + staffCount++; + } + + public int getStaffCount(){ + return staffCount; + } + + public void addTotalSales(){ + totalSales++; + } + + public int getTotalSales(){ + return totalSales; + } + + public void initTotalSales(){ + totalSales=0; + } + + public void printConvenienceStoreInfo() { + System.out.println("편의점 브랜드: " + brand); + System.out.println("편의점 주소: " + address); + System.out.println("편의점 직원 수: " + staffCount); + System.out.println("편의점 총 매출 : " + totalSales); + } + + + public static void main(String[] args){ + ConvenienceStore familyMart = new ConvenienceStore(); + + //복잡허다... 그나마 같은 클래스의 메소드라 프라이빗에 접근가능해서 다행 + familyMart.brand="Family Mart"; + familyMart.address = "^*^"; + familyMart.staffCount=6; + + familyMart.initTotalSales(); + familyMart.addStaffCount(); + familyMart.addTotalSales(); + + familyMart.printConvenienceStoreInfo(); + } +} +*/ + +// 생성자 선언을 해준 편의점객체 +public class ConvenienceStore { + //브랜드 + private String brand; + //주소 + private String address; + //직원수 + private int staffCount; + + //총 매출 + private int totalSales; + + //생성자란? : 객체를 생성하는 메소드, new 연산자로 클래스 인스턴스를 생성시 가장 먼저 호출되는 메서드 + + // 잠깐! 생성자도 오버로딩 되나요? -> 됩니다. + public ConvenienceStore(String brand, String address, int staffCount, int totalSales){ + this.brand=brand; + this.address=address; + this.staffCount=staffCount; + this.totalSales=totalSales; + } + + public ConvenienceStore(String brand, String address){ + this.brand=brand; + this.address=address; + this.staffCount=1; + this.totalSales=1; + } + + public ConvenienceStore(String brand, String address, int staffCount){ + this.brand=brand; + this.address=address; + this.staffCount=staffCount; + this.totalSales=1; + } + + public void addStaffCount(){ + staffCount++; + } + + public int getStaffCount(){ + return staffCount; + } + + public void addTotalSales(){ + totalSales++; + } + + public int getTotalSales(){ + return totalSales; + } + + + public void printConvenienceStoreInfo() { + System.out.println("편의점 브랜드: " + brand); + System.out.println("편의점 주소: " + address); + System.out.println("편의점 직원 수: " + staffCount); + System.out.println("편의점 총 매출 : " + totalSales); + } + + + public static void main(String[] args){ + //깔끔 good + ConvenienceStore familyMart = new ConvenienceStore("7-11","gondDUK",4,1234); + + familyMart.addStaffCount(); + familyMart.addTotalSales(); + + familyMart.printConvenienceStoreInfo(); + + ConvenienceStore familyMart2 = new ConvenienceStore("7-11","gondDUK",4); + familyMart2.printConvenienceStoreInfo(); + + ConvenienceStore familyMart3 = new ConvenienceStore("7-11","gondDUK"); + familyMart3.printConvenienceStoreInfo(); + + } +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/NewTest.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/NewTest.java new file mode 100644 index 0000000..9e11873 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/classAndInstance/NewTest.java @@ -0,0 +1,65 @@ +package sopt.org.firstSeminar.OOP.classAndInstance; + + +public class NewTest { + public static void main(String[] args) { + String dog1 = new String("dog"); + String dog2 = new String("dog"); + + // identityHashCode() -> 메모리 주소(저장주소)를 숫자값을로 반환해주는 메서드 + System.out.println(System.identityHashCode(dog1)); //1068934215 + System.out.println(System.identityHashCode(dog2)); //127618319 + // 같은 값(value)을 가진 객체여도 다른 인스턴스임.(각기 다른 메모리주소를 가짐) + + + + // 간단하게 정리하는 스트링 리터럴과 new 객체의 차이점. + // new 연산자로 생성된 객체는 Heap 메모리 영역에 생성된다. + // 스트링 리터럴은 자바 7이전까지는 Pergem안의 string constant pool, + // 자바 7 부터는 Heap 메모리에 작게 할당된 에 저장 string constant pool 에 저장된다. + // 문자열 리터럴이 생성될 때마다 JVM은 해당 문자열이 string constant pool에 존재하는지 확인 + // 있으면, 상수 풀에 저장된 기존 문자열을 쓰고 + // 없으면, 상수풀에 새로 저장한다. + // ! 이때 다른 리터럴 타입(int, bool..) 과 문자열 리터럴은 저장 위치가 다르다 ! 다른 리터럴타입은 일시적으로 스택에 저장됨 + String test1 = "Test"; + String test2 = "Test"; + String test3 = "test"; + String test4 = new String("Test"); + + System.out.println(System.identityHashCode(test1)); //1798286609 + System.out.println(System.identityHashCode(test2)); //1798286609 + System.out.println(System.identityHashCode(test3)); //2036958521 + System.out.println(System.identityHashCode(test4)); //1945604815 + + test3 = "Test"; + System.out.println(System.identityHashCode(test3)); //1798286609 + + + // equals 메소드와 '==' 연산자의 차이 + // equals 메소드는 값만 비교 + System.out.println(dog1.equals(dog2)); + // '==' 연산자는 해당 객체의 메모리 주소를 비교 + System.out.println(dog1 == dog2); + + ConvenienceStore cs1 = new ConvenienceStore("gs","서울",4,5); + ConvenienceStore cs2 = new ConvenienceStore("gs","서울",4,5); + + + // equals 메소드는 값만 비교 + System.out.println(cs1.equals(cs2)); //false + // '==' 연산자는 해당 객체의 메모리 주소를 비교 + System.out.println(cs1 == cs2);//false + //앞에서 equals 메소드는 값만 비교라고했는데 왜 여기서는 둘다 false지? + // 이유 -> String의 equals 메소드와 Object의 equals 메소드는 다름. + // 자바의 모든 객체가 상속받는 최상위 객체인 Object의 equals 메소드는 + + /*public boolean equals(Object obj) { + return (this == obj); + }*/ + + //위와 같다. 내부적으로 주소를 비교하는것! + // 이 equals 메소드를 다른 객체에서 각자 객체의 특성에 맞게(ex. 문자열은 value가 같으면 true 반환) 오버라이딩하여 사용한다. + + + } +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/encapsulation/Capsul.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/encapsulation/Capsul.java new file mode 100644 index 0000000..5677631 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/encapsulation/Capsul.java @@ -0,0 +1,14 @@ +package sopt.org.firstSeminar.OOP.encapsulation; + +public class Capsul { + //접근제어자 범위 + private int p; + //클래스 안에서만 사용가능 + int d; + // default는 클래스안, 같은 패키지 안까지 사용가능 + protected int pp; + //클래스 안, 같은 패키지, 상속받은 자식클래스까지는 사용가능 + public int c; + // 모든 곳에서 접근 가능 + +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/inheritance/Dog.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/inheritance/Dog.java new file mode 100644 index 0000000..3c6adf8 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/inheritance/Dog.java @@ -0,0 +1,38 @@ +package sopt.org.firstSeminar.OOP.inheritance; + +import sopt.org.firstSeminar.OOP.classAndInstance.Animal; + +public class Dog extends Animal { + private String gender; + + public void walk(){ + System.out.println("개가 산책한다."); + } + + public void bark(){ + System.out.println("개가 짖는다."); + } + + public static void main(String[] args){ + Dog doggie1 = new Dog(); + + // 부모 객체를 자식객체로 형변환 가넝~ + Animal doggie2 = new Dog(); + + // 자식객체를 부모객체로 형변환? 불가능 컴파일 에러납니다. + //Dog doggie3 = new Animal(); + + + doggie1.drink(); + doggie1.speak(); + doggie2.drink(); + doggie2.speak(); + + //부모객체로 정의된 인스턴스는 자식객체의 고유 메소드를 사용하지 못한다. + // 당연함 그것이.... 타입정의임 + doggie1.walk(); + doggie1.bark(); + //doggie2.walk(); //컴파일 에러나유 + //doggie2.bark(); //컴파일 에러2 + } +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Calculator.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Calculator.java new file mode 100644 index 0000000..e304886 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Calculator.java @@ -0,0 +1,25 @@ +package sopt.org.firstSeminar.OOP.polymorphism; + +//오버 로딩은 같은 메서드가 다른 타입으로 동작하는 것. +public class Calculator { + Character operator; + + public int add(int a, int b){ + return a+b; + } + + public double add (double a, double b){ + return a+b; + } + + public static void main(String[] args){ + Calculator calculator = new Calculator(); + int intResult = calculator.add(1,10); + + // 아래의 경우는 자동병변환이 일어남 + double doubleResult= calculator.add(1,10); + + System.out.println(intResult); + System.out.println(doubleResult); + } +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Car.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Car.java new file mode 100644 index 0000000..3073c03 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Car.java @@ -0,0 +1,12 @@ +package sopt.org.firstSeminar.OOP.polymorphism; + +public interface Car { + public abstract void turnOn(); + void turnOff(); + // 어차피 인터페이스 내부의 메서드는 전부 추상메서드라서 굳이 표기안해도 public abstract가 기본 + + //인터페이스는 추상메소드로만 이루어져야하는데, 접근제어자의 특성상 public+abstract 조합밖에는 되지 않습니다. + //private abstract void turnTurn(); //컴파일 에러 + //protected abstract void turnIn(); //컴파일 에러 + //default abstract void turnTo(); //컴파일 에러 +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Dog.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Dog.java new file mode 100644 index 0000000..dd44fdb --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Dog.java @@ -0,0 +1,21 @@ +package sopt.org.firstSeminar.OOP.polymorphism; + +import sopt.org.firstSeminar.OOP.classAndInstance.Animal; + +//사실 지금 다른 패키지에 있기때문에 같은 이름을 가진 클래스가 존재는 할 수 있지만 +// 이런 이름이 같은 클래스 사용은 안하는게 좋음. +// 물론 이건 연습 코드라서.... +public class Dog extends Animal { + private String gender; + + public void walk(){ + System.out.println("개가 산책한다."); + + } + + // 오버라이딩은 자식 객체가 상속받는 부모객체의 메소드와 정확히 같은 메소드를 오버라이딩(재정의) 할 수 있다. + @Override + public void speak(){ + System.out.println("개가 짖는다."); + } +} \ No newline at end of file diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/GenericTest.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/GenericTest.java new file mode 100644 index 0000000..cdde9e7 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/GenericTest.java @@ -0,0 +1,87 @@ +package sopt.org.firstSeminar.OOP.polymorphism; + + +// 본래 하나의 파일에 하나의 클래스가 원칙이지만, +// public class(한파일당 하나, 파일의 이름)과 class들의 조합도 가능은 함 +// 그러나 권장되지는 않는다! + + + +//제네릭의 사용위치 1. 클래스, 인터페이스 내부 + +import java.util.ArrayList; + +class GenericClass { + T type; + //여러개의 제네릭 사용가능 + E element; + + S string; + + public S IsGenericMthod(T type){ + //제네릭은 런타임으로 지정되지만, 제네릭으로 들어오는 타입을 구체적으로 코드상을 명사할 경우 컴파일 에러 + //return element.getClass().getName(); + return string; + } + + + // 제네릭의 사용위치 2. 메소드 내부 + // 클래스, 인터페이스에서 지정된 제너릭을 사용할수도 있으나 < > 안의 제네릭은 메소드 범위 내의 제네릭임으로 + // GenericClass의 S와 동일한 키워드지만 메소드 자체 키워드이다. + // 같은 키워드를 쓰지 않도록 주의해서 사용해자 + public S genericMethod1(S type){ + return type; + } + //메소드의 < > 안의 키워드가 아닌 키워드는 클래스(또는 인터페이스) 안이기에 클래스의 키워드를 쓸 수 있다. + public E genericMethod2(E type1, S type2){ + System.out.println(type1.getClass().getName()); + + System.out.println(type2.getClass().getName()); + + return type1; + } + + // 메소드 자체 키워드 K는 메소드의 두번째 매개변수에 따라 바뀌지만 T는 클래스 선언시 정해진 제네릭 타입을 띠리야 한다. + public T genericMethod3(T type1, K type2, V type3){ + System.out.println(type2.getClass().getName()); + System.out.println(type3.getClass().getName()); + + return type1; + } +} + +// interface GenericTest {} +public class GenericTest { + public static void main(String[] args){ + GenericClass genericClass = new GenericClass(); + + Double d = 10.3; + Integer i = 3; + //genericClass.IsGenericMthod(d); //컴파일 에러남 + String s = genericClass.IsGenericMthod(i); + System.out.println(s); + + String a = genericClass.genericMethod1("wow"); + System.out.println(a); + + Integer b = genericClass.genericMethod1(i); + System.out.println(b); + + Double dd = genericClass.genericMethod2(d, i); + System.out.println(dd); + + //Integer ii = genericClass.genericMethod2(i, d); //컴파일 에러 + //System.out.println(ii); + + Integer ig = genericClass.genericMethod3(i,new ArrayList(), new Object()); + System.out.println(ig); + + Integer ih = genericClass.genericMethod3(i,new String(), new Double(11.1)); + System.out.println(ih); + + //Integer ij = genericClass.genericMethod3(new ArrayList(),i, new Object()); //컴파일 에러 + + + + } +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Person.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Person.java new file mode 100644 index 0000000..982492b --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Person.java @@ -0,0 +1,18 @@ +package sopt.org.firstSeminar.OOP.polymorphism; + +//사실 지금 다른 패키지에 있기때문에 같은 이름을 가진 클래스와 인터페이스가 존재는 할 수 있지만 +// 같은 이름은 최대한 사용은 안하는게 좋음. +// 물론 이건 연습 코드라서.... +public abstract class Person { + // 추상 클래스에서 추상 메소드조합은 접근 제어자 특성상 public, protected만 가능하다. + //private abstract void turnTurn(); //컴파일 에러 + //default abstract void turnTo(); //컴파일 에러 + + protected abstract void turnIn(); + + public abstract void walk(); + private String gender; + + + +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/SportsCar.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/SportsCar.java new file mode 100644 index 0000000..c556be1 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/SportsCar.java @@ -0,0 +1,12 @@ +package sopt.org.firstSeminar.OOP.polymorphism; + +public class SportsCar implements Car{ + @Override + public void turnOn(){ + System.out.println("스포츠차 시동켜기"); + } + @Override + public void turnOff(){ + System.out.println("스포츠차 시동끄기"); + } +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Student.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Student.java new file mode 100644 index 0000000..bba4b16 --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/OOP/polymorphism/Student.java @@ -0,0 +1,15 @@ +package sopt.org.firstSeminar.OOP.polymorphism; +import sopt.org.firstSeminar.OOP.abstraction.Person; +public class Student extends Person { + public Student(int age, String name, String species,String gender, boolean isMarried){ + super(age,name,species,gender,isMarried); + + } + @Override + public void work(){ + System.out.println("학생은 공부한다."); + } + + + +} diff --git a/firstSeminar/src/main/java/sopt/org/firstSeminar/controller/TestController.java b/firstSeminar/src/main/java/sopt/org/firstSeminar/controller/TestController.java new file mode 100644 index 0000000..bf29fcf --- /dev/null +++ b/firstSeminar/src/main/java/sopt/org/firstSeminar/controller/TestController.java @@ -0,0 +1,13 @@ +package sopt.org.firstSeminar.controller; + +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.GetMapping; + + +@RestController +public class TestController { + @GetMapping("/test") + public String test(){ + return "Welcome Spring"; + } +} \ No newline at end of file diff --git a/firstSeminar/src/test/java/sopt/org/firstSeminar/FirstSeminarApplicationTests.java b/firstSeminar/src/test/java/sopt/org/firstSeminar/FirstSeminarApplicationTests.java new file mode 100644 index 0000000..228964f --- /dev/null +++ b/firstSeminar/src/test/java/sopt/org/firstSeminar/FirstSeminarApplicationTests.java @@ -0,0 +1,13 @@ +package sopt.org.firstSeminar; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class FirstSeminarApplicationTests { + + @Test + void contextLoads() { + } + +}