├── .idea
├── .gitignore
├── codeStyles
│ └── codeStyleConfig.xml
├── description.html
├── dictionaries
│ └── krung2.xml
├── encodings.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── libraries
│ ├── logback_classic_1_2_5.xml
│ ├── logback_core_1_2_5.xml
│ └── slf4j_api_1_7_9.xml
├── misc.xml
├── modules.xml
├── project-template.xml
├── runConfigurations.xml
├── uiDesigner.xml
└── vcs.xml
├── JAVA_Class.iml
├── libs
├── logback-classic-1.2.5.jar
├── logback-core-1.2.5.jar
├── mariadb-java-client-2.4.1.jar
└── slf4j-api-1.7.9.jar
├── out
└── production
│ ├── .DS_Store
│ └── JAVA_Class
│ ├── AnotherTime
│ └── Test.class
│ ├── com
│ └── classTime
│ │ ├── Dog.class
│ │ ├── Factorization
│ │ └── Factorization.class
│ │ ├── Hello.class
│ │ ├── Inheritance
│ │ ├── Animal.class
│ │ ├── Calc
│ │ │ ├── Adder.class
│ │ │ ├── Divider.class
│ │ │ ├── Multiplier.class
│ │ │ └── Subtract.class
│ │ ├── Mammal.class
│ │ ├── MyClass.class
│ │ └── tr1
│ │ │ ├── Circle.class
│ │ │ ├── Polygon.class
│ │ │ ├── Scanner_.class
│ │ │ ├── Square.class
│ │ │ └── Triangle.class
│ │ ├── SmallCalc
│ │ ├── ScannerFuc.class
│ │ ├── SmallCalc.class
│ │ └── SmallCalcRun.class
│ │ ├── SmallCalcT
│ │ └── NumberAnalyser.class
│ │ ├── Sum.class
│ │ ├── abstractClass
│ │ ├── Animal.class
│ │ └── Dog.class
│ │ ├── accumulator
│ │ ├── Accumulator.class
│ │ ├── AccumulatorRunner.class
│ │ └── ScannerStudy.class
│ │ ├── api
│ │ ├── GenericStudy.class
│ │ ├── ListStudy.class
│ │ ├── MapStudy.class
│ │ ├── MyClass.class
│ │ └── PhoneBook
│ │ │ ├── Book.class
│ │ │ └── Data.class
│ │ ├── array
│ │ ├── ArrayStudy.class
│ │ ├── BestSort.class
│ │ ├── InsertSort.class
│ │ ├── Queue.class
│ │ ├── SelectionSort.class
│ │ ├── Sort.class
│ │ └── Stack.class
│ │ ├── assessment
│ │ ├── BinarySearch.class
│ │ ├── baseball
│ │ │ └── Baseball.class
│ │ ├── newPhoneBook
│ │ │ ├── DBPhoneBook.class
│ │ │ ├── NameCard.class
│ │ │ └── PhoneBook.class
│ │ └── phoneBook
│ │ │ ├── DBPhoneBook.class
│ │ │ ├── FilePhoneBook.class
│ │ │ ├── NameCard.class
│ │ │ ├── PhoneBook.class
│ │ │ ├── PhoneBookTest.class
│ │ │ └── phoneBook.dat
│ │ ├── file
│ │ ├── FileCopy.class
│ │ ├── FileFinder.class
│ │ ├── FileImage.class
│ │ ├── FileReader.class
│ │ ├── FileStudy.class
│ │ ├── FileWrite.class
│ │ ├── TextFile.class
│ │ └── commandLine
│ │ │ └── Command.class
│ │ ├── interface1
│ │ ├── Animal.class
│ │ ├── Cat.class
│ │ ├── Doer.class
│ │ └── Dog.class
│ │ ├── jdbc
│ │ ├── Jdbc.class
│ │ ├── JdbcStudy.class
│ │ └── NameCard.class
│ │ ├── tryCatch
│ │ ├── MyList.class
│ │ ├── Node.class
│ │ └── TryStudy.class
│ │ └── variable
│ │ ├── CharStudy.class
│ │ ├── DoubleStudy.class
│ │ ├── Hex.class
│ │ ├── IntegerStudy.class
│ │ └── VariableStudy.class
│ ├── kr
│ └── hs
│ │ └── dgsw
│ │ └── javaClass
│ │ ├── nio
│ │ ├── FileStudy.class
│ │ ├── charBuffer
│ │ │ └── BufferStudy.class
│ │ ├── fileChannel
│ │ │ └── FileChannelStudy.class
│ │ └── studyFile
│ │ │ ├── favicon.ico
│ │ │ ├── hello.txt
│ │ │ ├── new
│ │ │ └── new.txt
│ │ │ └── read.txt
│ │ ├── server
│ │ ├── BroadCastServerWorker.class
│ │ ├── CommonClient.class
│ │ ├── CommonServer$Agent.class
│ │ ├── CommonServer.class
│ │ ├── EchoServerWorker.class
│ │ ├── SimpleClient.class
│ │ ├── SimpleServer.class
│ │ ├── SocketWorker.class
│ │ ├── SocketWorkerAdapter$Listener.class
│ │ ├── SocketWorkerAdapter.class
│ │ ├── myself
│ │ │ ├── MyClient.class
│ │ │ └── MyServer.class
│ │ ├── nioBlockingServer
│ │ │ ├── NioBlockingServer.class
│ │ │ ├── SocketChannelAgent$Listener.class
│ │ │ └── SocketChannelAgent.class
│ │ └── nioNonBlockingServer
│ │ │ └── NioNonBlockingServer.class
│ │ ├── tcpServer
│ │ ├── ErrorCode.class
│ │ ├── SessionsCallback.class
│ │ ├── TcpServer.class
│ │ ├── TcpServerException.class
│ │ ├── TcpServerFactory.class
│ │ ├── TcpSession.class
│ │ ├── dev
│ │ │ ├── Executor.class
│ │ │ └── SimpleSessionsCallback.class
│ │ └── type
│ │ │ ├── blocking
│ │ │ ├── BlockingServer.class
│ │ │ ├── BlockingServerAgent$Listener.class
│ │ │ └── BlockingServerAgent.class
│ │ │ ├── nonblocking
│ │ │ ├── NonBlockingServer.class
│ │ │ └── NonBlockingServerSession.class
│ │ │ └── socket
│ │ │ ├── SocketServer.class
│ │ │ ├── SocketServerAgent$Listener.class
│ │ │ └── SocketServerAgent.class
│ │ ├── test
│ │ ├── ChattingClient$1.class
│ │ ├── ChattingClient.class
│ │ ├── ChattingCommand.class
│ │ ├── ChattingServer$Agent.class
│ │ ├── ChattingServer.class
│ │ ├── ChattingServerWorker$1.class
│ │ ├── ChattingServerWorker.class
│ │ ├── Message.class
│ │ ├── SocketWorker$Listener.class
│ │ └── SocketWorker.class
│ │ └── thread
│ │ ├── Calculater.class
│ │ ├── DaemonThread.class
│ │ ├── MainClass.class
│ │ ├── MyRunnable.class
│ │ ├── MyThread.class
│ │ ├── Stop.class
│ │ ├── SyncThread.class
│ │ ├── WaitThread.class
│ │ └── producerConsumer
│ │ ├── Consumer.class
│ │ ├── Producer.class
│ │ └── ProducerConsumerDoer.class
│ └── performance
│ └── makeStudent
│ └── student.class
├── readme.md
└── src
├── AnotherTime
└── Test.java
├── com
└── classTime
│ ├── .DS_Store
│ ├── Dog.java
│ ├── Factorization
│ └── Factorization.java
│ ├── Hello.java
│ ├── Inheritance
│ ├── .DS_Store
│ ├── Animal.java
│ ├── Calc
│ │ ├── Adder.java
│ │ ├── Divider.java
│ │ ├── Multiplier.java
│ │ └── Subtract.java
│ ├── Mammal.java
│ ├── MyClass.java
│ └── tr1
│ │ ├── Circle.java
│ │ ├── Polygon.java
│ │ ├── Scanner_.java
│ │ ├── Square.java
│ │ └── Triangle.java
│ ├── SmallCalc
│ ├── ScannerFuc.java
│ ├── SmallCalc.java
│ └── SmallCalcRun.java
│ ├── SmallCalcT
│ └── NumberAnalyser.java
│ ├── Sum.java
│ ├── abstractClass
│ ├── Animal.java
│ └── Dog.java
│ ├── accumulator
│ ├── Accumulator.java
│ ├── AccumulatorRunner.java
│ └── ScannerStudy.java
│ ├── api
│ ├── GenericStudy.java
│ ├── ListStudy.java
│ ├── MapStudy.java
│ ├── MyClass.java
│ └── PhoneBook
│ │ ├── Book.java
│ │ └── Data.java
│ ├── array
│ ├── ArrayStudy.java
│ ├── BestSort.java
│ ├── InsertSort.java
│ ├── Queue.java
│ ├── SelectionSort.java
│ ├── Sort.java
│ └── Stack.java
│ ├── assessment
│ ├── BinarySearch.java
│ ├── baseball
│ │ └── Baseball.java
│ ├── newPhoneBook
│ │ ├── DBPhoneBook.java
│ │ ├── NameCard.java
│ │ └── PhoneBook.java
│ └── phoneBook
│ │ ├── .DS_Store
│ │ ├── DBPhoneBook.java
│ │ ├── FilePhoneBook.java
│ │ ├── NameCard.java
│ │ ├── PhoneBook.java
│ │ ├── PhoneBookTest.java
│ │ └── phoneBook.dat
│ ├── file
│ ├── FileCopy.java
│ ├── FileFinder.java
│ ├── FileImage.java
│ ├── FileReader.java
│ ├── FileStudy.java
│ ├── FileWrite.java
│ ├── TextFile.java
│ └── commandLine
│ │ └── Command.java
│ ├── interface1
│ ├── Animal.java
│ ├── Cat.java
│ ├── Doer.java
│ └── Dog.java
│ ├── jdbc
│ ├── Jdbc.java
│ ├── JdbcStudy.java
│ └── NameCard.java
│ ├── tryCatch
│ ├── MyList.java
│ ├── Node.java
│ └── TryStudy.java
│ └── variable
│ ├── CharStudy.java
│ ├── DoubleStudy.java
│ ├── Hex.java
│ ├── IntegerStudy.java
│ └── VariableStudy.java
├── kr
└── hs
│ └── dgsw
│ └── javaClass
│ ├── nio
│ ├── FileStudy.java
│ ├── charBuffer
│ │ └── BufferStudy.java
│ ├── fileChannel
│ │ └── FileChannelStudy.java
│ └── studyFile
│ │ ├── favicon.ico
│ │ ├── hello.txt
│ │ ├── new
│ │ └── new.txt
│ │ └── read.txt
│ ├── server
│ ├── BroadCastServerWorker.java
│ ├── CommonClient.java
│ ├── CommonServer.java
│ ├── EchoServerWorker.java
│ ├── SimpleClient.java
│ ├── SimpleServer.java
│ ├── SocketWorker.java
│ ├── SocketWorkerAdapter.java
│ ├── myself
│ │ ├── MyClient.java
│ │ └── MyServer.java
│ ├── nioBlockingServer
│ │ ├── NioBlockingServer.java
│ │ └── SocketChannelAgent.java
│ └── nioNonBlockingServer
│ │ └── NioNonBlockingServer.java
│ ├── tcpServer
│ ├── ErrorCode.java
│ ├── SessionsCallback.java
│ ├── TcpServer.java
│ ├── TcpServerException.java
│ ├── TcpServerFactory.java
│ ├── TcpSession.java
│ ├── dev
│ │ ├── Executor.java
│ │ └── SimpleSessionsCallback.java
│ └── type
│ │ ├── blocking
│ │ ├── BlockingServer.java
│ │ └── BlockingServerAgent.java
│ │ ├── nonblocking
│ │ ├── NonBlockingServer.java
│ │ └── NonBlockingServerSession.java
│ │ └── socket
│ │ ├── SocketServer.java
│ │ └── SocketServerAgent.java
│ ├── test
│ ├── ChattingClient.java
│ ├── ChattingCommand.java
│ ├── ChattingServer.java
│ ├── ChattingServerWorker.java
│ ├── Message.java
│ └── SocketWorker.java
│ └── thread
│ ├── Calculater.java
│ ├── DaemonThread.java
│ ├── MainClass.java
│ ├── MyRunnable.java
│ ├── MyThread.java
│ ├── Stop.java
│ ├── SyncThread.java
│ ├── WaitThread.java
│ └── producerConsumer
│ ├── Consumer.java
│ ├── Producer.java
│ └── ProducerConsumerDoer.java
└── performance
└── makeStudent
└── student.java
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple Java application that includes a class with main()
method
--------------------------------------------------------------------------------
/.idea/dictionaries/krung2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/logback_classic_1_2_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/logback_core_1_2_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/libraries/slf4j_api_1_7_9.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/project-template.xml:
--------------------------------------------------------------------------------
1 |
2 | IJ_BASE_PACKAGE
3 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/JAVA_Class.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/libs/logback-classic-1.2.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/libs/logback-classic-1.2.5.jar
--------------------------------------------------------------------------------
/libs/logback-core-1.2.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/libs/logback-core-1.2.5.jar
--------------------------------------------------------------------------------
/libs/mariadb-java-client-2.4.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/libs/mariadb-java-client-2.4.1.jar
--------------------------------------------------------------------------------
/libs/slf4j-api-1.7.9.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/libs/slf4j-api-1.7.9.jar
--------------------------------------------------------------------------------
/out/production/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/.DS_Store
--------------------------------------------------------------------------------
/out/production/JAVA_Class/AnotherTime/Test.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/AnotherTime/Test.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Dog.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Dog.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Factorization/Factorization.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Factorization/Factorization.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Hello.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Hello.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/Animal.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/Animal.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/Calc/Adder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/Calc/Adder.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/Calc/Divider.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/Calc/Divider.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/Calc/Multiplier.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/Calc/Multiplier.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/Calc/Subtract.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/Calc/Subtract.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/Mammal.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/Mammal.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/MyClass.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/MyClass.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Circle.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Circle.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Polygon.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Polygon.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Scanner_.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Scanner_.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Square.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Square.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Triangle.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Inheritance/tr1/Triangle.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/SmallCalc/ScannerFuc.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/SmallCalc/ScannerFuc.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/SmallCalc/SmallCalc.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/SmallCalc/SmallCalc.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/SmallCalc/SmallCalcRun.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/SmallCalc/SmallCalcRun.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/SmallCalcT/NumberAnalyser.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/SmallCalcT/NumberAnalyser.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/Sum.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/Sum.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/abstractClass/Animal.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/abstractClass/Animal.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/abstractClass/Dog.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/abstractClass/Dog.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/accumulator/Accumulator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/accumulator/Accumulator.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/accumulator/AccumulatorRunner.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/accumulator/AccumulatorRunner.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/accumulator/ScannerStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/accumulator/ScannerStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/api/GenericStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/api/GenericStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/api/ListStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/api/ListStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/api/MapStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/api/MapStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/api/MyClass.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/api/MyClass.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/api/PhoneBook/Book.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/api/PhoneBook/Book.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/api/PhoneBook/Data.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/api/PhoneBook/Data.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/array/ArrayStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/array/ArrayStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/array/BestSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/array/BestSort.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/array/InsertSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/array/InsertSort.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/array/Queue.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/array/Queue.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/array/SelectionSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/array/SelectionSort.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/array/Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/array/Sort.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/array/Stack.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/array/Stack.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/BinarySearch.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/BinarySearch.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/baseball/Baseball.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/baseball/Baseball.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/newPhoneBook/DBPhoneBook.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/newPhoneBook/DBPhoneBook.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/newPhoneBook/NameCard.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/newPhoneBook/NameCard.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/newPhoneBook/PhoneBook.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/newPhoneBook/PhoneBook.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/phoneBook/DBPhoneBook.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/phoneBook/DBPhoneBook.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/phoneBook/FilePhoneBook.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/phoneBook/FilePhoneBook.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/phoneBook/NameCard.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/phoneBook/NameCard.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/phoneBook/PhoneBook.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/phoneBook/PhoneBook.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/phoneBook/PhoneBookTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/assessment/phoneBook/PhoneBookTest.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/assessment/phoneBook/phoneBook.dat:
--------------------------------------------------------------------------------
1 | 정재봉 010-3458-4250 대구시 동구
2 | 유산슬 010-5555-6666 합정역 5번 출구
3 | 윤여정 010-9876-5432 아카데미 시상식장
4 |
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/file/FileCopy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/file/FileCopy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/file/FileFinder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/file/FileFinder.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/file/FileImage.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/file/FileImage.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/file/FileReader.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/file/FileReader.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/file/FileStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/file/FileStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/file/FileWrite.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/file/FileWrite.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/file/TextFile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/file/TextFile.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/file/commandLine/Command.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/file/commandLine/Command.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/interface1/Animal.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/interface1/Animal.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/interface1/Cat.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/interface1/Cat.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/interface1/Doer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/interface1/Doer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/interface1/Dog.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/interface1/Dog.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/jdbc/Jdbc.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/jdbc/Jdbc.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/jdbc/JdbcStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/jdbc/JdbcStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/jdbc/NameCard.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/jdbc/NameCard.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/tryCatch/MyList.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/tryCatch/MyList.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/tryCatch/Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/tryCatch/Node.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/tryCatch/TryStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/tryCatch/TryStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/variable/CharStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/variable/CharStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/variable/DoubleStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/variable/DoubleStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/variable/Hex.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/variable/Hex.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/variable/IntegerStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/variable/IntegerStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/com/classTime/variable/VariableStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/com/classTime/variable/VariableStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/FileStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/FileStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/charBuffer/BufferStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/charBuffer/BufferStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/fileChannel/FileChannelStudy.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/fileChannel/FileChannelStudy.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/studyFile/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/studyFile/favicon.ico
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/studyFile/hello.txt:
--------------------------------------------------------------------------------
1 | 안녕하세요. 대소고 여러분
2 |
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/studyFile/new/new.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/studyFile/new/new.txt
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/nio/studyFile/read.txt:
--------------------------------------------------------------------------------
1 | 대구소프트웨어마이스터고등학교
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/BroadCastServerWorker.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/BroadCastServerWorker.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/CommonClient.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/CommonClient.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/CommonServer$Agent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/CommonServer$Agent.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/CommonServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/CommonServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/EchoServerWorker.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/EchoServerWorker.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SimpleClient.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SimpleClient.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SimpleServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SimpleServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SocketWorker.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SocketWorker.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SocketWorkerAdapter$Listener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SocketWorkerAdapter$Listener.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SocketWorkerAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/SocketWorkerAdapter.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/myself/MyClient.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/myself/MyClient.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/myself/MyServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/myself/MyServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/nioBlockingServer/NioBlockingServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/nioBlockingServer/NioBlockingServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/nioBlockingServer/SocketChannelAgent$Listener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/nioBlockingServer/SocketChannelAgent$Listener.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/nioBlockingServer/SocketChannelAgent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/nioBlockingServer/SocketChannelAgent.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/nioNonBlockingServer/NioNonBlockingServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/server/nioNonBlockingServer/NioNonBlockingServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/ErrorCode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/ErrorCode.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/SessionsCallback.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/SessionsCallback.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/TcpServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/TcpServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/TcpServerException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/TcpServerException.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/TcpServerFactory.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/TcpServerFactory.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/TcpSession.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/TcpSession.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/dev/Executor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/dev/Executor.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/dev/SimpleSessionsCallback.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/dev/SimpleSessionsCallback.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/blocking/BlockingServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/blocking/BlockingServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/blocking/BlockingServerAgent$Listener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/blocking/BlockingServerAgent$Listener.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/blocking/BlockingServerAgent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/blocking/BlockingServerAgent.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/nonblocking/NonBlockingServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/nonblocking/NonBlockingServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/nonblocking/NonBlockingServerSession.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/nonblocking/NonBlockingServerSession.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/socket/SocketServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/socket/SocketServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/socket/SocketServerAgent$Listener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/socket/SocketServerAgent$Listener.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/socket/SocketServerAgent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/tcpServer/type/socket/SocketServerAgent.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingClient$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingClient$1.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingClient.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingClient.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingCommand.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingCommand.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingServer$Agent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingServer$Agent.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingServer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingServerWorker$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingServerWorker$1.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingServerWorker.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/ChattingServerWorker.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/Message.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/Message.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/SocketWorker$Listener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/SocketWorker$Listener.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/SocketWorker.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/test/SocketWorker.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/Calculater.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/Calculater.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/DaemonThread.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/DaemonThread.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/MainClass.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/MainClass.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/MyRunnable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/MyRunnable.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/MyThread.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/MyThread.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/Stop.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/Stop.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/SyncThread.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/SyncThread.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/WaitThread.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/WaitThread.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/producerConsumer/Consumer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/producerConsumer/Consumer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/producerConsumer/Producer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/producerConsumer/Producer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/producerConsumer/ProducerConsumerDoer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/kr/hs/dgsw/javaClass/thread/producerConsumer/ProducerConsumerDoer.class
--------------------------------------------------------------------------------
/out/production/JAVA_Class/performance/makeStudent/student.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/out/production/JAVA_Class/performance/makeStudent/student.class
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | ## JAVA_Class
2 |
3 |
4 |
5 | - 보시기 전 `STAR` 한번씩 만 부탁드립니당!
6 | - 매 자바 시간마다 커밋
7 | - 자바 수업이 든 날에는 새로운 브랜치 파서 커밋
8 | - 매주 주말 일요일에 모아 한번에 커밋
9 | - 커밋 메시지는 그날 배운것들로 정리
10 | - 꾸준하게 하기
11 |
--------------------------------------------------------------------------------
/src/AnotherTime/Test.java:
--------------------------------------------------------------------------------
1 | package AnotherTime;
2 |
3 | public class Test {
4 | public static void main(String[] args) {
5 | System.out.println("123");
6 | for (int i = 0;i < 10; i++) {
7 | System.out.println(i);
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/com/classTime/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/src/com/classTime/.DS_Store
--------------------------------------------------------------------------------
/src/com/classTime/Dog.java:
--------------------------------------------------------------------------------
1 | package com.classTime;
2 |
3 | public class Dog {
4 |
5 | String name;
6 | int age;
7 | String gender;
8 |
9 | public Dog() {}
10 |
11 | public Dog(String name) {
12 | this.name = name;
13 | }
14 |
15 | public Dog(String name, int age) {
16 | this.name = name;
17 | this.age = age;
18 | }
19 |
20 | public Dog(String name, int age, String gender) {
21 | this.name = name;
22 | this.age = age;
23 | this.gender = gender;
24 | }
25 |
26 | public void bark() {
27 |
28 | }
29 |
30 | public void run() {
31 |
32 | }
33 |
34 | public void eat(String food) {
35 | System.out.println(name + "가 " + food + "를 먹습니다");
36 | }
37 |
38 | public static void main(String[] args) {
39 |
40 | Dog mesi = new Dog();
41 | Dog snoopy = new Dog();
42 | Dog nardo = new Dog("호날두");
43 |
44 | mesi.name = "mesi";
45 | mesi.age = 3;
46 | mesi.gender = "F";
47 |
48 | snoopy.name = "snoopy";
49 | snoopy.age = 10;
50 | snoopy.gender = "M";
51 |
52 | mesi.eat("사료");
53 | snoopy.eat("고기");
54 | nardo.eat("골");
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/com/classTime/Factorization/Factorization.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Factorization;public class Factorization {
2 | }
3 |
--------------------------------------------------------------------------------
/src/com/classTime/Hello.java:
--------------------------------------------------------------------------------
1 | package com.classTime;
2 |
3 | public class Hello {
4 | public static void main (String [] args) {
5 | System.out.println(args.length);
6 |
7 | System.out.println("Hello Java!");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/src/com/classTime/Inheritance/.DS_Store
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/Animal.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance;
2 |
3 | public class Animal {
4 |
5 | protected String name;
6 | private String food;
7 |
8 | public void eat() {
9 | System.out.println(getName() + "이(가) " + getFood() + "을(를) 먹는다");
10 | }
11 |
12 | public String getName() {
13 | return name;
14 | }
15 |
16 | public void setName(String name) {
17 | this.name = name;
18 | }
19 |
20 | public String getFood() {
21 | return food;
22 | }
23 |
24 | public void setFood(String food) {
25 | this.food = food;
26 | }
27 |
28 | public static void main(String[] args) {
29 |
30 | Animal cat = new Animal();
31 | cat.setName("고양이");
32 | cat.setFood("고기");
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/Calc/Adder.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.Calc;
2 |
3 | import java.util.Scanner;
4 |
5 | public class Adder {
6 |
7 | private int operand1;
8 | private int operand2;
9 | Scanner scanner = new Scanner(System.in);
10 |
11 | public int calculate() {
12 | return operand1 + operand2;
13 | }
14 |
15 | public void display() {
16 | String str = String.format("%d %s %d = %d",
17 | operand1, getOperator(), operand2, calculate());
18 |
19 | System.out.println(str);
20 | }
21 |
22 | public String getOperator() {
23 | return "+";
24 | }
25 |
26 | public int scan() {
27 | return scanner.nextInt();
28 | }
29 |
30 | protected void mainFunc() {
31 |
32 | while (true) {
33 |
34 | setOperand1(scan());
35 | setOperand2(scan());
36 |
37 | if (0 == operand1 && 0 == operand2) {
38 | break;
39 | }
40 |
41 | display();
42 | }
43 | }
44 |
45 | public int getOperand1() {
46 | return operand1;
47 | }
48 |
49 | public void setOperand1(int operand1) {
50 | this.operand1 = operand1;
51 | }
52 |
53 | public int getOperand2() {
54 | return operand2;
55 | }
56 |
57 | public void setOperand2(int operand2) {
58 | this.operand2 = operand2;
59 | }
60 |
61 | public static void main(String[] args) {
62 | Adder adder = new Adder();
63 | adder.setOperand1(4928);
64 | adder.setOperand2(9282);
65 |
66 | adder.display();
67 |
68 | adder.mainFunc();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/Calc/Divider.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.Calc;
2 |
3 | public class Divider extends Adder {
4 |
5 | @Override
6 | public int calculate() {
7 | return getOperand1() / getOperand2();
8 | }
9 |
10 | @Override
11 | public String getOperator() {
12 | return "-";
13 | }
14 |
15 | public static void main(String[] args) {
16 | Divider divider = new Divider();
17 |
18 | divider.mainFunc();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/Calc/Multiplier.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.Calc;
2 |
3 | public class Multiplier extends Adder{
4 |
5 | @Override
6 | public int calculate() {
7 | return getOperand1() * getOperand2();
8 | }
9 |
10 | @Override
11 | public String getOperator() {
12 | return "-";
13 | }
14 |
15 | public static void main(String[] args) {
16 | Multiplier multiplier = new Multiplier();
17 |
18 | multiplier.mainFunc();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/Calc/Subtract.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.Calc;
2 |
3 | public class Subtract extends Adder {
4 |
5 | @Override
6 | public int calculate() {
7 | return getOperand1() - getOperand2();
8 | }
9 |
10 | @Override
11 | public String getOperator() {
12 | return "-";
13 | }
14 |
15 | public static void main(String[] args) {
16 | Subtract subtract = new Subtract();
17 | // subtract.setOperand1(4928);
18 | // subtract.setOperand2(9282);
19 | //
20 | // subtract.display();
21 |
22 | subtract.mainFunc();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/Mammal.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance;
2 |
3 | public class Mammal extends Animal {
4 |
5 | public void birthBaby() {
6 | System.out.println(getName() + "이(가) 새끼를 낳는다.");
7 | }
8 |
9 | public void eat() {
10 | System.out.println(getName() + "이(가) 아기 때에는 젖을 먹습니다.");
11 | super.eat();
12 | }
13 |
14 |
15 | public static void main(String[] args) {
16 |
17 | Mammal hippo = new Mammal();
18 | hippo.setName("하마");
19 | hippo.setFood("물");
20 |
21 | hippo.eat();
22 |
23 | Animal dog = new Mammal();
24 | // Mammal mouse = new Animal(); 허용 안됨
25 |
26 | // dog.birthBaby(); Animal타입에는 birthBaby라는 메소드가 없음
27 | dog.eat();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/MyClass.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance;
2 |
3 | public class MyClass {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyClass myClass = new MyClass();
8 | System.out.println(myClass.toString());
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/tr1/Circle.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.tr1;
2 |
3 | public class Circle extends Polygon{
4 |
5 | private double radius;
6 | private final double PI = 3.141592;
7 |
8 | public double getRadius() {
9 | return radius;
10 | }
11 |
12 | public void setRadius(double radius) {
13 | this.radius = radius;
14 | }
15 |
16 | public double getPI() {
17 | return PI;
18 | }
19 |
20 | @Override
21 | public double getArea() {
22 | return radius * radius * PI;
23 | }
24 |
25 | @Override
26 | public String getName() {
27 | return "원";
28 | }
29 |
30 | public static void main(String[] args) {
31 |
32 | Scanner_ scanner_ = new Scanner_();
33 | Circle circle = new Circle();
34 |
35 | System.out.println("반지름의 길이를 입력해 주세요");
36 | circle.setRadius(scanner_.getValue());
37 |
38 | circle.printArea();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/tr1/Polygon.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.tr1;
2 |
3 | public abstract class Polygon {
4 |
5 | public abstract double getArea();
6 |
7 | public abstract String getName();
8 |
9 | public void printArea() {
10 | System.out.println(getName() + "의 면적 : " + getArea());
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/tr1/Scanner_.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.tr1;
2 |
3 | import java.util.Scanner;
4 |
5 | public class Scanner_ {
6 |
7 | public Scanner _scanner = new Scanner(System.in);
8 |
9 | public int getValue() {
10 | return _scanner.nextInt();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/tr1/Square.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.tr1;
2 |
3 | public class Square extends Polygon{
4 |
5 | private int bottom;
6 | private int height;
7 |
8 | public int getBottom() {
9 | return bottom;
10 | }
11 |
12 | public void setBottom(int bottom) {
13 | this.bottom = bottom;
14 | }
15 |
16 | public int getHeight() {
17 | return height;
18 | }
19 |
20 | public void setHeight(int height) {
21 | this.height = height;
22 | }
23 |
24 | @Override
25 | public double getArea() {
26 | return bottom * height;
27 | }
28 |
29 | @Override
30 | public String getName() {
31 | return "사각형";
32 | }
33 |
34 | public static void main(String[] args) {
35 |
36 | Scanner_ scanner_ = new Scanner_();
37 | Square square = new Square();
38 |
39 | System.out.println("밑변의 길이를 입력해주세요");
40 | square.setBottom(scanner_.getValue());
41 | System.out.println("높이의 길이를 입력해주세요");
42 | square.setHeight(scanner_.getValue());
43 |
44 | square.printArea();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/classTime/Inheritance/tr1/Triangle.java:
--------------------------------------------------------------------------------
1 | package com.classTime.Inheritance.tr1;
2 |
3 | public class Triangle extends Polygon {
4 |
5 | private double bottom;
6 | private double height;
7 |
8 | public double getBottom() {
9 | return bottom;
10 | }
11 |
12 | public void setBottom(double bottom) {
13 | this.bottom = bottom;
14 | }
15 |
16 | public double getHeight() {
17 | return height;
18 | }
19 |
20 | public void setHeight(double height) {
21 | this.height = height;
22 | }
23 |
24 | @Override
25 | public double getArea() {
26 | return bottom * height / 2;
27 | }
28 |
29 | @Override
30 | public String getName() {
31 | return "삼각형";
32 | }
33 |
34 |
35 | public static void main(String[] args) {
36 |
37 | Scanner_ scanner_ = new Scanner_();
38 | Triangle triangle = new Triangle();
39 |
40 | System.out.println("밑변의 길이를 입력해 주세요");
41 | triangle.setBottom(scanner_.getValue());
42 | System.out.println("높이의 길이를 입력해 주세요");
43 | triangle.setHeight(scanner_.getValue());
44 |
45 | triangle.printArea();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/classTime/SmallCalc/ScannerFuc.java:
--------------------------------------------------------------------------------
1 | package com.classTime.SmallCalc;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ScannerFuc {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | public int scan() {
10 | return scanner.nextInt();
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/com/classTime/SmallCalc/SmallCalc.java:
--------------------------------------------------------------------------------
1 | package com.classTime.SmallCalc;
2 |
3 | public class SmallCalc {
4 |
5 | private int[] values;
6 | private int arraySize;
7 |
8 | public SmallCalc (int arraySize) {
9 | this.values = new int[arraySize];
10 | this.arraySize = arraySize;
11 | }
12 |
13 | public void addNumber (int scanValue, int array) {
14 | this.values[array] = scanValue;
15 | }
16 |
17 | public void avg () {
18 | float sum = 0;
19 |
20 | for(int i = 0;i < arraySize;i ++) {
21 | sum += values[i];
22 | }
23 |
24 | System.out.println("avg is " + sum / arraySize);
25 | }
26 |
27 | public void big () {
28 | int big = values[0];
29 |
30 | for(int i = 1;i < arraySize - 1;i ++) {
31 | if (big < values[i]) {
32 | big = values[i];
33 | }
34 | }
35 |
36 | System.out.println("largest is " + big);
37 | }
38 |
39 | public void small () {
40 | int small = values[0];
41 |
42 | for (int i = 1;i < arraySize - 1;i ++) {
43 | if (small > values[i]) {
44 | small = values[i];
45 | }
46 | }
47 |
48 | System.out.println("smallest is " + small);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/com/classTime/SmallCalc/SmallCalcRun.java:
--------------------------------------------------------------------------------
1 | package com.classTime.SmallCalc;
2 |
3 | import java.util.Scanner;
4 |
5 | public class SmallCalcRun {
6 |
7 | public static void main(String[] args) {
8 |
9 | ScannerFuc scannerFuc = new ScannerFuc();
10 |
11 | int arraySize;
12 |
13 | System.out.println("입력할 숫자의 개수를 입력해 주세요");
14 | arraySize = scannerFuc.scan();
15 | System.out.println();
16 |
17 | SmallCalc calc = new SmallCalc(arraySize);
18 |
19 | for(int i = 0;i < arraySize;i ++) {
20 |
21 | System.out.println("숫자를 입력해주세요");
22 |
23 | int value = scannerFuc.scan();
24 |
25 | calc.addNumber(value, i);
26 |
27 | System.out.println();
28 | }
29 |
30 | System.out.println("1");
31 | calc.big();
32 | calc.small();
33 | calc.avg();
34 |
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/com/classTime/SmallCalcT/NumberAnalyser.java:
--------------------------------------------------------------------------------
1 | package com.classTime.SmallCalcT;
2 |
3 | import java.util.Scanner;
4 |
5 | public class NumberAnalyser {
6 |
7 | private static final int SIZE = 3;
8 |
9 | private int[] values;
10 | private int index;
11 |
12 | public NumberAnalyser() {
13 | this.values = new int[SIZE];
14 | this.index = 0;
15 | }
16 |
17 | public void setValue(int value) {
18 | if (index >= SIZE) {
19 | throw new RuntimeException("크기 초과");
20 | }
21 |
22 | this.values[index] = value;
23 | this.index ++;
24 | }
25 |
26 | public int getMinimum() {
27 | int min = values[0];
28 |
29 | for (int i = 1; i < SIZE; i++) {
30 | if (min > values[i]) {
31 | min = values[i];
32 | }
33 | }
34 |
35 | return min;
36 | }
37 |
38 | public int getMaximum() {
39 | int max = values[0];
40 |
41 | for (int i = 1; i < SIZE; i++) {
42 | if (max < values[i]) {
43 | max = values[i];
44 | }
45 | }
46 |
47 | return max;
48 | }
49 |
50 | private int getSum() {
51 | int sum = 0;
52 |
53 | for (int value : values) {
54 | sum += value;
55 | }
56 |
57 | return sum;
58 | }
59 |
60 | public double getAverage() {
61 | return (double)getSum() / (double)SIZE;
62 | }
63 |
64 | public static void main(String[] args) {
65 | NumberAnalyser analyser = new NumberAnalyser();
66 | Scanner scanner = new Scanner(System.in);
67 |
68 | for (int i = 0; i < SIZE; i ++) {
69 | System.out.println("정수를 입력하세요");
70 | int value = scanner.nextInt();
71 |
72 | analyser.setValue(value);
73 | }
74 |
75 | String result = String.format("최소값 : %d, 최대값 : %d, 평균값 : %f",
76 | analyser.getMinimum(),
77 | analyser.getMaximum(),
78 | analyser.getAverage());
79 |
80 | System.out.println(result);
81 |
82 | scanner.close();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/com/classTime/Sum.java:
--------------------------------------------------------------------------------
1 | package com.classTime;
2 |
3 | public class Sum {
4 |
5 | public static void main(String[] args) {
6 | int sum = 0;
7 |
8 | for (int i = 0; i < args.length; i ++) {
9 | int value = Integer.parseInt(args[i]);
10 |
11 | sum += value;
12 | if (i == args.length - 1) {
13 | System.out.print(value);
14 | } else {
15 | System.out.print(value + " + ");
16 | }
17 | }
18 |
19 | System.out.println(" = " + sum);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/com/classTime/abstractClass/Animal.java:
--------------------------------------------------------------------------------
1 | package com.classTime.abstractClass;
2 |
3 | public abstract class Animal {
4 |
5 | public String getName() {
6 | return "동물";
7 | }
8 |
9 | public abstract int getCountOfLegs();
10 |
11 | public static void main(String[] args) {
12 | Animal animal = new Dog();
13 |
14 | animal.getName();
15 | animal.getCountOfLegs();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/com/classTime/abstractClass/Dog.java:
--------------------------------------------------------------------------------
1 | package com.classTime.abstractClass;
2 |
3 | public class Dog extends Animal {
4 |
5 | @Override
6 | public int getCountOfLegs() {
7 | return 4;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/com/classTime/accumulator/Accumulator.java:
--------------------------------------------------------------------------------
1 | package com.classTime.accumulator;
2 |
3 | public class Accumulator {
4 |
5 | private int sum;
6 |
7 | public Accumulator() {
8 | sum = 0;
9 | }
10 |
11 | public void add(int value) {
12 | this.sum += value;
13 | }
14 |
15 | public void display() {
16 | System.out.println("누적값 : " + sum);
17 | System.out.println();
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/com/classTime/accumulator/AccumulatorRunner.java:
--------------------------------------------------------------------------------
1 | package com.classTime.accumulator;
2 |
3 | import java.util.Scanner;
4 |
5 | public class AccumulatorRunner {
6 |
7 | public static void main(String[] args) {
8 |
9 | Scanner scanner = new Scanner(System.in);
10 |
11 | Accumulator accumulator = new Accumulator();
12 |
13 | while (true) {
14 |
15 | System.out.println("정수를 입력하세요.");
16 | int value = scanner.nextInt();
17 |
18 | // if (value == -9999) 상수를 앞에둬서 실수로 assign되지 않게 한다.
19 | if (-9999 == value) {
20 | break;
21 | }
22 | accumulator.add(value);
23 | accumulator.display();
24 |
25 | }
26 |
27 | System.out.println("종료");
28 |
29 | scanner.close();
30 |
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/classTime/accumulator/ScannerStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.accumulator;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ScannerStudy {
6 |
7 | public static void main(String[] args) {
8 |
9 | Scanner sc = new Scanner(System.in);
10 |
11 | int i = sc.nextInt();
12 | float f = sc.nextFloat();
13 |
14 | System.out.println("int i : " + i);
15 | System.out.println("float f : " + f);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/com/classTime/api/GenericStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.api;
2 |
3 | import java.util.Date;
4 |
5 | public class GenericStudy {
6 |
7 | public static void main(String[] args) {
8 |
9 | MyClass class1 = new MyClass();
10 |
11 | MyClass class2 = new MyClass();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/com/classTime/api/ListStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.api;
2 |
3 | import java.util.List;
4 | import java.util.ArrayList;
5 |
6 | public class ListStudy {
7 |
8 | public static void printAll(List list) {
9 |
10 | for (int i = 0; i < list.size(); i ++) {
11 |
12 | System.out.println(i + " : " + list.get(i));
13 | }
14 | }
15 |
16 | public static void main(String[] args) {
17 |
18 | List list = new ArrayList();
19 |
20 | list.add("대소고");
21 | list.add("2학년 2반");
22 | list.add("자바 수업");
23 | list.add("수요일");
24 | printAll(list);
25 |
26 | System.out.println(" --------- ");
27 |
28 | list.add(2, "데이터베이스");
29 | list.remove(3);
30 | printAll(list);
31 |
32 | list.add(4, "이건 어때?");
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/classTime/api/MapStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.api;
2 |
3 | import java.util.Collection;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 | import java.util.Set;
7 |
8 | public class MapStudy {
9 |
10 | public static void main(String[] args) {
11 |
12 | Map map = new HashMap();
13 |
14 | map.put("419 혁명", 1960);
15 | map.put("625 전쟁", 1950);
16 | map.put("임진왜란", 1592);
17 | map.put("조선건국", 1392);
18 |
19 | int value = map.get("임진왜란"); // int (null일때 예외) Integer (null return)
20 | System.out.println(value + "\n");
21 |
22 | map.remove("임진왜란");
23 |
24 | Set keys = map.keySet();
25 | for (String key: keys) {
26 | System.out.println(key);
27 | }
28 |
29 | System.out.println("---------------");
30 |
31 | Collection values = map.values();
32 | for (Integer val : values) {
33 | System.out.println(val);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/classTime/api/MyClass.java:
--------------------------------------------------------------------------------
1 | package com.classTime.api;
2 |
3 | public class MyClass {
4 |
5 | private X age;
6 |
7 | private T name;
8 |
9 | public X getAge() {
10 | return age;
11 | }
12 |
13 | public void setAge(X age) {
14 | this.age = age;
15 | }
16 |
17 | public T getName() {
18 | return name;
19 | }
20 |
21 | public void setName(T name) {
22 | this.name = name;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/com/classTime/api/PhoneBook/Book.java:
--------------------------------------------------------------------------------
1 | package com.classTime.api.PhoneBook;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.Set;
6 |
7 | public class Book {
8 |
9 | private final Map map = new HashMap<>();
10 |
11 | public void insert (String name, String phoneNum, String address) {
12 | Data data = new Data(phoneNum, address);
13 |
14 | map.put(name, data);
15 | }
16 |
17 | public void remove (String name) {
18 | map.remove(name);
19 | }
20 |
21 | public void displayName () {
22 |
23 | System.out.println("등록된 이름은 : \n");
24 |
25 | Set names = map.keySet();
26 | for (String name: names) {
27 | System.out.println(name);
28 | }
29 | }
30 |
31 | public void display () {
32 |
33 | System.out.println("\n등록된 정보 : ");
34 |
35 | Set names = map.keySet();
36 | for (String name: names) {
37 |
38 | System.out.print(name + " : ");
39 |
40 | Data value = map.get(name);
41 | value.display();
42 | }
43 | }
44 |
45 | public static void main(String[] args) {
46 | Book book = new Book();
47 |
48 | book.insert("신중빈", "010-2395-4337", "부산광역시");
49 | book.insert("손민재", "010-1234-5678", "대구광역시");
50 | book.insert("전해윤", "010-6543-0987", "대구광역시");
51 |
52 | book.display();
53 |
54 | book.remove("전해윤");
55 |
56 | book.display();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/com/classTime/api/PhoneBook/Data.java:
--------------------------------------------------------------------------------
1 | package com.classTime.api.PhoneBook;
2 |
3 | public class Data {
4 |
5 | public String phoneNum;
6 |
7 | public String address;
8 |
9 | public Data (String phoneNum, String address) {
10 | this.phoneNum = phoneNum;
11 | this.address = address;
12 | }
13 |
14 | public void display () {
15 | System.out.println(phoneNum + ", " + address);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/com/classTime/array/ArrayStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.array;
2 |
3 | import com.classTime.Dog;
4 |
5 | import java.util.Random;
6 |
7 | public class ArrayStudy {
8 |
9 | public static void main(String[] args) {
10 |
11 | int[] array = new int[5];
12 | array[0] = 3;
13 | array[3] = 5;
14 | // array[5] = 8;
15 |
16 | System.out.println(array[1]);
17 | System.out.println("배열의 크기 : " + array.length + "\n");
18 |
19 | Random random = new Random();
20 |
21 | for (int i = 0; i < array.length;i ++) {
22 | array[i] = random.nextInt(1000);
23 | }
24 |
25 | for (int value : array) {
26 | System.out.println(value);
27 | }
28 |
29 | Dog[] dogArray = new Dog[7];
30 |
31 | System.out.println(dogArray[0]);
32 | dogArray[0] = new Dog();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/classTime/array/BestSort.java:
--------------------------------------------------------------------------------
1 | package com.classTime.array;
2 |
3 | import java.util.Arrays;
4 |
5 | public class BestSort extends Sort{
6 |
7 | @Override
8 | public void sort() {
9 | Arrays.sort(array);
10 | }
11 |
12 | public static void main(String[] args) {
13 | Sort sort = new BestSort();
14 |
15 | sort.fillValues();
16 |
17 | System.out.println(" 정렬 전");
18 | sort.printArray();
19 |
20 | long before = System.currentTimeMillis();
21 | sort.sort();
22 | long after = System.currentTimeMillis();
23 |
24 | System.out.println("\n\n 정렬 후");
25 | sort.printArray();
26 |
27 | System.out.println("\n경과 시간 : " + (double)(after - before) / 1000 + "초");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/com/classTime/array/InsertSort.java:
--------------------------------------------------------------------------------
1 | package com.classTime.array;
2 |
3 | public class InsertSort extends Sort {
4 |
5 | @Override
6 | public void sort() {
7 | for (int i = 1;i < array.length; i ++) {
8 | int key = array[i];
9 | int j;
10 |
11 | for (j = i - 1; j >= 0 && array[j] > key;j --) {
12 | array[j + 1] = array[j];
13 | }
14 |
15 | array[j + 1] = key;
16 | }
17 | }
18 |
19 | public static void main(String[] args) {
20 | Sort sort = new InsertSort();
21 |
22 | sort.fillValues();
23 |
24 | System.out.println(" 정렬 전");
25 | sort.printArray();
26 |
27 | long before = System.currentTimeMillis();
28 | sort.sort();
29 | long after = System.currentTimeMillis();
30 |
31 | System.out.println("\n\n 정렬 후");
32 | sort.printArray();
33 |
34 | System.out.println("\n경과 시간 : " + (double)(after - before) / 1000 + "초");
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/classTime/array/Queue.java:
--------------------------------------------------------------------------------
1 | package com.classTime.array;
2 |
3 | public class Queue {
4 |
5 |
6 | private int front = 0;
7 | private int rear = 0;
8 |
9 | private static final int SIZE = 100;
10 | public String[] queue = new String[SIZE];
11 |
12 | public void enqueue (String value) {
13 | queue[front ++] = value;
14 | }
15 |
16 | public void dequeue () {
17 | System.out.println(queue[rear ++] + " 제거 \n");
18 | }
19 |
20 | public void display() {
21 | for (int i = rear; i < front; i ++) {
22 | System.out.println(queue[i]);
23 | }
24 | System.out.println();
25 | }
26 |
27 | public static void main(String[] args) {
28 | Queue queue = new Queue();
29 |
30 | queue.enqueue("어벤져스");
31 | queue.enqueue("인터스텔라");
32 |
33 | queue.display();
34 | queue.dequeue();
35 | queue.display();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/classTime/array/SelectionSort.java:
--------------------------------------------------------------------------------
1 | package com.classTime.array;
2 |
3 | public class SelectionSort extends Sort {
4 |
5 | @Override
6 | public void sort() {
7 | for (int i = 0; i < array.length; i ++) {
8 | int minIndex = findMinimumIndex(i);
9 |
10 | if (i != minIndex) {
11 | swap (i, minIndex);
12 | }
13 | }
14 | }
15 |
16 | private int findMinimumIndex(int index) {
17 | int result = index;
18 |
19 | for (int i = index + 1; i < array.length; i ++) {
20 |
21 | if (array[result] > array[i]) {
22 | result = i;
23 | }
24 | }
25 |
26 | return result;
27 | }
28 |
29 | public static void main(String[] args) {
30 | Sort sort = new SelectionSort();
31 |
32 | sort.fillValues();
33 |
34 | System.out.println(" 정렬 전");
35 | sort.printArray();
36 |
37 | long before = System.currentTimeMillis();
38 | sort.sort();
39 | long after = System.currentTimeMillis();
40 |
41 | System.out.println("\n\n 정렬 후");
42 | sort.printArray();
43 |
44 | System.out.println("\n경과 시간 : " + (double)(after - before) / 1000 + "초");
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/classTime/array/Sort.java:
--------------------------------------------------------------------------------
1 | package com.classTime.array;
2 |
3 | import java.util.Random;
4 |
5 | public abstract class Sort {
6 |
7 | private static final int SIZE = 100;
8 |
9 | protected int[] array = new int[SIZE];
10 |
11 |
12 | public void fillValues() {
13 | Random random = new Random();
14 |
15 | for (int i = 0;i < array.length; i ++) {
16 | array[i] = random.nextInt(10000);
17 | }
18 | }
19 |
20 | public void printArray() {
21 | for (int i = 0;i < array.length; i ++) {
22 | System.out.println(i + " : " + array[i]);
23 | }
24 | }
25 |
26 | protected void swap (int index1,int index2) {
27 | int tmp = array[index1];
28 | array[index1] = array[index2];
29 | array[index2] = tmp;
30 | }
31 |
32 | public abstract void sort();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/com/classTime/array/Stack.java:
--------------------------------------------------------------------------------
1 | package com.classTime.array;
2 |
3 | public class Stack {
4 |
5 | private int top = 0;
6 |
7 | private static final int SIZE = 100;
8 | public String[] stack = new String[SIZE];
9 |
10 | public void push(String value) {
11 | stack[top++] = value;
12 | }
13 |
14 | public void pop() {
15 | System.out.println(stack[-- top] + " 제거 \n");
16 | }
17 |
18 | public void display() {
19 | for (int i = 0; i < top; i ++) {
20 | System.out.println(stack[i]);
21 | }
22 | System.out.println();
23 | }
24 |
25 | public static void main(String[] args) {
26 | Stack stack = new Stack();
27 |
28 | stack.push("어벤져스");
29 | stack.push("인터스텔라");
30 |
31 | stack.display();
32 | stack.pop();
33 | stack.display();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/BinarySearch.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment;
2 |
3 | import java.util.Arrays;
4 | import java.util.Random;
5 |
6 | public class BinarySearch {
7 |
8 | private static final int SIZE = 100000;
9 |
10 | private Random random = new Random();
11 |
12 | private int value;
13 |
14 | /**
15 | * 주어진 list는 오름차순으로 정렬되어 있습니다.
16 | * 주어진 list에서 주어진 value 가 저장되어 있는 위치를 찾아서 리턴하세요.
17 | * 만약 list 안에 value가 없을 경우에는 -1을 리턴하세요.
18 | *
19 | * @param value 찾아야 할 값
20 | * @return list 내부에서 value 가 저장되어 있는 배열의 index, 없으면 -1
21 | */
22 | public int findIndex(int[] list, int value) {
23 |
24 | int start = 0;
25 | int mid = 0;
26 | int end = list.length - 1;
27 |
28 | while (start <= end) {
29 |
30 | mid = (start + end) / 2;
31 |
32 | if (value > list[mid]) {
33 |
34 | start = mid + 1;
35 | } else if(list[mid] == value){
36 |
37 | return mid;
38 | } else {
39 | end = mid - 1;
40 | }
41 | }
42 |
43 | return -1;
44 | }
45 |
46 | public int[] makeSampleData() {
47 | int[] list = new int[SIZE];
48 |
49 | for (int i = 0 ; i < list.length ; i++) {
50 | list[i] = random.nextInt(SIZE);
51 | }
52 |
53 | value = list[random.nextInt(SIZE)];
54 |
55 | Arrays.sort(list);
56 |
57 | return list;
58 | }
59 |
60 | public static void main(String[] args) {
61 | BinarySearch binarySearch = new BinarySearch();
62 | int[] list = binarySearch.makeSampleData();
63 |
64 | int index = binarySearch.findIndex(list, binarySearch.value);
65 |
66 | if (index == -1) {
67 |
68 | System.out.println("찾는 값이 배열에 존재하지 않습니다");
69 | return;
70 | }
71 |
72 | System.out.println("index : " + index + " \n" + binarySearch.value + " " + list[index]);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/baseball/Baseball.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment.baseball;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | public class Baseball {
7 |
8 | private int[] arr;
9 |
10 | public Baseball() {
11 |
12 | this.arr = new int[3];
13 | setting();
14 | }
15 |
16 | public boolean check(int[] inputNum) {
17 |
18 | int strike = 0;
19 | int ball = 0;
20 | // int[] checkArr = {firstNum, secondNum, thirdNum};
21 |
22 | for (int i = 0;i < 3; i ++) {
23 | for (int j = 0;j < 3; j ++) {
24 |
25 | if (inputNum[i] == this.arr[j] && i == j) {
26 |
27 | strike ++;
28 | } else if (inputNum[i] == this.arr[j]) {
29 |
30 | ball ++;
31 | }
32 | }
33 | }
34 |
35 | if (strike == 3) {
36 |
37 | System.out.println("축하합니다. 숫자를 맞췄습니다");
38 | return false;
39 | }
40 |
41 | if (strike == 0 && ball == 0) {
42 |
43 | System.out.println("아웃");
44 | return true;
45 | }
46 |
47 | System.out.println(strike + "S" + ball + "B입니다.");
48 |
49 | return true;
50 | }
51 |
52 | private void setting() {
53 |
54 | Random rand = new Random();
55 |
56 | boolean[] check = new boolean[10];
57 |
58 | int i = 0;
59 | while (i < 3) {
60 |
61 | int newNum = rand.nextInt(10);
62 | if (check[newNum] == false) {
63 |
64 | check[newNum] = true;
65 | arr[i] = newNum;
66 | i ++;
67 | }
68 | }
69 | }
70 |
71 | public void start() {
72 |
73 | Scanner sc = new Scanner(System.in);
74 |
75 | boolean checker = true;
76 | int[] inputNum = new int[3];
77 |
78 | while (checker) {
79 |
80 | System.out.println("숫자를 맞춰보세요.");
81 |
82 | for (int i = 0; i < 3; i ++) {
83 | inputNum[i] = sc.nextInt();
84 | }
85 |
86 | checker = this.check(inputNum);
87 | }
88 | }
89 |
90 | public static void main(String[] args) {
91 |
92 | Baseball baseball = new Baseball();
93 | baseball.start();
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/newPhoneBook/NameCard.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment.newPhoneBook;
2 |
3 | public class NameCard {
4 | /**
5 | * 아이디
6 | */
7 | public int id;
8 |
9 | /**
10 | * 성명
11 | */
12 | public String name;
13 |
14 | /**
15 | * 전화 번호
16 | */
17 | public String phoneNumber;
18 |
19 | /**
20 | * 주소
21 | */
22 | public String address;
23 |
24 | public int getId() {
25 | return id;
26 | }
27 |
28 | public void setId(int id) {
29 | this.id = id;
30 | }
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 | public String getPhoneNumber() {
41 | return phoneNumber;
42 | }
43 |
44 | public void setPhoneNumber(String phoneNumber) {
45 | this.phoneNumber = phoneNumber;
46 | }
47 |
48 | public String getAddress() {
49 | return address;
50 | }
51 |
52 | public void setAddress(String address) {
53 | this.address = address;
54 | }
55 |
56 | @Override
57 | public String toString() {
58 |
59 | StringBuilder buffer = new StringBuilder();
60 | buffer.append("{");
61 | buffer.append("'id' : " + id).append(", ");
62 | buffer.append("'name' : '" + name).append("', ");
63 | buffer.append("'phoneNumber' : '" + phoneNumber).append("', ");
64 | buffer.append("'address' : '" + address);
65 | buffer.append("}");
66 |
67 | return buffer.toString();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/newPhoneBook/PhoneBook.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment.newPhoneBook;
2 |
3 | import java.util.List;
4 |
5 | public interface PhoneBook {
6 |
7 | /**
8 | * 등록된 주소록을 모두 읽어온다.
9 | * @return
10 | */
11 | public List getList();
12 |
13 | /**
14 | * 주어진 아이디를 가진 주소록을 읽어온다.
15 | *
16 | * @param id
17 | * @return
18 | */
19 | public NameCard getCard(int id);
20 |
21 | /**
22 | * 주어진 이름을 가진 주소록을 읽어온다
23 | *
24 | * @param name
25 | * @return
26 | */
27 | public NameCard getCard(String name);
28 |
29 | /**
30 | * 주소록에 주어진 데이터를 추가한다.
31 | *
32 | * @param name
33 | * @param phoneNumber
34 | * @param address
35 | * @return
36 | */
37 | public int addCard(String name, String phoneNumber, String address);
38 |
39 | /**
40 | * 주어진 아이디를 가진 주소를 삭제한다.
41 | *
42 | * @param id
43 | * @return
44 | */
45 | public boolean removeCard(int id);
46 |
47 | /**
48 | * 주소록 데이터를 변경한다.
49 | *
50 | * @param id
51 | * @param name
52 | * @param phoneNumber
53 | * @param address
54 | */
55 | public void updateCard(int id, String name, String phoneNumber, String address);
56 |
57 | /**
58 | * 등록된 주소의 개수를 되돌린다.
59 | *
60 | * @return
61 | */
62 | public int size();
63 |
64 | /**
65 | * 키워드로 주소록에서 사람을 찾는다
66 | * @param keyword
67 | * @return
68 | */
69 | public List search(String keyword);
70 |
71 | /**
72 | * 주소록을 시작한다.
73 | *
74 | * @return
75 | */
76 | public void start();
77 | }
78 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/phoneBook/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/src/com/classTime/assessment/phoneBook/.DS_Store
--------------------------------------------------------------------------------
/src/com/classTime/assessment/phoneBook/DBPhoneBook.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment.phoneBook;
2 |
3 | import java.sql.Connection;
4 | import java.sql.DriverManager;
5 | import java.sql.PreparedStatement;
6 | import java.sql.ResultSet;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class DBPhoneBook implements PhoneBook {
11 |
12 | private Connection getConnection() throws Exception {
13 |
14 | Class.forName("org.mariadb.jdbc.Driver");
15 | // return DriverManager.getConnection("jdbc:mysql://localhost/java", "root", "1234");
16 | return DriverManager.getConnection("jdbc:mariadb://211.53.209.159/dgsw_java", "dgsw_student", "1234");
17 | }
18 |
19 | private NameCard setNameCard (ResultSet rs) throws Exception{
20 |
21 | NameCard card = new NameCard();
22 |
23 | int idx = rs.getInt("id");
24 | String name = rs.getString("name");
25 | String phoneNumber = rs.getString("phone_number");
26 | String address = rs.getString("address");
27 |
28 | card.setId(idx);
29 | card.setName(name);
30 | card.setPhoneNumber(phoneNumber);
31 | card.setAddress(address);
32 |
33 | return card;
34 | }
35 |
36 | @Override
37 | public List getList() {
38 |
39 | try {
40 |
41 | Connection con = this.getConnection();
42 |
43 | String sql = "SELECT * FROM phone_book";
44 | PreparedStatement pstmt = con.prepareStatement(sql);
45 | ResultSet rs = pstmt.executeQuery();
46 |
47 | List cardList = new ArrayList();
48 |
49 | while (rs.next()) {
50 |
51 | NameCard card = this.setNameCard(rs);
52 |
53 | cardList.add(card);
54 | }
55 |
56 | rs.close();
57 | pstmt.close();
58 | con.close();
59 |
60 | return cardList;
61 | } catch (Exception e) {
62 |
63 | e.printStackTrace();
64 | }
65 |
66 | return null;
67 | }
68 |
69 | @Override
70 | public NameCard getCard(int id) {
71 |
72 | try {
73 |
74 | Connection con = this.getConnection();
75 |
76 | String sql = "SELECT * FROM phone_book WHERE id = ?";
77 | PreparedStatement pstmt = con.prepareStatement(sql);
78 | pstmt.setInt(1, id);
79 |
80 | ResultSet rs = pstmt.executeQuery();
81 |
82 | NameCard nameCard = null;
83 |
84 | if (rs.next()) {
85 |
86 | nameCard = this.setNameCard(rs);
87 | }
88 |
89 | rs.close();
90 | pstmt.close();
91 | con.close();
92 |
93 | return nameCard;
94 |
95 | } catch (Exception e) {
96 |
97 | e.printStackTrace();
98 | }
99 |
100 | return null;
101 | }
102 |
103 | @Override
104 | public NameCard getCard(String name) {
105 |
106 | try {
107 |
108 | Connection con = this.getConnection();
109 |
110 | String sql = "SELECT * FROM phone_book WHERE name = ?";
111 | PreparedStatement pstmt = con.prepareStatement(sql);
112 | pstmt.setString(1, name);
113 |
114 | ResultSet rs = pstmt.executeQuery();
115 |
116 | NameCard nameCard = null;
117 |
118 | if (rs.next()) {
119 |
120 | nameCard = this.setNameCard(rs);
121 | }
122 |
123 | rs.close();
124 | pstmt.close();
125 | con.close();
126 |
127 | return nameCard;
128 |
129 | } catch (Exception e) {
130 |
131 | e.printStackTrace();
132 | }
133 |
134 | return null;
135 | }
136 |
137 | @Override
138 | public int addCard(String name, String phoneNumber, String address) {
139 |
140 | try {
141 |
142 | Connection con = this.getConnection();
143 |
144 | StringBuilder sql = new StringBuilder();
145 |
146 | sql.append(" INSERT INTO phone_book ");
147 | sql.append(" (name, phone_number, address) ");
148 | sql.append(" VALUES ");
149 | sql.append(" (?, ?, ?) ");
150 |
151 | PreparedStatement pstmt = con.prepareStatement(sql.toString());
152 | pstmt.setString(1, name);
153 | pstmt.setString(2, phoneNumber);
154 | pstmt.setString(3, address);
155 |
156 | pstmt.executeUpdate();
157 |
158 | pstmt.close();
159 | con.close();
160 |
161 | return 1;
162 |
163 | } catch (Exception e) {
164 |
165 | e.printStackTrace();
166 | }
167 |
168 | return 0;
169 | }
170 |
171 | @Override
172 | public boolean removeCard(int id) {
173 |
174 | try {
175 |
176 | Connection con = this.getConnection();
177 |
178 | StringBuilder sql = new StringBuilder();
179 |
180 | sql.append(" DELETE FROM phone_book ");
181 | sql.append(" WHERE ");
182 | sql.append(" id = ? ");
183 |
184 | PreparedStatement pstmt = con.prepareStatement(sql.toString());
185 | pstmt.setInt(1, id);
186 |
187 | pstmt.executeUpdate();
188 |
189 | pstmt.close();
190 | con.close();
191 |
192 | return true;
193 |
194 | } catch (Exception e) {
195 |
196 | e.printStackTrace();
197 | }
198 |
199 | return false;
200 | }
201 |
202 | @Override
203 | public void updateCard(int id, String name, String phoneNumber, String address) {
204 |
205 | try {
206 |
207 | Connection con = this.getConnection();
208 |
209 | StringBuilder sql = new StringBuilder();
210 | sql.append(" UPDATE phone_book ");
211 | sql.append(" SET ");
212 | sql.append(" name = ?, ");
213 | sql.append(" phone_number = ?, ");
214 | sql.append(" address = ? ");
215 | sql.append(" WHERE id = ? ");
216 |
217 | PreparedStatement pstmt = con.prepareStatement(sql.toString());
218 | pstmt.setString(1, name);
219 | pstmt.setString(2, phoneNumber);
220 | pstmt.setString(3, address);
221 | pstmt.setInt(4, id);
222 |
223 | pstmt.executeUpdate();
224 |
225 | pstmt.close();
226 | con.close();
227 |
228 | } catch (Exception e) {
229 |
230 | e.printStackTrace();
231 | }
232 | }
233 |
234 | @Override
235 | public int size() {
236 |
237 | return this.getList().size();
238 | }
239 |
240 | }
241 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/phoneBook/FilePhoneBook.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment.phoneBook;
2 |
3 | import java.io.*;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | public class FilePhoneBook implements PhoneBook {
8 |
9 | private static final String FILE_PATH = "/Users/krung2/Documents/Github/JAVA_Class/src/com/classTime/assessment/phoneBook/";
10 | public static final String FILE_NAME = "phoneBook.dat";
11 |
12 | private File file;
13 |
14 | // 이 문자열은 무조건 바꿔주세요!!
15 | private String splitMsg = " ";
16 |
17 | public FilePhoneBook() {
18 | file = new File(FILE_PATH + FILE_NAME);
19 | }
20 |
21 |
22 | @Override
23 | public List getList() {
24 |
25 | try {
26 |
27 | List cardList = new ArrayList();
28 |
29 | BufferedReader br = new BufferedReader(new FileReader(file));
30 |
31 | String line = null;
32 | int cnt = 1;
33 | while ((line = br.readLine()) != null) {
34 |
35 | String[] cardInfo = line.split(splitMsg);
36 |
37 | NameCard nameCard = new NameCard();
38 |
39 | nameCard.setId(cnt);
40 | nameCard.setName(cardInfo[0]);
41 | nameCard.setPhoneNumber(cardInfo[1]);
42 | nameCard.setAddress(cardInfo[2]);
43 |
44 | cardList.add(nameCard);
45 | cnt ++;
46 | }
47 |
48 | br.close();
49 |
50 | return cardList;
51 |
52 | } catch (Exception e) {
53 |
54 | e.printStackTrace();
55 | }
56 |
57 | return null;
58 | }
59 |
60 | @Override
61 | public NameCard getCard(int id) {
62 |
63 | List cardList = this.getList();
64 |
65 | for (NameCard nameCard : cardList) {
66 |
67 | if (nameCard.id == id) {
68 |
69 | return nameCard;
70 | }
71 | }
72 |
73 | System.out.println("찾는 카드id는 존재하지 않습니");
74 | return null;
75 | }
76 |
77 | @Override
78 | public NameCard getCard(String name) {
79 |
80 | List cardList = this.getList();
81 |
82 | for (NameCard nameCard : cardList) {
83 |
84 | if (nameCard.name.equals(name)) {
85 |
86 | return nameCard;
87 | }
88 | }
89 |
90 | System.out.println("찾는 이름은 존재하지 않습니다");
91 | return null;
92 | }
93 |
94 | @Override
95 | public int addCard(String name, String phoneNumber, String address) {
96 |
97 | try {
98 |
99 | BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
100 |
101 | bw.write(name + splitMsg + phoneNumber + splitMsg + address +"\n");
102 | bw.close();
103 |
104 | return 1;
105 |
106 | } catch (Exception e) {
107 |
108 | e.printStackTrace();
109 | return 0;
110 | }
111 |
112 | }
113 |
114 | @Override
115 | public boolean removeCard(int id) {
116 |
117 | List cardList = this.getList();
118 |
119 | file.delete();
120 |
121 | for (NameCard nameCard: cardList) {
122 |
123 | if (nameCard.id == id) {
124 |
125 | cardList.remove(nameCard);
126 | break;
127 | }
128 | }
129 |
130 | addNameCard(cardList);
131 |
132 | return false;
133 | }
134 |
135 | @Override
136 | public void updateCard(int id, String name, String phoneNumber, String address) {
137 |
138 | List cardList = this.getList();
139 |
140 | file.delete();
141 |
142 | for (NameCard nameCard: cardList) {
143 |
144 | if (nameCard.id == id) {
145 |
146 | nameCard.setName(name);
147 | nameCard.setPhoneNumber(phoneNumber);
148 | nameCard.setAddress(address);
149 | break;
150 | }
151 | }
152 |
153 | addNameCard(cardList);
154 | }
155 |
156 | @Override
157 | public int size() {
158 |
159 | List cardList = this.getList();
160 |
161 | return cardList.size();
162 | }
163 |
164 | private void addNameCard (List cardList) {
165 |
166 | for (NameCard nameCard: cardList) {
167 |
168 | this.addCard(
169 | nameCard.getName(),
170 | nameCard.getPhoneNumber(),
171 | nameCard.getAddress()
172 | );
173 | }
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/phoneBook/NameCard.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment.phoneBook;
2 |
3 | public class NameCard {
4 | /**
5 | * 아이디
6 | */
7 | public int id;
8 |
9 | /**
10 | * 성명
11 | */
12 | public String name;
13 |
14 | /**
15 | * 전화 번호
16 | */
17 | public String phoneNumber;
18 |
19 | /**
20 | * 주소
21 | */
22 | public String address;
23 |
24 | public int getId() {
25 | return id;
26 | }
27 |
28 | public void setId(int id) {
29 | this.id = id;
30 | }
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 | public String getPhoneNumber() {
41 | return phoneNumber;
42 | }
43 |
44 | public void setPhoneNumber(String phoneNumber) {
45 | this.phoneNumber = phoneNumber;
46 | }
47 |
48 | public String getAddress() {
49 | return address;
50 | }
51 |
52 | public void setAddress(String address) {
53 | this.address = address;
54 | }
55 |
56 | @Override
57 | public String toString() {
58 |
59 | StringBuilder buffer = new StringBuilder();
60 | buffer.append("{");
61 | buffer.append("'id' : " + id).append(", ");
62 | buffer.append("'name' : '" + name).append("', ");
63 | buffer.append("'phoneNumber' : '" + phoneNumber).append("', ");
64 | buffer.append("'address' : '" + address);
65 | buffer.append("}");
66 |
67 | return buffer.toString();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/phoneBook/PhoneBook.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment.phoneBook;
2 |
3 | import java.util.List;
4 |
5 | public interface PhoneBook {
6 |
7 | /**
8 | * 등록된 주소록을 모두 읽어온다.
9 | * @return
10 | */
11 | public List getList();
12 |
13 | /**
14 | * 주어진 아이디를 가진 주소록을 읽어온다.
15 | *
16 | * @param id
17 | * @return
18 | */
19 | public NameCard getCard(int id);
20 |
21 | /**
22 | * 주어진 이름을 가진 주소록을 읽어온다
23 | *
24 | * @param name
25 | * @return
26 | */
27 | public NameCard getCard(String name);
28 |
29 | /**
30 | * 주소록에 주어진 데이터를 추가한다.
31 | *
32 | * @param name
33 | * @param phoneNumber
34 | * @param address
35 | * @return
36 | */
37 | public int addCard(String name, String phoneNumber, String address);
38 |
39 | /**
40 | * 주어진 아이디를 가진 주소를 삭제한다.
41 | *
42 | * @param id
43 | * @return
44 | */
45 | public boolean removeCard(int id);
46 |
47 | /**
48 | * 주소록 데이터를 변경한다.
49 | *
50 | * @param id
51 | * @param name
52 | * @param phoneNumber
53 | * @param address
54 | */
55 | public void updateCard(int id, String name, String phoneNumber, String address);
56 |
57 | /**
58 | * 등록된 주소의 개수를 되돌린다.
59 | *
60 | * @return
61 | */
62 | public int size();
63 | }
64 |
--------------------------------------------------------------------------------
/src/com/classTime/assessment/phoneBook/PhoneBookTest.java:
--------------------------------------------------------------------------------
1 | package com.classTime.assessment.phoneBook;
2 |
3 | import java.util.List;
4 |
5 | public class PhoneBookTest {
6 |
7 | public static void main(String[] args) {
8 |
9 | PhoneBook phoneBook = new DBPhoneBook();
10 | NameCard nameCard = null;
11 |
12 | // 네 개의 데이터를 추가하세요.
13 | phoneBook.addCard("정재봉", "010-3458-4250", "대구시 동구");
14 | phoneBook.addCard("유재석", "010-1234-5678", "서울시 강남구");
15 | phoneBook.addCard("손흥민", "010-0000-0000", "런던시 토튼햄구");
16 | phoneBook.addCard("윤여정", "010-9876-5432", "아카데미 시상식장");
17 |
18 | // 등록된 모든 연락처를 읽어와 상세 정보를 출력하세요.
19 | List cards = phoneBook.getList();
20 | System.out.println("getList() --------------------");
21 | for (NameCard card : cards) {
22 | System.out.println(card.toString());
23 | }
24 |
25 | // getName(int) 메소드를 이용해서 연락처 하나를 읽어와 상세 정보를 출력하세요.
26 | nameCard = phoneBook.getCard(cards.get(1).getId());
27 | System.out.println("getCard(int) --------------------");
28 | System.out.println(nameCard.toString());
29 |
30 | // getName(String) 메소드를 이용해서 연락처 하나를 읽어와 상세 정보를 출력하세요.
31 | nameCard = phoneBook.getCard(cards.get(2).getName());
32 | System.out.println("getCard(String) --------------------");
33 | System.out.println(nameCard.toString());
34 |
35 | // 세번째로 등록된 연락처를 삭제하세요.
36 | phoneBook.removeCard(cards.get(2).getId());
37 | System.out.println("removeCard() --------------------");
38 | System.out.println("size : " + phoneBook.size());
39 |
40 | // 두번째로 등록된 연락처의 정보를 임의로 변경하세요.
41 | phoneBook.updateCard(cards.get(1).getId(), "유산슬", "010-5555-6666", "합정역 5번 출구");
42 | System.out.println("updateCard() --------------------");
43 | nameCard = phoneBook.getCard(cards.get(1).getId());
44 | System.out.println(nameCard.toString());
45 | }
46 | }
--------------------------------------------------------------------------------
/src/com/classTime/assessment/phoneBook/phoneBook.dat:
--------------------------------------------------------------------------------
1 | 정재봉 010-3458-4250 대구시 동구
2 | 유산슬 010-5555-6666 합정역 5번 출구
3 | 윤여정 010-9876-5432 아카데미 시상식장
4 |
--------------------------------------------------------------------------------
/src/com/classTime/file/FileCopy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.file;
2 |
3 | import java.io.*;
4 |
5 | public class FileCopy {
6 |
7 | String baseURL = "/Users/krung2/Desktop/java/file/asdf.jpeg";
8 | String baseImage = "/Users/krung2/Desktop/java/file/123.jpeg";
9 |
10 | public void copy(String src, String target)
11 | throws Exception {
12 | File srcFile = new File(src);
13 | File targetFile = new File(target);
14 |
15 | InputStream is = new FileInputStream(srcFile);
16 | OutputStream os = new FileOutputStream(targetFile);
17 |
18 | while (is.available() > 0) {
19 | int value = is.read();
20 | os.write(value);
21 | }
22 |
23 | is.close();
24 | os.close();
25 | }
26 |
27 | public static void main(String[] args) {
28 | FileCopy copy = new FileCopy();
29 |
30 | try {
31 | copy.copy(copy.baseImage, copy.baseURL);
32 | } catch (Exception e) {
33 | e.printStackTrace();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/classTime/file/FileFinder.java:
--------------------------------------------------------------------------------
1 | package com.classTime.file;
2 |
3 | import java.io.File;
4 | import java.util.regex.Pattern;
5 |
6 | public class FileFinder {
7 |
8 | public void showFile (String dirpath) throws Exception {
9 | File dir = new File(dirpath);
10 | File[] files = dir.listFiles();
11 |
12 | String pattern = "^\\\\S+.(?i)(ts)$";
13 |
14 | for (File file: files) {
15 | if (file.isDirectory()) {
16 | showFile(file.getPath());
17 | } else {
18 | if (Pattern.matches(pattern, file.getName())) {
19 | System.out.println(file);
20 | }
21 | }
22 | }
23 | }
24 |
25 | public static void main(String[] args) {
26 |
27 | FileFinder fileFinder = new FileFinder();
28 | String baseURL = "/Users/krung2/Desktop/java/file/";
29 |
30 | try {
31 | fileFinder.showFile("/Users");
32 | } catch (Exception e) {
33 | e.printStackTrace();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/classTime/file/FileImage.java:
--------------------------------------------------------------------------------
1 | package com.classTime.file;
2 |
3 | public class FileImage {
4 |
5 | String baseURL = "/Users/krung2/Desktop/java/file/";
6 | }
7 |
--------------------------------------------------------------------------------
/src/com/classTime/file/FileReader.java:
--------------------------------------------------------------------------------
1 | package com.classTime.file;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.InputStream;
6 |
7 | public class FileReader {
8 |
9 | public static void main(String[] args) {
10 |
11 | String baseURL = "/Users/krung2/Desktop/java/file/";
12 |
13 | try {
14 |
15 | File file = new File(baseURL + "abc.txt");
16 | InputStream is = new FileInputStream(file);
17 |
18 | while (is.available() > 0) {
19 | int value = is.read();
20 | char ch = (char)value;
21 | System.out.println(value + " " + ch);
22 | }
23 |
24 | is.close();
25 |
26 | } catch (Exception e) {
27 | e.printStackTrace();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/com/classTime/file/FileStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.file;
2 |
3 | import java.io.File;
4 | import java.util.Date;
5 |
6 | public class FileStudy {
7 |
8 | public static void main(String[] args) {
9 |
10 | String baseURL = "/Users/krung2/Desktop/java/file/";
11 |
12 | try {
13 | File file = new File(baseURL + "abc.txt");
14 |
15 | boolean exist = file.exists();
16 | System.out.println("exist : " + exist);
17 |
18 | file = new File(baseURL + "가나다.txt");
19 | boolean result = file.createNewFile();
20 | System.out.println("createNewFile : " + result);
21 |
22 | System.out.println("deleteFile : " + file.delete() + "\n");
23 |
24 | File dir = new File(baseURL + "sub");
25 | result = dir.mkdir();
26 | System.out.println("mkdir : " + result);
27 | System.out.println("rm : " + dir.delete() + "\n");
28 |
29 | File hello = new File(baseURL + "hello");
30 | System.out.println("isFile : " + hello.isFile());
31 | System.out.println("isDirectory : " + hello.isDirectory());
32 |
33 | System.out.println("getName : " + hello.getName());
34 | System.out.println("getName : " + hello.getAbsolutePath());
35 | System.out.println("length : " + hello.length());
36 | System.out.println("lastModified : " + hello.lastModified());
37 |
38 | long lastModified = hello.lastModified();
39 | Date date = new Date(lastModified);
40 | System.out.println("lastModified : " + date.toString());
41 |
42 | String parent = hello.getParent();
43 | System.out.println("getParent : " + parent + "\n");
44 |
45 | System.out.println("---------- list ----------");
46 |
47 | dir = new File(baseURL);
48 | File[] list = dir.listFiles();
49 |
50 | for (File file1: list) {
51 | System.out.println(file1.getName());
52 | }
53 |
54 | File renamed = new File(baseURL + "hello");
55 | hello.renameTo(renamed);
56 |
57 | } catch (Exception e) {
58 |
59 | e.printStackTrace();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/classTime/file/FileWrite.java:
--------------------------------------------------------------------------------
1 | package com.classTime.file;
2 |
3 | import java.io.File;
4 | import java.io.FileOutputStream;
5 | import java.io.OutputStream;
6 |
7 | public class FileWrite {
8 |
9 | public static void main(String[] args) {
10 |
11 | String baseURL = "/Users/krung2/Desktop/java/file/";
12 |
13 | try {
14 | File file = new File(baseURL + "zzz.txt");
15 | OutputStream os = new FileOutputStream(file);
16 |
17 | os.write(49);
18 | os.write(65);
19 | os.write(105);
20 |
21 | os.close();
22 |
23 | } catch (Exception e) {
24 | e.printStackTrace();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/com/classTime/file/TextFile.java:
--------------------------------------------------------------------------------
1 | package com.classTime.file;
2 |
3 | import java.io.*;
4 | import java.io.FileReader;
5 |
6 | public class TextFile {
7 |
8 | public String read (String filePath) throws Exception {
9 |
10 | File file = new File(filePath);
11 | java.io.FileReader fileReader = new FileReader(file);
12 | BufferedReader reader = new BufferedReader(fileReader);
13 |
14 | String result = "";
15 | while (true) {
16 |
17 | String line = reader.readLine();
18 |
19 | if (line == null) {
20 | break ;
21 | }
22 |
23 | result += line + "\n";
24 | }
25 |
26 | reader.close();
27 |
28 | return result;
29 | }
30 |
31 | public void write(String filePath, String content) throws Exception {
32 |
33 | File file = new File(filePath);
34 | FileWriter fileWriter = new FileWriter(file);
35 | BufferedWriter writer = new BufferedWriter(fileWriter);
36 |
37 | writer.write(content);
38 |
39 | writer.close();
40 | }
41 |
42 | public static void main(String[] args) {
43 |
44 | try {
45 |
46 | String baseURL = "/Users/krung2/Desktop/java/file/hello";
47 |
48 | TextFile textFile = new TextFile();
49 |
50 | String contents = textFile.read(baseURL);
51 | System.out.println(contents);
52 |
53 |
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/com/classTime/file/commandLine/Command.java:
--------------------------------------------------------------------------------
1 | package com.classTime.file.commandLine;
2 |
3 | import java.io.File;
4 | import java.rmi.server.ExportException;
5 | import java.util.Scanner;
6 |
7 | public class Command {
8 |
9 | private String dirpath = "/Users/krung2/";
10 |
11 | public void nowDir () throws Exception {
12 |
13 | System.out.print(this.dirpath + " > ");
14 | }
15 |
16 | public void ls () throws Exception {
17 | File dir = new File(this.dirpath);
18 | File[] files = dir.listFiles();
19 |
20 | for (File file: files) {
21 | System.out.println(file.getName());
22 | }
23 | }
24 |
25 | public void cd (String path) throws Exception{
26 |
27 | if (path.equals("..")) {
28 |
29 | this.dirpath = this.dirpath.substring(0, this.dirpath.lastIndexOf("/"));
30 | return;
31 | }
32 |
33 | String newPath = this.dirpath + path + "/";
34 | File dir = new File(newPath);
35 |
36 | if (dir.isDirectory()) {
37 |
38 | this.dirpath = newPath;
39 | } else {
40 |
41 | System.out.println("없는 경로입니다");
42 | }
43 | }
44 |
45 | public void mkdir (String path) throws Exception {
46 |
47 | File dir = new File(this.dirpath + path);
48 |
49 | if (dir.exists()) {
50 |
51 | System.out.println("이미 같은 이름의 폴더가 있습니다");
52 | } else {
53 |
54 | dir.mkdir();
55 | }
56 | }
57 |
58 | public void rmdir (String path) throws Exception {
59 |
60 | File dir = new File(this.dirpath + path);
61 |
62 | if (dir.exists()) {
63 |
64 | dir.delete();
65 | } else {
66 |
67 | System.out.println("없는 폴더입니다");
68 | }
69 | }
70 |
71 | public void touch (String fileName) throws Exception {
72 |
73 | File file = new File(this.dirpath + fileName);
74 |
75 | if (file.exists()) {
76 |
77 | System.out.println("이미 있는 파일입니다");
78 | } else {
79 |
80 | file.createNewFile();
81 | }
82 | }
83 |
84 | public void rm (String fileName) throws Exception {
85 |
86 | File file = new File(this.dirpath + fileName);
87 |
88 | if (file.exists()) {
89 |
90 | file.delete();
91 | } else {
92 |
93 | System.out.println("없는 파일입니다");
94 | }
95 | }
96 |
97 | public static void main(String[] args) {
98 |
99 | Command commandLine = new Command();
100 | Scanner scanner = new Scanner(System.in);
101 |
102 | try {
103 |
104 | while (true) {
105 |
106 | commandLine.nowDir();
107 |
108 | String command = scanner.nextLine();
109 | String[] commandSplit = command.split(" ");
110 |
111 | switch (commandSplit[0]) {
112 | case "ls":
113 | commandLine.ls();
114 | break;
115 | case "cd":
116 | commandLine.cd(commandSplit[1]);
117 | break;
118 | case "mkdir":
119 | commandLine.mkdir(commandSplit[1]);
120 | break;
121 | case "rmdir":
122 | commandLine.rmdir(commandSplit[1]);
123 | break;
124 | case "touch":
125 | commandLine.touch(commandSplit[1]);
126 | break;
127 | case "rm":
128 | commandLine.rm(commandSplit[1]);
129 | break;
130 | default :
131 | break;
132 | }
133 |
134 | }
135 | } catch (Exception e) {
136 |
137 | e.printStackTrace();
138 | }
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/com/classTime/interface1/Animal.java:
--------------------------------------------------------------------------------
1 | package com.classTime.interface1;
2 |
3 | public interface Animal {
4 |
5 | public void eat();
6 |
7 | public void makeSound();
8 | }
--------------------------------------------------------------------------------
/src/com/classTime/interface1/Cat.java:
--------------------------------------------------------------------------------
1 | package com.classTime.interface1;
2 |
3 | public class Cat implements Animal {
4 |
5 | @Override
6 | public void eat() {
7 |
8 | System.out.println("생선을 먹습니다.");
9 | }
10 |
11 | @Override
12 | public void makeSound() {
13 |
14 | System.out.println("야옹");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/com/classTime/interface1/Doer.java:
--------------------------------------------------------------------------------
1 | package com.classTime.interface1;
2 |
3 | public class Doer {
4 |
5 | public static void main(String[] args) {
6 |
7 | Animal cat = new Cat();
8 | Animal dog = new Dog();
9 |
10 | cat.eat();
11 | dog.eat();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/com/classTime/interface1/Dog.java:
--------------------------------------------------------------------------------
1 | package com.classTime.interface1;
2 |
3 | public class Dog implements Animal {
4 |
5 | @Override
6 | public void eat () {
7 | System.out.println("사료");
8 | }
9 |
10 | @Override
11 | public void makeSound () {
12 | System.out.println("멍멍");
13 | }
14 | }
--------------------------------------------------------------------------------
/src/com/classTime/jdbc/Jdbc.java:
--------------------------------------------------------------------------------
1 | package com.classTime.jdbc;
2 |
3 | public class Jdbc {
4 |
5 | public static void main(String[] args) {
6 |
7 | try {
8 |
9 | Class.forName("org.mariadb.jdbc.Driver");
10 | System.out.println("Success!");
11 | } catch (Exception e) {
12 |
13 | e.printStackTrace();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/com/classTime/jdbc/JdbcStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.jdbc;
2 |
3 | import javax.naming.Name;
4 | import java.lang.constant.Constable;
5 | import java.sql.Connection;
6 | import java.sql.DriverManager;
7 | import java.sql.PreparedStatement;
8 | import java.sql.ResultSet;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class JdbcStudy {
13 |
14 | private Connection getConnection() throws Exception {
15 |
16 | Class.forName("org.mariadb.jdbc.Driver");
17 | return DriverManager.getConnection("jdbc:mariadb://211.53.209.159/dgsw_java", "dgsw_student", "1234");
18 | }
19 |
20 | private NameCard setNameCard (ResultSet rs) throws Exception{
21 |
22 | NameCard card = new NameCard();
23 |
24 | int idx = rs.getInt("id");
25 | String name = rs.getString("name");
26 | String phoneNumber = rs.getString("phone_number");
27 | String address = rs.getString("address");
28 |
29 | card.setId(idx);
30 | card.setName(name);
31 | card.setPhoneNumber(phoneNumber);
32 | card.setAddress(address);
33 |
34 | return card;
35 | }
36 |
37 | public NameCard get(int id) throws Exception {
38 |
39 | Connection con = this.getConnection();
40 |
41 | String sql = "SELECT * FROM phone_book WHERE id = ? ";
42 | PreparedStatement pstmt = con.prepareStatement(sql);
43 | pstmt.setInt(1, id);
44 | ResultSet rs = pstmt.executeQuery();
45 |
46 | NameCard nameCard = null;
47 | if (rs.next()) {
48 |
49 | nameCard = this.setNameCard(rs);
50 | }
51 |
52 | rs.close();
53 | pstmt.close();
54 | con.close();
55 |
56 | return nameCard;
57 | }
58 |
59 | public NameCard get(String name) throws Exception {
60 |
61 | Connection con = this.getConnection();
62 |
63 | String sql = "SELECT * FROM phone_book WHERE name= ?";
64 | PreparedStatement pstmt = con.prepareStatement(sql);
65 | pstmt.setString(1, name);
66 | ResultSet rs = pstmt.executeQuery();
67 |
68 | NameCard nameCard = null;
69 | if (rs.next()) {
70 |
71 | nameCard = this.setNameCard(rs);
72 | }
73 |
74 | rs.close();
75 | pstmt.close();
76 | con.close();
77 |
78 | return nameCard;
79 | }
80 |
81 | public List getList() throws Exception {
82 |
83 | Connection con = this.getConnection();
84 |
85 | String sql = "SELECT * FROM phone_book";
86 | PreparedStatement pstmt = con.prepareStatement(sql);
87 | ResultSet rs = pstmt.executeQuery();
88 |
89 | List cardList = new ArrayList();
90 | while (rs.next()){
91 |
92 | NameCard nameCard = this.setNameCard(rs);
93 |
94 | cardList.add(nameCard);
95 | }
96 |
97 | rs.close();
98 | pstmt.close();
99 | con.close();
100 |
101 | return cardList;
102 | }
103 |
104 | public void insert(String name, String phoneNumber, String address) throws Exception {
105 |
106 | Connection con = this.getConnection();
107 |
108 | StringBuilder sql = new StringBuilder();
109 |
110 | sql.append("INSERT INTO phone_book ");
111 | sql.append(" (name, phone_number, address) ");
112 | sql.append("VALUES ");
113 | sql.append(" (?, ?, ?) ");
114 |
115 | PreparedStatement pstmt = con.prepareStatement(sql.toString());
116 | pstmt.setString(1, name);
117 | pstmt.setString(2, phoneNumber);
118 | pstmt.setString(3, address);
119 |
120 | pstmt.executeUpdate();
121 |
122 | pstmt.close();
123 | con.close();
124 | }
125 |
126 | public void update (int id, String name, String phoneNumber, String address) throws Exception {
127 |
128 | Connection con = this.getConnection();
129 |
130 | StringBuilder sql = new StringBuilder();
131 | sql.append("UPDATE phone_book SET ");
132 | sql.append(" name = ?, ");
133 | sql.append(" phone_number = ?, ");
134 | sql.append(" address = ? ");
135 | sql.append(" WHERE id = ? ");
136 |
137 | PreparedStatement pstmt = con.prepareStatement(sql.toString());
138 | pstmt.setString(1, name);
139 | pstmt.setString(2, phoneNumber);
140 | pstmt.setString(3, address);
141 | pstmt.setInt(4, id);
142 |
143 | pstmt.executeUpdate();
144 |
145 | pstmt.close();
146 | con.close();
147 | }
148 |
149 | public void delete (int id) throws Exception {
150 |
151 | Connection con = this.getConnection();
152 |
153 | StringBuilder sql = new StringBuilder();
154 | sql.append("DELETE FROM phone_book ");
155 | sql.append(" WHERE id=?");
156 |
157 | PreparedStatement pstmt = con.prepareStatement(sql.toString());
158 | pstmt.setInt(1, id);
159 |
160 | pstmt.executeUpdate();
161 |
162 | pstmt.close();
163 | con.close();
164 | }
165 |
166 | public static void main(String[] args) {
167 |
168 | try {
169 |
170 | JdbcStudy jdbcStudy = new JdbcStudy();
171 | NameCard card = jdbcStudy.get(30);
172 | NameCard nameCard = jdbcStudy.get("사승은");
173 | List cardList = jdbcStudy.getList();
174 |
175 | if (card == null) {
176 |
177 | System.out.println("데이터가 존재하지 않습니다");
178 | return;
179 | }
180 |
181 | System.out.println(
182 | card.getId() + " " +
183 | card.getName() + " " +
184 | card.getPhoneNumber() + " " +
185 | card.getAddress() + " "
186 | );
187 |
188 | if (nameCard == null) {
189 |
190 | System.out.println("데이터가 존재하지 않습니다");
191 | return;
192 | }
193 |
194 | System.out.println(
195 | nameCard.getId() + " " +
196 | nameCard.getName() + " " +
197 | nameCard.getPhoneNumber() + " " +
198 | nameCard.getAddress() + " "
199 | );
200 |
201 | for (NameCard card1 : cardList) {
202 |
203 | System.out.println(
204 | card1.getId() + " " +
205 | card1.getName() + " " +
206 | card1.getPhoneNumber() + " " +
207 | card1.getAddress() + " "
208 | );
209 | }
210 |
211 | // jdbcStudy.insert("신중빈", "010-1234-5678", "투르크메니스탄");
212 | // jdbcStudy.update(55, "윤석현", "010-123-4533", "키르기스스탄");
213 | jdbcStudy.delete(51);
214 | } catch (Exception e) {
215 | e.printStackTrace();
216 | }
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/src/com/classTime/jdbc/NameCard.java:
--------------------------------------------------------------------------------
1 | package com.classTime.jdbc;
2 |
3 | public class NameCard {
4 |
5 | private int id;
6 |
7 | private String name;
8 |
9 | private String phoneNumber;
10 |
11 | private String address;
12 |
13 | public int getId() {
14 | return id;
15 | }
16 |
17 | public void setId(int id) {
18 | this.id = id;
19 | }
20 |
21 | public String getName() {
22 | return name;
23 | }
24 |
25 | public void setName(String name) {
26 | this.name = name;
27 | }
28 |
29 | public String getPhoneNumber() {
30 | return phoneNumber;
31 | }
32 |
33 | public void setPhoneNumber(String phoneNumber) {
34 | this.phoneNumber = phoneNumber;
35 | }
36 |
37 | public String getAddress() {
38 | return address;
39 | }
40 |
41 | public void setAddress(String address) {
42 | this.address = address;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/com/classTime/tryCatch/MyList.java:
--------------------------------------------------------------------------------
1 | package com.classTime.tryCatch;
2 |
3 | public class MyList {
4 |
5 | private Node head;
6 |
7 | public void insert (String value) {
8 |
9 | Node newNode = new Node();
10 | newNode.setData(value);
11 |
12 | if (head == null) {
13 |
14 | head = newNode;
15 | } else {
16 |
17 | Node pointer = head;
18 | while (true) {
19 |
20 | if (pointer.getNext() == null) {
21 |
22 | pointer.setNext(newNode);
23 | break;
24 | } else {
25 |
26 | pointer = pointer.getNext();
27 | }
28 | }
29 | }
30 | }
31 |
32 | public Node getNode (int index) {
33 |
34 | Node node = head;
35 |
36 | if (node == null || index < 0) {
37 |
38 | throw new ArrayIndexOutOfBoundsException();
39 | }
40 |
41 |
42 | for (int i = 0;i < index; i ++) {
43 |
44 | node = node.getNext();
45 | if (node == null) {
46 |
47 | throw new ArrayIndexOutOfBoundsException();
48 | }
49 | }
50 |
51 | return node;
52 | }
53 |
54 | public String read (int index) {
55 |
56 | Node node = this.getNode(index);
57 |
58 | return node.getData();
59 | }
60 |
61 | public void delete (int index) {
62 |
63 | if (index > 0) {
64 |
65 | Node prevNode = getNode(index - 1);
66 | Node node = prevNode.getNext();
67 | if (node == null) {
68 |
69 | prevNode.setNext(null);
70 | } else {
71 |
72 | prevNode.setNext(node.getNext());
73 | }
74 | } else {
75 | throw new ArrayIndexOutOfBoundsException();
76 | }
77 | }
78 |
79 | public int length () {
80 |
81 | Node pointer = head;
82 | int count = 0;
83 |
84 | while (pointer != null) {
85 | count ++;
86 | pointer = pointer.getNext();
87 | }
88 |
89 | return count;
90 | }
91 |
92 | public static void main(String[] args) {
93 | MyList list = new MyList();
94 |
95 | System.out.println("리스트의 길이 : " + list.length());
96 |
97 | list.insert("자바");
98 | list.insert("네트워크");
99 | list.insert("데이터베이스");
100 |
101 | System.out.println("리스트의 길이 : " + list.length());
102 | System.out.println(list.read(1));
103 |
104 | list.delete(2);
105 |
106 | System.out.println("리스트의 길이 : " + list.length());
107 | System.out.println(list.read(2)); // ArrayIndexOutOfBoundsException 발생
108 | System.out.println(list.read(-1)); // ArrayIndexOutOfBoundsException 발생
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/com/classTime/tryCatch/Node.java:
--------------------------------------------------------------------------------
1 | package com.classTime.tryCatch;
2 |
3 | public class Node {
4 |
5 | public String getData() {
6 | return data;
7 | }
8 |
9 | public void setData(String data) {
10 | this.data = data;
11 | }
12 |
13 | public Node getNext() {
14 | return next;
15 | }
16 |
17 | public void setNext(Node next) {
18 | this.next = next;
19 | }
20 |
21 | private String data;
22 | private Node next;
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/classTime/tryCatch/TryStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.tryCatch;
2 |
3 | import java.io.*;
4 | import java.util.InputMismatchException;
5 | import java.util.Scanner;
6 |
7 | public class TryStudy {
8 |
9 | public static int divide() {
10 |
11 | Scanner scanner = new Scanner(System.in);
12 |
13 | try {
14 | System.out.println(" 두 정수를 입력하세요.");
15 | int value1 = scanner.nextInt();
16 | int value2 = scanner.nextInt();
17 |
18 | String printFormat = String.format("%d / %d = %d",
19 | value1, value2, (value1 / value2));
20 |
21 | System.out.println(printFormat);
22 |
23 | return value1 / value2;
24 | } catch (ArithmeticException e) {
25 |
26 | System.out.println("0으로 나눌 수 없습니다.");
27 | e.printStackTrace();;
28 | } catch (InputMismatchException e) {
29 |
30 | System.out.println("정수를 입력하세요");
31 | e.printStackTrace();
32 | } catch (Exception err) {
33 |
34 | System.out.println("잘못된 입력입니다.");
35 | err.printStackTrace();
36 | } finally {
37 |
38 | scanner.close();
39 | }
40 |
41 | throw new RuntimeException();
42 | }
43 |
44 | public static void readFile()
45 | throws FileNotFoundException, IOException {
46 |
47 | try {
48 | File file = new File("/Users/krung2/Documents/Document/JavaClass/a.txt");
49 |
50 | FileReader fileReader = new FileReader(file);
51 | BufferedReader reader = new BufferedReader(fileReader);
52 |
53 | String firstLine = reader.readLine();
54 | System.out.println(firstLine);
55 |
56 | reader.close();
57 | } catch (FileNotFoundException err) {
58 |
59 |
60 | } catch (IOException e) {
61 |
62 |
63 | }
64 | }
65 |
66 | public static void method1() throws Exception {
67 |
68 | throw new Exception("샘플 예외");
69 | }
70 |
71 | public static void method2() throws RuntimeException {
72 |
73 | throw new RuntimeException();
74 | }
75 |
76 | public static void main(String[] args) {
77 | divide();
78 |
79 | // method1();
80 | method2();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/com/classTime/variable/CharStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.variable;
2 |
3 | public class CharStudy {
4 |
5 | public static void main(String[] args) {
6 |
7 | char a = 65;
8 | char b = 'a';
9 | char d = '가';
10 |
11 | System.out.println(a);
12 | System.out.println(b + " " + (int)b);
13 | System.out.println(d + " " + (int)d);
14 |
15 | for (char i = '가'; i < '나'; i ++) {
16 | System.out.println(i + " " + (int)i);
17 | }
18 |
19 | System.out.println("지원되는 한글의 개수 : " + ('힣' -'가' + 1));
20 |
21 | char hanja = '天';
22 |
23 | System.out.println(hanja + " " + (int) hanja);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/com/classTime/variable/DoubleStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.variable;
2 |
3 | public class DoubleStudy {
4 |
5 | public static void main(String[] args) {
6 |
7 | double doubleValue = 3.1415926;
8 | float floatValue = 3.1415926F;
9 |
10 | System.err.println(doubleValue);
11 | System.err.println(floatValue);
12 |
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/com/classTime/variable/Hex.java:
--------------------------------------------------------------------------------
1 | package com.classTime.variable;
2 |
3 | import java.util.Scanner;
4 |
5 | public class Hex {
6 |
7 | public static void main(String[] args) {
8 |
9 | Scanner scanner = new Scanner(System.in);
10 | int intValue = scanner.nextInt();
11 |
12 | String hex = convertToHexStringT(intValue);
13 | System.out.println(intValue + " -> " + hex);
14 |
15 | scanner.close();
16 | }
17 |
18 | private static String convertToHexString (int value) {
19 | String result = "";
20 |
21 | int divValue;
22 |
23 | while (value != 0) {
24 | divValue = value % 16;
25 | value /= 16;
26 |
27 | switch (divValue) {
28 | case 10:
29 | result = "A" + result;
30 | case 11:
31 | result = "B" + result;
32 | break;
33 | case 12:
34 | result = "C" + result;
35 | break;
36 | case 13:
37 | result = "D" + result;
38 | break;
39 | case 14:
40 | result = "E" + result;
41 | break;
42 | case 15:
43 | result = "F" + result;
44 | break;
45 | default:
46 | result = divValue + result;
47 | }
48 | }
49 |
50 | return result;
51 | }
52 |
53 | private static String convertToHexStringCase (int value) {
54 | switch (value) {
55 | case 10:
56 | return "A";
57 | case 11:
58 | return "B";
59 | case 12:
60 | return "C";
61 | case 13:
62 | return "D";
63 | case 14:
64 | return "E";
65 | case 15:
66 | return "F";
67 | default:
68 | return value + "";
69 | }
70 | }
71 |
72 | private static String convertToHexStringT (int value) {
73 |
74 | String result = "";
75 |
76 | while (value > 0) {
77 | int remainder = value % 16;
78 | String char1 = convertToHexStringCase(remainder);
79 | result = char1 + result;
80 |
81 | value /= 16;
82 | }
83 |
84 | return result;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/com/classTime/variable/IntegerStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.variable;
2 |
3 | public class IntegerStudy {
4 |
5 | public static void main(String[] args) {
6 |
7 | byte byteValue; // 1 바이트
8 | short shortValue; // 2 바이트
9 | int intValue; // 4 바이트
10 | long longValue; // 8 바이트
11 | char charValue; // 2 바이트
12 |
13 | System.out.println("Byte : " + Byte.BYTES);
14 | System.out.println("Short : " + Short.BYTES);
15 | System.out.println("Integer : " + Integer.BYTES);
16 | System.out.println("Long : " + Long.BYTES);
17 | System.out.println("Char : " + Character.BYTES);
18 |
19 | System.out.println();
20 |
21 | System.out.println("Byte Range : " + Byte.MIN_VALUE + " ~ " + Byte.MAX_VALUE);
22 | System.out.println("Short Range : " + Short.MIN_VALUE + " ~ " + Short.MAX_VALUE);
23 | System.out.println("Integer Range : " + Integer.MIN_VALUE + " ~ " + Integer.MAX_VALUE);
24 | System.out.println("Long Range : " + Long.MIN_VALUE + " ~ " + Long.MAX_VALUE);
25 | System.out.println("Char Range : " + Character.MIN_VALUE + " ~ " + Character.MAX_VALUE);
26 |
27 | System.out.println();
28 |
29 | byteValue = (byte)128;
30 | System.out.println("byteValue : " + byteValue);
31 | intValue = 123456780;
32 | longValue = 1234567890000L;
33 |
34 | intValue = 0xFF;
35 | byteValue = 0b1001011;
36 | shortValue = 0232;
37 | System.out.println(intValue);
38 | System.out.println(byteValue);
39 | System.out.println(shortValue);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/com/classTime/variable/VariableStudy.java:
--------------------------------------------------------------------------------
1 | package com.classTime.variable;
2 |
3 | public class VariableStudy {
4 |
5 |
6 | static String name;
7 |
8 | public void method1 (String param) {
9 | int local = 3;
10 |
11 | if (3 == local) {
12 | int a = 1;
13 | } else {
14 | int a = 2;
15 | }
16 |
17 | int a = 1;
18 | }
19 |
20 | public void method2 (String param) {
21 | int local = 5;
22 | }
23 |
24 | public static void main(String[] args) {
25 | VariableStudy study1 = new VariableStudy();
26 | VariableStudy study2 = new VariableStudy();
27 |
28 | VariableStudy.name = "홍길동";
29 | study2.name = "이순신";
30 |
31 | System.out.println(study1.name);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/nio/FileStudy.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.nio;
2 |
3 | import java.nio.file.*;
4 | import java.util.List;
5 |
6 | public class FileStudy {
7 |
8 | public static void studyPath() throws Exception {
9 | Path path = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile/hello.txt");
10 | path = Paths.get("/Users", "krung2", "Documents", "Github", "JAVA_Class", "src", "kr", "hs", "dgsw", "javaClass", "nio", "studyFile", "hello.txt");
11 |
12 | System.out.println(String.format("파일이름 : %s", path.getFileName()));
13 | System.out.println(String.format("부모 디렉토리 : %s", path.getParent()));
14 | System.out.println(String.format("중첩 경로 수 : %s", path.getNameCount()));
15 |
16 | System.out.println(String.format("디렉토리 여부 : %s", Files.isDirectory(path)));
17 | System.out.println(String.format("파일 여부 : %s", Files.isRegularFile(path)));
18 | System.out.println(String.format("마지막 수정 시간 : %s", Files.getLastModifiedTime(path)));
19 | System.out.println(String.format("파일 크기 : %s", Files.size(path)));
20 | System.out.println(String.format("소유자 : %s", Files.getOwner(path)));
21 | System.out.println(String.format("숨김 여부 : %s", Files.isHidden(path)));
22 | System.out.println(String.format("읽기 가능 여부 : %s", Files.isReadable(path)));
23 | System.out.println(String.format("쓰기 가능 여부 : %s", Files.isWritable(path)));
24 | }
25 |
26 | public static void studyFileManagement() throws Exception {
27 | System.out.println("파일/디렉토리 생성 삭제 공부");
28 |
29 | Path dirPath = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile/new");
30 | Path filePath = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile/new/new.txt");
31 |
32 | if (Files.notExists(dirPath)) {
33 | Files.createDirectories(dirPath);
34 | }
35 |
36 | if (Files.notExists(filePath)) {
37 | Files.createFile(filePath);
38 | }
39 |
40 | Path parentPath = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile");
41 | DirectoryStream directoryStream =
42 | Files.newDirectoryStream(parentPath);
43 |
44 | for (Path path: directoryStream) {
45 | if (Files.isDirectory(path)) {
46 | System.out.println(String.format("디렉토리 : %s", path.getFileName()));
47 | continue;
48 | }
49 | System.out.println(String.format("파일 : %s (%d)", path.getFileName(), Files.size(path)));
50 | }
51 | }
52 |
53 | public static void studyWatchService () throws Exception {
54 | System.out.println("Watch Service 공부");
55 |
56 | WatchService watchService = FileSystems.getDefault().newWatchService();
57 |
58 | Path path = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile");
59 | path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
60 |
61 | while (true) {
62 | WatchKey watchKey = watchService.take();
63 |
64 | List> eventList = watchKey.pollEvents();
65 | for (WatchEvent> event : eventList) {
66 | Path eventPath = (Path)event.context();
67 | WatchEvent.Kind> kind = event.kind();
68 |
69 | if (kind == StandardWatchEventKinds.ENTRY_CREATE) System.out.println(String.format("파일 %s가 생성되었습니다", eventPath.getFileName()));
70 | if (kind == StandardWatchEventKinds.ENTRY_DELETE) System.out.println(String.format("파일 %s가 삭제되었습니다", eventPath.getFileName()));
71 | if (kind == StandardWatchEventKinds.ENTRY_MODIFY) System.out.println(String.format("파일 %s가 수정되었습니다", eventPath.getFileName()));
72 | }
73 |
74 | boolean valid = watchKey.reset();
75 | if (!valid) break;
76 | }
77 | }
78 |
79 | public static void main(String[] args) {
80 | try {
81 | studyPath();
82 | studyFileManagement();
83 | } catch (Exception e) {
84 | e.printStackTrace();
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/nio/charBuffer/BufferStudy.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.nio.charBuffer;
2 |
3 | import java.nio.Buffer;
4 | import java.nio.ByteBuffer;
5 |
6 | public class BufferStudy {
7 |
8 | public static void studyBuffer() throws Exception {
9 | ByteBuffer buffer1 = ByteBuffer.allocate(10);
10 |
11 | byte[] bytes = new byte[] {1, 2, 3, 4, 5};
12 | ByteBuffer buffer2 = ByteBuffer.wrap(bytes);
13 |
14 | printStatus(buffer1, "buffer1 생성");
15 | printStatus(buffer2, "buffer2 생성");
16 |
17 | buffer1.put((byte) 55);
18 | buffer1.put((byte) -12);
19 | printStatus(buffer1, "buffer1에 2바이트 추가");
20 |
21 | buffer1.put(new byte[] {15, 16, 17, 18, 19});
22 | printStatus(buffer1, "buffer1에 4바이트 추가");
23 |
24 | byte value = buffer2.get();
25 | System.out.println("읽은 값 : " + value);
26 | printStatus(buffer2, "buffer2에서 1바이트 읽음");
27 |
28 | byte[] bytes1 = new byte[3];
29 | buffer2.get(bytes1);
30 | printStatus(buffer2, "buffer2에서 3바이트 읽음");
31 |
32 | printStatus(buffer1, "buffer1 flip() 실행전");
33 | buffer1.flip();
34 | printStatus(buffer1, "buffer1 flip() 실행후");
35 | value = buffer1.get();
36 | System.out.println("읽은 값 : " + value);
37 | printStatus(buffer1, "buffer1에서 1바이트 읽음");
38 |
39 | printStatus(buffer1, "buffer1 rewind() 실행전");
40 | buffer1.rewind();
41 | printStatus(buffer1, "buffer1 rewind() 실행후");
42 |
43 | buffer1.get(bytes1);
44 | printStatus(buffer1, "buffer1 상태");
45 | buffer1.mark();
46 |
47 | buffer1.get();
48 | printStatus(buffer1, "buffer1 reset() 수행 전");
49 | buffer1.reset();
50 | printStatus(buffer1, "buffer1 reset() 수행 후");
51 |
52 | printStatus(buffer1, "buffer1 compact() 수행 전");
53 | buffer1.compact();
54 | printStatus(buffer1, "buffer1 compact() 수행 후");
55 | }
56 |
57 | public static void printStatus(Buffer buffer, String note) {
58 | System.out.println(String.format("%s : %d %d %d", note, buffer.position(), buffer.limit(), buffer.capacity()));
59 | }
60 |
61 | public static void main(String[] args) {
62 | try {
63 | studyBuffer();
64 | } catch (Exception e) {
65 | e.printStackTrace();
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/nio/fileChannel/FileChannelStudy.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.nio.fileChannel;
2 |
3 | import java.nio.ByteBuffer;
4 | import java.nio.channels.FileChannel;
5 | import java.nio.charset.StandardCharsets;
6 | import java.nio.file.Path;
7 | import java.nio.file.Paths;
8 | import java.nio.file.StandardOpenOption;
9 |
10 | public class FileChannelStudy {
11 |
12 | public static void studyWrite() throws Exception {
13 | Path path = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile/read.txt");
14 | FileChannel channel = FileChannel.open(path, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
15 |
16 | String data = "대구소프트웨어마이스터고등학교";
17 | byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
18 | ByteBuffer buffer = ByteBuffer.wrap(bytes);
19 |
20 | channel.write(buffer);
21 |
22 | channel.close();
23 | }
24 |
25 | public static void studyRead() throws Exception {
26 | Path path = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile/read.txt");
27 | FileChannel channel = FileChannel.open(path, StandardOpenOption.READ);
28 |
29 | ByteBuffer buffer = ByteBuffer.allocate(100);
30 | byte[] bytes = new byte[100];
31 | String data = "";
32 |
33 | while (true) {
34 | int cnt = channel.read(buffer);
35 |
36 | if (cnt < 0) break;
37 |
38 | buffer.flip();
39 |
40 | buffer.get(bytes);
41 | data += new String(bytes, 0, cnt, StandardCharsets.UTF_8);
42 | buffer.clear();
43 | }
44 |
45 | channel.close();
46 | System.out.println(data);
47 | }
48 |
49 | public static void copy() throws Exception {
50 | Path src = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile/favicon.ico");
51 | Path target = Paths.get("/Users/krung2/Documents/Github/JAVA_Class/src/kr/hs/dgsw/javaClass/nio/studyFile/favicon.ico");
52 | }
53 |
54 | public static void main(String[] args) {
55 | try {
56 | studyWrite();
57 | } catch (Exception e) {
58 | e.printStackTrace();
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/nio/studyFile/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/src/kr/hs/dgsw/javaClass/nio/studyFile/favicon.ico
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/nio/studyFile/hello.txt:
--------------------------------------------------------------------------------
1 | 안녕하세요. 대소고 여러분
2 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/nio/studyFile/new/new.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krung2/Java_Class/f6167c65b30aa8dda50cf7f6b9494570a8184a8f/src/kr/hs/dgsw/javaClass/nio/studyFile/new/new.txt
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/nio/studyFile/read.txt:
--------------------------------------------------------------------------------
1 | 대구소프트웨어마이스터고등학교
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/BroadCastServerWorker.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server;
2 |
3 | import java.io.IOException;
4 | import java.io.OutputStream;
5 | import java.net.Socket;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class BroadCastServerWorker extends SocketWorkerAdapter {
10 |
11 | private static List socketList = new ArrayList<>();
12 |
13 | @Override
14 | public void startTalking() throws IOException {
15 |
16 | socketList.add(this.socket);
17 | }
18 |
19 | @Override
20 | public void listen(String message) throws IOException {
21 |
22 | for (Socket socket: socketList) {
23 | OutputStream os = socket.getOutputStream();
24 | os.write(message.getBytes());
25 | }
26 | }
27 |
28 | @Override
29 | public void disconnect() throws IOException {
30 |
31 | if (is != null) is.close();
32 | if (os != null) os.close();
33 | if (socket != null) {
34 | socket.close();
35 | socketList.remove(socket);
36 | }
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/CommonClient.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server;
2 |
3 | import java.io.IOException;
4 | import java.net.Socket;
5 | import java.util.Scanner;
6 |
7 | public class CommonClient extends SocketWorkerAdapter {
8 |
9 | public void connect (String address, int port) throws IOException {
10 |
11 | this.socket = new Socket(address, port);
12 | }
13 |
14 | @Override
15 | public void startTalking() throws IOException {
16 |
17 | Scanner scanner = new Scanner(System.in);
18 |
19 | while (true) {
20 | String line = scanner.nextLine();
21 |
22 | if ("quit".equals(line)) break;
23 |
24 | this.os.write(line.getBytes());
25 | }
26 |
27 | scanner.close();
28 | disconnect();
29 | }
30 |
31 | @Override
32 | public void listen(String message) throws IOException {
33 | System.out.println(message);
34 | }
35 |
36 | public static void main(String[] args) {
37 |
38 | try {
39 |
40 | CommonClient client = new CommonClient();
41 | client.connect("127.0.0.1", 8001);
42 | client.prepareTalking();
43 | client.startTalking();
44 | } catch (Exception e) {
45 | e.printStackTrace();
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/CommonServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server;
2 |
3 | import java.net.ServerSocket;
4 | import java.net.Socket;
5 |
6 | public class CommonServer {
7 |
8 | private ServerSocket serverSocket;
9 |
10 | public void startServer(int port) {
11 |
12 | try {
13 |
14 | serverSocket = new ServerSocket(port);
15 | System.out.println("서버 시작");
16 |
17 | while (true) {
18 |
19 | Socket socket = serverSocket.accept();
20 |
21 | Agent agent = new Agent(socket);
22 | new Thread(agent).start();
23 | }
24 | } catch (Exception e) {
25 | e.printStackTrace();
26 | }
27 | }
28 |
29 | private class Agent implements Runnable {
30 |
31 | private final Socket socket;
32 |
33 | public Agent(Socket socket) {
34 |
35 | this.socket = socket;
36 | }
37 |
38 | @Override
39 | public void run() {
40 |
41 | try {
42 |
43 | SocketWorker socketWorker = new BroadCastServerWorker();
44 | socketWorker.setSocket(socket);
45 | socketWorker.prepareTalking();
46 | socketWorker.startTalking();
47 | } catch (Exception e) {
48 | e.printStackTrace();
49 | }
50 | }
51 | }
52 |
53 | public static void main(String[] args) {
54 |
55 | try{
56 |
57 | CommonServer server = new CommonServer();
58 | server.startServer(8001);
59 | } catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/EchoServerWorker.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server;
2 |
3 | import java.io.IOException;
4 |
5 | public class EchoServerWorker extends SocketWorkerAdapter {
6 |
7 | @Override
8 | public void startTalking() throws IOException {
9 |
10 | }
11 |
12 | @Override
13 | public void listen(String message) throws IOException {
14 |
15 | this.os.write(message.getBytes());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/SimpleClient.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.Socket;
7 | import java.util.Scanner;
8 |
9 | public class SimpleClient {
10 |
11 | private Socket socket;
12 |
13 | private InputStream is;
14 |
15 | private OutputStream os;
16 |
17 | private Scanner scanner;
18 |
19 | private static final String SERVER_ADDRESS = "127.0.0.1";
20 |
21 | private static final int PORT = 8002;
22 |
23 | public void connect() throws IOException {
24 |
25 | socket = new Socket(SERVER_ADDRESS, PORT);
26 | }
27 |
28 | public void disconnect () throws Exception{
29 |
30 | if (os != null) {
31 | os.close();
32 | }
33 |
34 | if (is != null) {
35 | is.close();
36 | }
37 |
38 | if (socket != null) {
39 | socket.close();
40 | }
41 | }
42 |
43 | public void prepareTalking () throws Exception {
44 | is = socket.getInputStream();
45 | os = socket.getOutputStream();
46 | }
47 |
48 | public void startTalking () throws Exception {
49 |
50 | String message = "안녕하세요";
51 |
52 | byte[] bytes = message.getBytes();
53 | os.write(message.getBytes());
54 | os.flush();
55 | }
56 |
57 | public void sendMessage(String message) throws Exception {
58 |
59 | os.write(message.getBytes());
60 | }
61 |
62 | public String receiveMessage () throws Exception {
63 |
64 | byte[] buffer = new byte[1024];
65 |
66 | int length = is.read(buffer);
67 |
68 | return new String(buffer, 0, length);
69 | }
70 |
71 | public void processUserInput() throws Exception {
72 |
73 | scanner = new Scanner(System.in);
74 | int value1;
75 | int value2;
76 |
77 | while (true) {
78 | value1 = scanner.nextInt();
79 | value2 = scanner.nextInt();
80 |
81 | if (value1 == 0 && value2 == 0) {
82 | break;
83 | }
84 |
85 | String message = String.format("%d,%d", value1, value2);
86 |
87 | sendMessage(message);
88 |
89 | String returnMessage = receiveMessage();
90 | System.out.println("받은 메시지 : " + returnMessage);
91 | }
92 |
93 | scanner.close();
94 | disconnect();
95 | }
96 |
97 | public static void main(String[] args) {
98 |
99 | try {
100 |
101 | SimpleClient client = new SimpleClient();
102 | client.connect();
103 | client.prepareTalking();
104 | client.processUserInput();
105 | // client.startTalking();
106 | client.disconnect();
107 | } catch (Exception e) {
108 |
109 | e.printStackTrace();
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/SimpleServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.ServerSocket;
7 | import java.net.Socket;
8 |
9 | public class SimpleServer {
10 |
11 | private ServerSocket serverSocket;
12 |
13 | public static final String SERVER_ADDRESS = "127.0.0.1";
14 |
15 | public static final int PORT = 8002;
16 |
17 | public void startServer() throws IOException {
18 |
19 | serverSocket = new ServerSocket(PORT);
20 | System.out.println("서버 소켓이 생성되었습니다.");
21 |
22 | while (true) {
23 |
24 | System.out.println("클라이언트 접속 기다림");
25 | Socket socket = serverSocket.accept();
26 | System.out.println("클라이언트 접속됨 : " + socket.getInetAddress().toString());
27 | startTalking(socket);
28 | }
29 | }
30 |
31 | public void startTalking (Socket socket) {
32 |
33 | try {
34 |
35 | InputStream is = socket.getInputStream();
36 | OutputStream os = socket.getOutputStream();
37 |
38 | byte[] bytes = new byte[4096];
39 |
40 | while (true) {
41 |
42 | int length = is.read(bytes);
43 |
44 | String message = new String(bytes, 0, length);
45 | System.out.println("클라이언트 메시지 : " + message);
46 |
47 | int index = message.indexOf(",");
48 | String sValue1 = message.substring(0, index);
49 | String sValue2 = message.substring(index + 1);
50 | int value1 = Integer.parseInt(sValue1);
51 | int value2 = Integer.parseInt(sValue2);
52 | int sum = value1 + value2;
53 |
54 | os.write((sum + "").getBytes());
55 | }
56 | } catch (Exception e) {
57 |
58 | System.out.println("클라이언트 연결 종료");
59 | // e.printStackTrace();
60 | }
61 | }
62 |
63 | public static void main(String[] args) {
64 |
65 | try {
66 |
67 | SimpleServer server = new SimpleServer();
68 | server.startServer();
69 | } catch (Exception e) {
70 |
71 | e.printStackTrace();
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/SocketWorker.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server;
2 |
3 | import java.io.IOException;
4 | import java.net.Socket;
5 |
6 | public interface SocketWorker {
7 |
8 | public void setSocket(Socket socket);
9 |
10 | public void prepareTalking() throws IOException;
11 |
12 | public void startTalking() throws IOException;
13 |
14 | public void disconnect() throws IOException;
15 | }
16 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/SocketWorkerAdapter.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.Socket;
7 |
8 | public abstract class SocketWorkerAdapter implements SocketWorker{
9 |
10 | protected Socket socket;
11 |
12 | protected InputStream is;
13 |
14 | protected OutputStream os;
15 |
16 | protected Thread listenerThread;
17 |
18 | @Override
19 | public void setSocket(Socket socket) {
20 |
21 | this.socket = socket;
22 | }
23 |
24 | @Override
25 | public void prepareTalking() throws IOException {
26 |
27 | this.is = socket.getInputStream();
28 | this.os = socket.getOutputStream();
29 |
30 | Listener listener = new Listener();
31 | listenerThread = new Thread(listener);
32 | listenerThread.setDaemon(true);
33 | listenerThread.start();
34 | }
35 |
36 | @Override
37 | public abstract void startTalking() throws IOException;
38 |
39 | public abstract void listen(String message) throws IOException;
40 |
41 | @Override
42 | public void disconnect() throws IOException {
43 |
44 | if (is != null) is.close();
45 | if (os != null) os.close();
46 | if (socket != null) socket.close();
47 | }
48 |
49 | private class Listener implements Runnable {
50 |
51 | @Override
52 | public void run() {
53 |
54 | byte[] buffer = new byte[1024];
55 | int length;
56 |
57 | try {
58 |
59 | while (true) {
60 |
61 | length = is.read(buffer);
62 | listen(new String(buffer, 0, length));
63 | }
64 | } catch (Exception e) {
65 | e.printStackTrace();
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/myself/MyClient.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server.myself;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.Socket;
7 | import java.util.Scanner;
8 |
9 | public class MyClient {
10 |
11 | Socket socket;
12 |
13 | InputStream is;
14 |
15 | OutputStream os;
16 |
17 | private final Scanner scanner;
18 |
19 | private static final String SERVER_ADDRESS = "127.0.0.1";
20 |
21 | private static final int PORT = 8001;
22 |
23 | MyClient () {
24 | this.scanner = new Scanner(System.in);
25 | }
26 |
27 | public void connect () throws IOException {
28 |
29 | socket = new Socket(SERVER_ADDRESS, PORT);
30 |
31 | System.out.println("connecting " + socket.getInetAddress().toString());
32 | }
33 |
34 | public void prepareTalk () throws Exception {
35 | is = socket.getInputStream();
36 | os = socket.getOutputStream();
37 | }
38 |
39 | public void talking () throws Exception {
40 |
41 | while (true) {
42 |
43 | System.out.println("메시지를 입력후 Enter를 눌러주세요 (exit입력시 종료)");
44 | String message = scanner.nextLine();
45 |
46 | if (message.equals("exit")){
47 | System.out.println("서버와의 접속을 종료합니다");
48 | disconnect();
49 | break;
50 | }
51 |
52 | os.write(message.getBytes());
53 |
54 | byte[] bytes = new byte[2048];
55 | int length = is.read(bytes);
56 |
57 | System.out.println("서버 메시지 : " + new String(bytes, 0, length));
58 | }
59 | }
60 |
61 | public void disconnect () throws Exception {
62 |
63 | if (is != null) {
64 | is.close();
65 | }
66 |
67 | if (os != null) {
68 | os.close();
69 | }
70 |
71 | if (socket != null) {
72 | socket.close();
73 | }
74 | }
75 |
76 | public static void main(String[] args) {
77 |
78 | try {
79 |
80 | MyClient myClient = new MyClient();
81 | myClient.connect();
82 | myClient.prepareTalk();
83 | myClient.talking();
84 | } catch (Exception e) {
85 |
86 | e.printStackTrace();
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/myself/MyServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server.myself;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.ServerSocket;
7 | import java.net.Socket;
8 |
9 | public class MyServer {
10 |
11 | ServerSocket serverSocket;
12 |
13 | public static final String SERVER_ADDRESS = "127.0.0.1";
14 |
15 | public static final int PORT = 8001;
16 |
17 | public void start() throws IOException {
18 |
19 | serverSocket = new ServerSocket(PORT);
20 | System.out.println("SERVER is running at " + PORT);
21 |
22 | while (true) {
23 |
24 | System.out.println("waiting...");
25 | Socket client = serverSocket.accept();
26 | System.out.println("client is Connect : " + client.getInetAddress().toString());
27 | startTalk(client);
28 | }
29 | }
30 |
31 | public void startTalk(Socket socket) {
32 |
33 | try {
34 | while (true) {
35 |
36 | InputStream is = socket.getInputStream();
37 | OutputStream os = socket.getOutputStream();
38 |
39 | byte[] bytes = new byte[9999];
40 | int length = is.read(bytes);
41 |
42 | String clientMessage = new String(bytes, 0, length);
43 | System.out.println("client's message : " + clientMessage);
44 |
45 | String serverMessage = clientMessage + " 수신 완료";
46 | os.write(serverMessage.getBytes());
47 | }
48 |
49 | } catch (Exception e) {
50 |
51 | System.out.println("client is disconnect");
52 | // e.printStackTrace();
53 | }
54 | }
55 |
56 | public static void main(String[] args) {
57 |
58 | try {
59 |
60 | MyServer myServer = new MyServer();
61 | myServer.start();
62 | } catch (Exception e) {
63 |
64 | e.printStackTrace();
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/nioBlockingServer/NioBlockingServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server.nioBlockingServer;
2 |
3 | import java.net.InetSocketAddress;
4 | import java.nio.channels.ServerSocketChannel;
5 | import java.nio.channels.SocketChannel;
6 |
7 | public class NioBlockingServer {
8 |
9 | private ServerSocketChannel serverSocketChannel;
10 |
11 | public void start(int port) throws Exception {
12 |
13 | this.serverSocketChannel = ServerSocketChannel.open();
14 | // ServerSocket이 사용할 포트 지정해주기
15 | this.serverSocketChannel.bind(new InetSocketAddress((port)));
16 | // default value = false (false = nonBlockingServer, true = BlockingServer)
17 | this.serverSocketChannel.configureBlocking(true);
18 |
19 | while (true) {
20 | try {
21 | SocketChannel socketChannel = serverSocketChannel.accept();
22 |
23 | SocketChannelAgent agent = new SocketChannelAgent(socketChannel);
24 | agent.init();
25 | } catch (Exception e) {
26 | e.printStackTrace();
27 | }
28 | }
29 |
30 | }
31 | }
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/nioBlockingServer/SocketChannelAgent.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server.nioBlockingServer;
2 |
3 | import java.nio.ByteBuffer;
4 | import java.nio.channels.SocketChannel;
5 | import java.nio.charset.Charset;
6 | import java.nio.charset.StandardCharsets;
7 |
8 | public class SocketChannelAgent {
9 |
10 | private SocketChannel socketChannel;
11 |
12 | private Thread listnerThread;
13 |
14 | public SocketChannelAgent (SocketChannel socketChannel) {
15 | this.socketChannel = socketChannel;
16 | }
17 |
18 | public void init() throws Exception {
19 | listnerThread = new Thread(new Listener());
20 | listnerThread.setDaemon(true);
21 | listnerThread.start();
22 | }
23 |
24 | public void receive (String message) throws Exception {
25 | try {
26 | send(message);
27 | } catch (Exception e) {
28 | e.printStackTrace();
29 | }
30 | }
31 |
32 | public void send(String message) throws Exception {
33 | Charset charset = StandardCharsets.UTF_8;
34 | ByteBuffer buffer = charset.encode(message);
35 | buffer.flip();
36 |
37 | socketChannel.write(buffer);
38 | }
39 |
40 | private class Listener implements Runnable {
41 |
42 | @Override
43 | public void run() {
44 | ByteBuffer buffer = ByteBuffer.allocate(1024);
45 | byte[] bytes = new byte[1024];
46 | int length;
47 |
48 | try {
49 | while (true) {
50 | length = socketChannel.read(buffer);
51 |
52 | if (length < 0) break;
53 |
54 | buffer.flip();
55 | Charset charset = StandardCharsets.UTF_8;
56 | String message = charset.decode(buffer).toString();
57 | receive(message);
58 | }
59 | } catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/server/nioNonBlockingServer/NioNonBlockingServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.server.nioNonBlockingServer;
2 |
3 | import java.net.InetSocketAddress;
4 | import java.nio.channels.SelectionKey;
5 | import java.nio.channels.Selector;
6 | import java.nio.channels.ServerSocketChannel;
7 | import java.nio.channels.SocketChannel;
8 | import java.util.Set;
9 |
10 | public class NioNonBlockingServer {
11 |
12 | private ServerSocketChannel serverSocketChannel;
13 |
14 | public void start (int port) throws Exception {
15 | Selector selector = Selector.open();
16 |
17 | serverSocketChannel = ServerSocketChannel.open();
18 | serverSocketChannel.bind(new InetSocketAddress(port));
19 | serverSocketChannel.configureBlocking(false);
20 |
21 | serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
22 |
23 | while (true) {
24 | int count = selector.select();
25 | Set keys = selector.keys();
26 |
27 | for (SelectionKey key: keys) {
28 | if (key.isAcceptable()) {
29 | ServerSocketChannel channel = (ServerSocketChannel)key.channel();
30 | SocketChannel socketChannel = channel.accept();
31 | } else if (key.isReadable()) {
32 |
33 | } else if (key.isWritable()) {
34 |
35 | }
36 | }
37 | }
38 | }
39 |
40 | public static void main(String[] args) {
41 | try {
42 | NioNonBlockingServer server = new NioNonBlockingServer();
43 | server.start(3001);
44 | } catch (Exception e) {
45 | e.printStackTrace();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/ErrorCode.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer;
2 |
3 | public enum ErrorCode {
4 | PORT_ALREADY_OCCUPIED("1001", "Port가 이미 사용중입니다."),
5 | SERVER_SOCKET_FAIL("1002", "서버 소켓 오류 발생"),
6 | STREAM_CREATION_FAIL("1003", "Input/output stream 생성 실패"),
7 | MESSAGE_SENDING_FAIL("1004", "메시지 송신 실패"),
8 | SERVER_SOCKET_CHANNEL_FAIL("1005", "서버 소켓 채널 오류 발생"),
9 | SERVER_SOCKET_CLOSE_FAIL("2001", "서버 소켓 close 실패"),
10 | SERVER_SOCKET_CHANNEL_CLOSE_FAIL("2002", "서버 소켓 close 실패"),
11 | COMMON_ERROR("9999");
12 |
13 | private String code;
14 |
15 | private String message;
16 |
17 | private ErrorCode() {
18 | this("9999");
19 | }
20 |
21 | private ErrorCode(String code) {
22 | this(code, null);
23 | }
24 |
25 | private ErrorCode(String code, String message) {
26 | this.code = code;
27 | this.message = message;
28 | }
29 |
30 | public String getCode() {
31 | return code;
32 | }
33 |
34 | public void setCode(String code) {
35 | this.code = code;
36 | }
37 |
38 | public String getMessage() {
39 | return message;
40 | }
41 |
42 | public void setMessage(String message) {
43 | this.message = message;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/SessionsCallback.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer;
2 |
3 | public interface SessionsCallback {
4 | public void onConnected(TcpSession session);
5 |
6 | public void onDisconnected(TcpSession session);
7 |
8 | public void onMessageReceived(TcpSession session, byte[] data,
9 | int offset, int length);
10 | }
11 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/TcpServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer;
2 |
3 | public interface TcpServer {
4 |
5 | public void start(int port) throws TcpServerException;
6 |
7 | public void stop();
8 |
9 | public void setSessionsCallback(SessionsCallback callback);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/TcpServerException.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer;
2 |
3 | public class TcpServerException extends RuntimeException {
4 |
5 | /**
6 | * serialVersionUID
7 | */
8 | private static final long serialVersionUID = -7582465793107052204L;
9 |
10 | private ErrorCode errorCode;
11 |
12 | public TcpServerException() {
13 | super();
14 | }
15 |
16 | public TcpServerException(ErrorCode errorCode) {
17 | super(errorCode.getMessage());
18 | this.errorCode = errorCode;
19 | }
20 |
21 | public TcpServerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
22 | super(message, cause, enableSuppression, writableStackTrace);
23 | }
24 |
25 | public TcpServerException(String message, Throwable cause) {
26 | super(message, cause);
27 | }
28 |
29 | public TcpServerException(String message) {
30 | super(message);
31 | }
32 |
33 | public TcpServerException(Throwable cause) {
34 | super(cause);
35 | }
36 |
37 | public ErrorCode getErrorCode() {
38 | return errorCode;
39 | }
40 |
41 | public void setErrorCode(ErrorCode errorCode) {
42 | this.errorCode = errorCode;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/TcpServerFactory.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer;
2 |
3 | import kr.hs.dgsw.javaClass.tcpServer.type.blocking.BlockingServer;
4 | import kr.hs.dgsw.javaClass.tcpServer.type.nonblocking.NonBlockingServer;
5 | import kr.hs.dgsw.javaClass.tcpServer.type.socket.SocketServer;
6 |
7 | public class TcpServerFactory {
8 |
9 | public static final String SOCKET_SERVER = "_socket";
10 | public static final String NIO_BLOCKING_SERVER = "_nio_block";
11 | public static final String NIO_NONBLOCKING_SERVER = "_nio_nonblock";
12 |
13 | public static TcpServer make(String type) {
14 | TcpServer server = null;
15 |
16 | if (SOCKET_SERVER.equals(type)) {
17 | server = new SocketServer();
18 | } else if (NIO_BLOCKING_SERVER.equals(type)) {
19 | server = new BlockingServer();
20 | } else if (NIO_NONBLOCKING_SERVER.equals(type)) {
21 | server = new NonBlockingServer();
22 | }
23 |
24 | return server;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/TcpSession.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer;
2 |
3 | public interface TcpSession {
4 |
5 | public void send(byte[] bytes);
6 |
7 | public void send(byte[] bytes, int offset, int length);
8 |
9 | public void disconnect();
10 | }
11 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/dev/Executor.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer.dev;
2 |
3 | import kr.hs.dgsw.javaClass.tcpServer.SessionsCallback;
4 | import kr.hs.dgsw.javaClass.tcpServer.TcpServer;
5 | import kr.hs.dgsw.javaClass.tcpServer.TcpServerFactory;
6 |
7 | public class Executor {
8 |
9 | public static void main(String[] args) {
10 | try {
11 | TcpServer server = TcpServerFactory.make(TcpServerFactory.NIO_NONBLOCKING_SERVER);
12 |
13 | /* new Thread(new Runnable() {
14 |
15 | @Override
16 | public void run() {
17 | try {
18 | Thread.sleep(1000L);
19 | server.stop();
20 | } catch (Exception e) {
21 | // TODO: handle exception
22 | }
23 |
24 | }
25 | }).start(); */
26 |
27 | SessionsCallback sessionsCallback = new SimpleSessionsCallback();
28 | server.setSessionsCallback(sessionsCallback);
29 |
30 | server.start(3000);
31 |
32 | } catch (Exception e) {
33 | e.printStackTrace();
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/dev/SimpleSessionsCallback.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer.dev;
2 |
3 | import org.slf4j.LoggerFactory;
4 |
5 | import kr.hs.dgsw.javaClass.tcpServer.SessionsCallback;
6 | import kr.hs.dgsw.javaClass.tcpServer.TcpSession;
7 |
8 | public class SimpleSessionsCallback implements SessionsCallback {
9 |
10 | @Override
11 | public void onConnected(TcpSession session) {
12 | LoggerFactory.getLogger(getClass()).debug("Connected");
13 |
14 | }
15 |
16 | @Override
17 | public void onDisconnected(TcpSession session) {
18 | LoggerFactory.getLogger(getClass()).debug("Disconnected");
19 | }
20 |
21 | @Override
22 | public void onMessageReceived(TcpSession session, byte[] data, int offset, int length) {
23 | LoggerFactory.getLogger(getClass()).debug("Received : " + byteArrayToHex(data, offset, length));
24 | session.send(data, 0, length);
25 | }
26 |
27 | public static String byteArrayToHex(byte[] bytes, int offset, int length) {
28 | StringBuilder buffer = new StringBuilder(bytes.length * 2);
29 |
30 | for (int i = offset; i < length ; i++) {
31 | buffer.append(String.format("%02x", bytes[i]));
32 | }
33 |
34 | return buffer.toString();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/type/blocking/BlockingServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer.type.blocking;
2 |
3 | import java.io.IOException;
4 | import java.net.BindException;
5 | import java.net.InetSocketAddress;
6 | import java.nio.channels.AsynchronousCloseException;
7 | import java.nio.channels.ServerSocketChannel;
8 | import java.nio.channels.SocketChannel;
9 |
10 | import org.slf4j.Logger;
11 | import org.slf4j.LoggerFactory;
12 |
13 | import kr.hs.dgsw.javaClass.tcpServer.ErrorCode;
14 | import kr.hs.dgsw.javaClass.tcpServer.SessionsCallback;
15 | import kr.hs.dgsw.javaClass.tcpServer.TcpServer;
16 | import kr.hs.dgsw.javaClass.tcpServer.TcpServerException;
17 |
18 | public class BlockingServer implements TcpServer {
19 |
20 | private Logger logger = LoggerFactory.getLogger(getClass());
21 |
22 | protected ServerSocketChannel serverSocketChannel;
23 |
24 | protected SessionsCallback sessionsCallback;
25 |
26 | @Override
27 | public void start(int port) throws TcpServerException {
28 |
29 | try {
30 | serverSocketChannel = ServerSocketChannel.open();
31 | serverSocketChannel.configureBlocking(true);
32 | serverSocketChannel.bind(new InetSocketAddress(port));
33 | logger.info("Server started");
34 |
35 | SocketChannel socketChannel = null;
36 | while (true) {
37 | socketChannel = serverSocketChannel.accept();
38 | makeAgent(socketChannel);
39 | }
40 |
41 | } catch (BindException e) {
42 | throw new TcpServerException(ErrorCode.PORT_ALREADY_OCCUPIED);
43 | } catch (AsynchronousCloseException e) {
44 | logger.info("Server terminated");
45 | } catch (IOException e) {
46 | throw new TcpServerException(ErrorCode.SERVER_SOCKET_FAIL);
47 | }
48 | }
49 |
50 |
51 | @Override
52 | public void stop() {
53 | try {
54 | serverSocketChannel.close();
55 | } catch (IOException e) {
56 | e.printStackTrace();
57 | throw new TcpServerException(ErrorCode.SERVER_SOCKET_CHANNEL_CLOSE_FAIL);
58 | }
59 | }
60 |
61 |
62 | @Override
63 | public void setSessionsCallback(SessionsCallback callback) {
64 | this.sessionsCallback = callback;
65 | }
66 |
67 | protected void makeAgent(SocketChannel socketChannel) {
68 | BlockingServerAgent agent = new BlockingServerAgent(socketChannel, sessionsCallback);
69 | agent.start();
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/type/blocking/BlockingServerAgent.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer.type.blocking;
2 |
3 | import java.io.IOException;
4 | import java.nio.ByteBuffer;
5 | import java.nio.channels.SocketChannel;
6 |
7 | import kr.hs.dgsw.javaClass.tcpServer.ErrorCode;
8 | import kr.hs.dgsw.javaClass.tcpServer.SessionsCallback;
9 | import kr.hs.dgsw.javaClass.tcpServer.TcpServerException;
10 | import kr.hs.dgsw.javaClass.tcpServer.TcpSession;
11 |
12 | public class BlockingServerAgent implements TcpSession {
13 | public static final int BUFFER_SIZE = 1024;
14 |
15 | //private Logger logger = LoggerFactory.getLogger(getClass());
16 |
17 | protected SessionsCallback sessionsCallback;
18 |
19 | protected SocketChannel channel;
20 |
21 | protected ByteBuffer byteBuffer;
22 |
23 | protected Thread listenerThread;
24 |
25 |
26 | public BlockingServerAgent(SocketChannel channel, SessionsCallback sessionsCallback) {
27 | this.sessionsCallback = sessionsCallback;
28 | this.channel = channel;
29 | }
30 |
31 | public void start() {
32 | this.byteBuffer = ByteBuffer.allocate(BUFFER_SIZE);
33 |
34 | listenerThread = new Thread(new Listener());
35 | listenerThread.setDaemon(true);
36 | listenerThread.start();
37 |
38 | if (sessionsCallback != null) {
39 | sessionsCallback.onConnected(this);
40 | }
41 | }
42 |
43 | protected void close() {
44 | try {
45 | if (channel != null) {
46 | channel.close();
47 | }
48 | } catch (IOException e) {
49 | } finally {
50 | if (sessionsCallback != null) {
51 | sessionsCallback.onDisconnected(this);
52 | }
53 | }
54 |
55 | }
56 |
57 | @Override
58 | public void send(byte[] bytes) {
59 | send(bytes, 0, bytes.length);
60 | }
61 |
62 | @Override
63 | public void send(byte[] bytes, int offset, int length) {
64 | try {
65 | ByteBuffer buffer = ByteBuffer.allocate(length - offset);
66 |
67 | buffer.put(bytes, offset, length);
68 | buffer.flip();
69 |
70 | channel.write(buffer);
71 | } catch (IOException e) {
72 | throw new TcpServerException(ErrorCode.MESSAGE_SENDING_FAIL);
73 | }
74 | }
75 |
76 | @Override
77 | public void disconnect() {
78 | close();
79 |
80 | try {
81 | listenerThread.join();
82 |
83 | } catch (InterruptedException e) {
84 | }
85 | }
86 |
87 | private void onReceive(byte[] bytes, int length) {
88 | if (sessionsCallback != null) {
89 | sessionsCallback.onMessageReceived(this, bytes, 0, length);
90 | }
91 | }
92 |
93 | protected class Listener implements Runnable {
94 | @Override
95 | public void run() {
96 | byte[] bytes = new byte[BUFFER_SIZE];
97 | int length;
98 |
99 | try {
100 | while ((length = channel.read(byteBuffer)) >= 0) {
101 | byteBuffer.flip();
102 | byteBuffer.get(bytes, 0, length);
103 |
104 | onReceive(bytes, length);
105 | }
106 |
107 | close();
108 | } catch (IOException e) {
109 |
110 | }
111 | }
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/type/nonblocking/NonBlockingServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer.type.nonblocking;
2 |
3 | import java.io.IOException;
4 | import java.net.BindException;
5 | import java.net.InetSocketAddress;
6 | import java.nio.ByteBuffer;
7 | import java.nio.channels.AsynchronousCloseException;
8 | import java.nio.channels.SelectionKey;
9 | import java.nio.channels.Selector;
10 | import java.nio.channels.ServerSocketChannel;
11 | import java.nio.channels.SocketChannel;
12 | import java.util.Iterator;
13 | import java.util.Set;
14 |
15 | import org.slf4j.Logger;
16 | import org.slf4j.LoggerFactory;
17 |
18 | import kr.hs.dgsw.javaClass.tcpServer.ErrorCode;
19 | import kr.hs.dgsw.javaClass.tcpServer.SessionsCallback;
20 | import kr.hs.dgsw.javaClass.tcpServer.TcpServer;
21 | import kr.hs.dgsw.javaClass.tcpServer.TcpServerException;
22 | import kr.hs.dgsw.javaClass.tcpServer.TcpSession;
23 |
24 | public class NonBlockingServer implements TcpServer {
25 |
26 | private Logger logger = LoggerFactory.getLogger(getClass());
27 |
28 | protected Selector selector;
29 |
30 | protected ServerSocketChannel serverSocketChannel;
31 |
32 | protected SessionsCallback sessionsCallback;
33 |
34 | protected boolean running = true;
35 |
36 | @Override
37 | public void start(int port) throws TcpServerException {
38 |
39 | try {
40 | selector = Selector.open();
41 |
42 | serverSocketChannel = ServerSocketChannel.open();
43 | serverSocketChannel.configureBlocking(false);
44 | serverSocketChannel.bind(new InetSocketAddress(port));
45 |
46 | serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
47 |
48 | logger.info("Server started");
49 |
50 |
51 | while (true) {
52 | int keyCount = selector.select();
53 |
54 | if (keyCount > 0) {
55 | Set keys = selector.selectedKeys();
56 | Iterator iterator = keys.iterator();
57 |
58 | while (iterator.hasNext()) {
59 | SelectionKey key = iterator.next();
60 |
61 | if (key.isAcceptable()) {
62 | accept(key);
63 | } else if (key.isReadable()) {
64 | read(key);
65 | } else if (key.isWritable()) {
66 | write(key);
67 | }
68 |
69 | iterator.remove();
70 | }
71 | } else {
72 | if (!running) {
73 | throw new AsynchronousCloseException();
74 | }
75 | }
76 | }
77 |
78 | } catch (BindException e) {
79 | throw new TcpServerException(ErrorCode.PORT_ALREADY_OCCUPIED);
80 | } catch (AsynchronousCloseException e) {
81 | logger.info("Server terminated");
82 | } catch (IOException e) {
83 | throw new TcpServerException(ErrorCode.SERVER_SOCKET_FAIL);
84 | }
85 | }
86 |
87 | @Override
88 | public void stop() {
89 | try {
90 | running = false;
91 |
92 | serverSocketChannel.close();
93 | selector.wakeup();
94 | } catch (IOException e) {
95 | e.printStackTrace();
96 | throw new TcpServerException(ErrorCode.SERVER_SOCKET_CHANNEL_CLOSE_FAIL);
97 | }
98 | }
99 |
100 |
101 | @Override
102 | public void setSessionsCallback(SessionsCallback callback) {
103 | this.sessionsCallback = callback;
104 | }
105 |
106 | protected void accept(SelectionKey selectionKey) {
107 | try {
108 | ServerSocketChannel serverSocketChannel = (ServerSocketChannel)selectionKey.channel();
109 | SocketChannel socketChannel = serverSocketChannel.accept();
110 |
111 | socketChannel.configureBlocking(false);
112 | socketChannel.register(selector, SelectionKey.OP_READ);
113 |
114 | TcpSession session = new NonBlockingServerSession(socketChannel, selector);
115 |
116 | SelectionKey key = socketChannel.keyFor(selector);
117 | key.attach(session);
118 |
119 | sessionsCallback.onConnected(session);
120 |
121 | } catch (Exception e) {
122 | e.printStackTrace();
123 | }
124 | }
125 |
126 | protected void read(SelectionKey selectionKey) {
127 | try {
128 | SocketChannel socketChannel = (SocketChannel)selectionKey.channel();
129 |
130 | ByteBuffer buffer = ByteBuffer.allocate(1024);
131 | byte[] readBytes = new byte[1024];
132 | byte[] bytes = new byte[0];
133 | int length;
134 |
135 | while ((length = socketChannel.read(buffer)) > 0) {
136 | buffer.flip();
137 | buffer.get(readBytes, 0, length);
138 | bytes = concatByteArray(bytes, readBytes, length);
139 | }
140 |
141 | TcpSession session = (TcpSession)selectionKey.attachment();
142 |
143 | if (bytes.length > 0) {
144 | sessionsCallback.onMessageReceived(session, bytes, 0, bytes.length);
145 | } else {
146 | socketChannel.close();
147 |
148 | sessionsCallback.onDisconnected(session);
149 | }
150 |
151 | } catch (Exception e) {
152 | e.printStackTrace();
153 | }
154 | }
155 |
156 | protected void write(SelectionKey key) {
157 | NonBlockingServerSession session = (NonBlockingServerSession)key.attachment();
158 | session.sendPhysically();
159 | }
160 |
161 | protected static byte[] concatByteArray(byte[] first, byte[] second, int length) {
162 | byte[] result = new byte[first.length + second.length];
163 | System.arraycopy(first, 0, result, 0, 0);
164 | System.arraycopy(second, 0, result, first.length, length);
165 |
166 | return result;
167 | }
168 |
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/type/nonblocking/NonBlockingServerSession.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer.type.nonblocking;
2 |
3 | import java.nio.ByteBuffer;
4 | import java.nio.channels.SelectionKey;
5 | import java.nio.channels.Selector;
6 | import java.nio.channels.SocketChannel;
7 |
8 | import kr.hs.dgsw.javaClass.tcpServer.TcpSession;
9 |
10 | public class NonBlockingServerSession implements TcpSession {
11 |
12 | private SocketChannel socketChannel;
13 |
14 | private Selector selector;
15 |
16 | private ByteBuffer buffer;
17 |
18 | public NonBlockingServerSession(SocketChannel socketChannel, Selector selector) {
19 | this.socketChannel = socketChannel;
20 | this.selector = selector;
21 | }
22 |
23 | @Override
24 | public void send(byte[] bytes, int offset, int length) {
25 | buffer = ByteBuffer.wrap(bytes, offset, length);
26 |
27 | SelectionKey selectionKey = socketChannel.keyFor(selector);
28 | selectionKey.interestOps(SelectionKey.OP_WRITE);
29 | selector.wakeup();
30 | }
31 |
32 | @Override
33 | public void send(byte[] bytes) {
34 | send(bytes, 0, bytes.length);
35 | }
36 |
37 | @Override
38 | public void disconnect() {
39 | // TODO
40 | }
41 |
42 | public void sendPhysically() {
43 | try {
44 | if (buffer != null) {
45 | socketChannel.write(buffer);
46 | }
47 |
48 | SelectionKey selectionKey = socketChannel.keyFor(selector);
49 | selectionKey.interestOps(SelectionKey.OP_READ);
50 | selector.wakeup();
51 | } catch (Exception e) {
52 | e.printStackTrace();
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/type/socket/SocketServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer.type.socket;
2 |
3 | import java.io.IOException;
4 | import java.net.BindException;
5 | import java.net.ServerSocket;
6 | import java.net.Socket;
7 | import java.net.SocketException;
8 |
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | import kr.hs.dgsw.javaClass.tcpServer.ErrorCode;
13 | import kr.hs.dgsw.javaClass.tcpServer.SessionsCallback;
14 | import kr.hs.dgsw.javaClass.tcpServer.TcpServer;
15 | import kr.hs.dgsw.javaClass.tcpServer.TcpServerException;
16 | import kr.hs.dgsw.javaClass.tcpServer.TcpServerFactory;
17 | import kr.hs.dgsw.javaClass.tcpServer.dev.SimpleSessionsCallback;
18 |
19 |
20 | public class SocketServer implements TcpServer {
21 |
22 | private Logger logger = LoggerFactory.getLogger(getClass());
23 |
24 | protected ServerSocket serverSocket;
25 |
26 | protected SessionsCallback sessionsCallback;
27 |
28 | @Override
29 | public void start(int port) throws TcpServerException {
30 | try {
31 | serverSocket = new ServerSocket(port);
32 | logger.info("Server started");
33 |
34 | while (true) {
35 | Socket socket = serverSocket.accept();
36 | makeAgent(socket);
37 | }
38 | } catch (BindException e) {
39 | throw new TcpServerException(ErrorCode.PORT_ALREADY_OCCUPIED);
40 | } catch (SocketException e) {
41 | logger.info("Server terminated");
42 | } catch (IOException e) {
43 | throw new TcpServerException(ErrorCode.SERVER_SOCKET_FAIL);
44 | }
45 | }
46 |
47 | @Override
48 | public void stop() {
49 | try {
50 | if (serverSocket != null && serverSocket.isBound()) {
51 | serverSocket.close();
52 | }
53 | } catch (IOException e) {
54 | throw new TcpServerException(ErrorCode.SERVER_SOCKET_CLOSE_FAIL);
55 | }
56 | }
57 |
58 | @Override
59 | public void setSessionsCallback(SessionsCallback callback) {
60 | this.sessionsCallback = callback;
61 | }
62 |
63 | protected void makeAgent(Socket socket) {
64 | SocketServerAgent agent = new SocketServerAgent(socket, sessionsCallback);
65 | agent.start();
66 | }
67 |
68 | public static void main(String[] args) {
69 | try {
70 | TcpServer server = TcpServerFactory.make(TcpServerFactory.SOCKET_SERVER);
71 |
72 | /*
73 | new Thread(new Runnable() {
74 |
75 | @Override
76 | public void run() {
77 | try {
78 | Thread.sleep(1000L);
79 | server.stop();
80 | } catch (Exception e) {
81 | // TODO: handle exception
82 | }
83 |
84 | }
85 | }).start();
86 | */
87 |
88 | SessionsCallback sessionsCallback = new SimpleSessionsCallback();
89 | server.setSessionsCallback(sessionsCallback);
90 |
91 | server.start(3000);
92 |
93 |
94 | } catch (Exception e) {
95 | e.printStackTrace();
96 | }
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/tcpServer/type/socket/SocketServerAgent.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.tcpServer.type.socket;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.Socket;
7 |
8 | import kr.hs.dgsw.javaClass.tcpServer.ErrorCode;
9 | import kr.hs.dgsw.javaClass.tcpServer.SessionsCallback;
10 | import kr.hs.dgsw.javaClass.tcpServer.TcpServerException;
11 | import kr.hs.dgsw.javaClass.tcpServer.TcpSession;
12 |
13 | public class SocketServerAgent implements TcpSession {
14 |
15 | public static final int BUFFER_SIZE = 1024;
16 |
17 | //private Logger logger = LoggerFactory.getLogger(getClass());
18 |
19 | protected SessionsCallback sessionsCallback;
20 |
21 | protected Socket socket;
22 |
23 | protected InputStream is;
24 |
25 | protected OutputStream os;
26 |
27 | protected Thread listenerThread;
28 |
29 |
30 | public SocketServerAgent(Socket socket, SessionsCallback sessionsCallback) {
31 | this.sessionsCallback = sessionsCallback;
32 | this.socket = socket;
33 | }
34 |
35 | public void start() {
36 | try {
37 | is = socket.getInputStream();
38 | os = socket.getOutputStream();
39 |
40 | listenerThread = new Thread(new Listener());
41 | listenerThread.setDaemon(true);
42 | listenerThread.start();
43 |
44 | if (sessionsCallback != null) {
45 | sessionsCallback.onConnected(this);
46 | }
47 | } catch (IOException e) {
48 | throw new TcpServerException(ErrorCode.STREAM_CREATION_FAIL);
49 | }
50 | }
51 |
52 | protected void close() {
53 | try {
54 | if (is != null) {
55 | is.close();
56 | }
57 |
58 | if (os != null) {
59 | os.close();
60 | }
61 |
62 | if (socket != null) {
63 | socket.close();
64 | }
65 | } catch (IOException e) {
66 | } finally {
67 | if (sessionsCallback != null) {
68 | sessionsCallback.onDisconnected(this);
69 | }
70 | }
71 |
72 | }
73 |
74 | @Override
75 | public void send(byte[] bytes) {
76 | send(bytes, 0, bytes.length);
77 | }
78 |
79 | @Override
80 | public void send(byte[] bytes, int offset, int length) {
81 | try {
82 | os.write(bytes, offset, length);
83 | } catch (IOException e) {
84 | throw new TcpServerException(ErrorCode.MESSAGE_SENDING_FAIL);
85 | }
86 | }
87 |
88 | @Override
89 | public void disconnect() {
90 | close();
91 |
92 | try {
93 | listenerThread.join();
94 |
95 | } catch (InterruptedException e) {
96 | }
97 | }
98 |
99 | private void onReceive(byte[] bytes, int length) {
100 | if (sessionsCallback != null) {
101 | sessionsCallback.onMessageReceived(this, bytes, 0, length);
102 | }
103 | }
104 |
105 | protected class Listener implements Runnable {
106 | @Override
107 | public void run() {
108 | byte[] bytes = new byte[BUFFER_SIZE];
109 | int length;
110 |
111 | try {
112 | while ((length = is.read(bytes)) >= 0) {
113 | onReceive(bytes, length);
114 | }
115 |
116 | close();
117 | } catch (IOException e) {
118 |
119 | }
120 | }
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/test/ChattingClient.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.test;
2 |
3 | import java.io.IOException;
4 | import java.net.Socket;
5 | import java.nio.charset.StandardCharsets;
6 | import java.util.ArrayList;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Scanner;
10 |
11 | public class ChattingClient extends SocketWorker {
12 |
13 | private Scanner scanner;
14 |
15 | private HashMap userMap = new HashMap<>();
16 |
17 | public void connect (String address, int port) throws IOException {
18 |
19 | this.socket = new Socket(address, port);
20 | }
21 |
22 | @Override
23 | public void startTalking() throws IOException {
24 |
25 | scanner = new Scanner(System.in);
26 |
27 | System.out.println("id와 이름을 입력해주요 ex) 2210 신중빈");
28 | String idName = scanner.nextLine();
29 | sendMessage(ChattingCommand.ID, idName);
30 |
31 | while (true) {
32 | String line = scanner.nextLine();
33 |
34 | if (line.startsWith("/")) {
35 | List message = List.of(line.split(" "));
36 |
37 | switch (message.get(0)) {
38 | case "/귓속말":
39 | List messages = new ArrayList<>();
40 | for (int i = 2;i < message.size();i ++) {
41 | messages.add(message.get(i));
42 | }
43 | sendMessage(ChattingCommand.SM, message.get(1) + " " + String.join(" ", messages));
44 | break;
45 |
46 | case "/추방":
47 | sendMessage(ChattingCommand.WD, message.get(1));
48 | break;
49 |
50 | default:
51 | System.out.println("없는 명령어입니다 다시 시도해주세요");
52 | break;
53 | }
54 |
55 | } else {
56 |
57 | if (line == "quit") break;
58 |
59 | sendMessage(ChattingCommand.GM, line);
60 | }
61 | }
62 |
63 | scanner.close();
64 | disconnect();
65 | }
66 |
67 | @Override
68 | public void listen(byte[] buffer, int length) throws IOException {
69 | if (length == -1) {
70 | System.out.println("서버와 연결이 끊켰습니다");
71 | scanner.close();
72 | disconnect();
73 | }
74 |
75 | Message message = new Message(buffer, length);
76 | System.out.println(message.getCommand().toString() + String.format("%4d", message.getPayloadLength()) + message.getReceiveMessage());
77 |
78 | switch (message.getCommand()) {
79 | case UR:
80 | List connectusers = List.of(message.getReceiveMessage().split(","));
81 | connectusers.forEach(this::saveUserInfo);
82 | System.out.println(message.getReceiveMessage());
83 | break;
84 |
85 | case GR:
86 | List userInfo = getUserInfo(message.getReceiveMessage());
87 | String user = userMap.get(userInfo.get(0));
88 | System.out.println(user + " :" + userInfo.get(1));
89 | break;
90 |
91 | case JR:
92 | saveUserInfo(message.getReceiveMessage());
93 | System.out.println(message.getReceiveMessage() + "님이 접속하였습니다");
94 | break;
95 |
96 | case DR:
97 | System.out.println("중복된 아이디입니다");
98 | disconnect();
99 |
100 | return;
101 |
102 | case SR:
103 | List whisperUserInfo = getUserInfo(message.getReceiveMessage());
104 | String whisperUser = userMap.get(whisperUserInfo.get(0));
105 | System.out.println("귓속말) " + whisperUserInfo.get(0) + " " + whisperUser + " " +
106 | ":" + whisperUserInfo.get(1));
107 | break;
108 |
109 | case DC:
110 | String quitUser = userMap.get(message.getReceiveMessage());
111 | userMap.remove(message.getReceiveMessage());
112 | System.out.println(message.getReceiveMessage() + " " + quitUser + "가 퇴실했습니다");
113 | break;
114 |
115 | case WR:
116 | System.out.println("추방당했습니다");
117 | disconnect();
118 | return;
119 |
120 | case WA:
121 | String kickeduser = userMap.get(message.getReceiveMessage());
122 | userMap.remove(message.getReceiveMessage());
123 | System.out.println(message.getReceiveMessage() + " " + kickeduser + "가 추방당했습니다");
124 | break;
125 |
126 | default:
127 | break;
128 | }
129 | }
130 |
131 | @Override
132 | public String sendMessage(ChattingCommand chattingCommand, String payload) throws IOException {
133 | String message = super.sendMessage(chattingCommand, payload);
134 | this.os.write(message.getBytes(StandardCharsets.UTF_8));
135 | return "";
136 | }
137 |
138 |
139 | private void saveUserInfo (String idName) {
140 | userMap.put(idName.substring(0, 4), idName.substring(4));
141 | }
142 |
143 | public static void main(String[] args) {
144 |
145 | try {
146 |
147 | ChattingClient client = new ChattingClient();
148 | client.connect("10.80.163.75", 1200);
149 | client.prepareTalking();
150 | client.startTalking();
151 | } catch (Exception e) {
152 | e.printStackTrace();
153 | }
154 | }
155 |
156 | }
157 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/test/ChattingCommand.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.test;
2 |
3 | public enum ChattingCommand {
4 | ID,
5 | DR,
6 | UR,
7 | JR,
8 | GM,
9 | GR,
10 | SM,
11 | SR,
12 | DC,
13 | WD,
14 | WR,
15 | WA,
16 | }
17 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/test/ChattingServer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.test;
2 |
3 | import java.net.ServerSocket;
4 | import java.net.Socket;
5 |
6 | public class ChattingServer {
7 |
8 | private ServerSocket serverSocket;
9 |
10 | public void startServer () {
11 |
12 | try {
13 |
14 | serverSocket = new ServerSocket(1200);
15 | System.out.println("Server start");
16 |
17 | while (true) {
18 | Socket socket = serverSocket.accept();
19 | Agent agent = new Agent(socket);
20 |
21 | new Thread(agent).start();
22 | }
23 | } catch (Exception e) {
24 | e.printStackTrace();
25 | }
26 | }
27 |
28 | private class Agent implements Runnable {
29 |
30 | private final Socket socket;
31 |
32 | public Agent (Socket socket) {
33 | this.socket = socket;
34 | }
35 |
36 | @Override
37 | public void run() {
38 |
39 | try {
40 |
41 | SocketWorker socketWorker = new ChattingServerWorker();
42 | socketWorker.setSocket(socket);
43 | socketWorker.prepareTalking();
44 | socketWorker.startTalking();
45 | } catch (Exception e) {
46 | e.printStackTrace();
47 | }
48 | }
49 | }
50 |
51 | public static void main(String[] args) {
52 | try {
53 |
54 | ChattingServer server = new ChattingServer();
55 | server.startServer();
56 | } catch (Exception e) {
57 | e.printStackTrace();
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/test/ChattingServerWorker.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.test;
2 |
3 | import java.io.IOException;
4 | import java.nio.charset.StandardCharsets;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class ChattingServerWorker extends SocketWorker {
9 |
10 | private String idName;
11 | private String id;
12 | private static List userList = new ArrayList<>();
13 |
14 | @Override
15 | public void startTalking() throws IOException {
16 |
17 | System.out.println(this.socket.getInetAddress().toString() + " connet");
18 | userList.add(this);
19 | }
20 |
21 | @Override
22 | public void listen(byte[] buffer, int length) throws IOException {
23 |
24 | if (length < 0) disconnect();
25 |
26 | Message message = new Message(buffer, length);
27 | System.out.println(message.getCommand().toString() + message.getPayloadLength() + message.getReceiveMessage());
28 |
29 | switch (message.getCommand()) {
30 | case ID:
31 | saveId(message.getReceiveMessage());
32 | break;
33 |
34 | case GM:
35 | String sendMessage = sendMessage(ChattingCommand.GR, this.id + " " + message.getReceiveMessage());
36 | sendMessageToEveryOne(sendMessage);
37 | break;
38 |
39 | case SM:
40 | List userInfo = getUserInfo(message.getReceiveMessage());
41 | String sendWhisperMessage = sendMessage(ChattingCommand.SR, this.id + " " + userInfo.get(1));
42 | sendMessageToOne(userInfo.get(0), sendWhisperMessage);
43 | break;
44 |
45 | case WD:
46 | if (this.id != userList.get(0).id) break;
47 | kickUser(message.getReceiveMessage());
48 |
49 | default:
50 | break;
51 | }
52 | }
53 |
54 | public void sendMessageToEveryOne (String message) throws IOException {
55 | for (ChattingServerWorker user: userList) {
56 | if (user.id == null) continue;
57 | if (user.id.equals(this.id)) continue;
58 | try {
59 | user.socket.getOutputStream().write(message.getBytes(StandardCharsets.UTF_8));
60 | } catch (Exception e) {
61 | continue;
62 | }
63 | }
64 | }
65 |
66 | private void sendMessageToOne (String userId, String message) throws IOException {
67 | for (ChattingServerWorker user: userList) {
68 | if (user.id == null) break;
69 | if (user.id.equals(userId)) {
70 | try {
71 | user.socket.getOutputStream().write(message.getBytes(StandardCharsets.UTF_8));
72 | } catch (Exception e) {
73 | continue;
74 | }
75 | break;
76 | }
77 | }
78 | }
79 |
80 | private void kickUser (String userId) throws IOException {
81 | ChattingServerWorker kickUser = null;
82 | for (ChattingServerWorker user: userList) {
83 | if (user.id.equals(userId)) {
84 | user.socket.getOutputStream().write(
85 | sendMessage(ChattingCommand.WR)
86 | .getBytes(StandardCharsets.UTF_8)
87 | );
88 | kickUser = user;
89 | } else {
90 | user.socket.getOutputStream().write(
91 | sendMessage(ChattingCommand.WA, userId)
92 | .getBytes(StandardCharsets.UTF_8)
93 | );
94 | }
95 | }
96 | disconnectToObject(kickUser);
97 | }
98 |
99 | @Override
100 | public void disconnect() throws IOException {
101 | sendMessageToEveryOne(sendMessage(ChattingCommand.DC, this.id));
102 |
103 | if (is != null) is.close();
104 | if (os != null) os.close();
105 | if (socket != null) {
106 | socket.close();
107 | userList.remove(this);
108 | }
109 | }
110 |
111 | private void disconnectToObject(ChattingServerWorker kickUser) throws IOException {
112 | if (kickUser.is != null) is.close();
113 | if (kickUser.os != null) os.close();
114 | if (kickUser.socket != null) {
115 | kickUser.socket.close();
116 | userList.remove(kickUser);
117 | }
118 | }
119 |
120 | public void saveId(String idName) throws IOException{
121 | try {
122 | List userNameList = new ArrayList<>();
123 |
124 | String savingId = idName.substring(0, 4);
125 |
126 | for (ChattingServerWorker user: userList) {
127 |
128 | userNameList.add(user.idName);
129 | if (savingId.equals(user.id)) {
130 | this.os.write(sendMessage(ChattingCommand.DR).getBytes(StandardCharsets.UTF_8));
131 | return;
132 | }
133 | }
134 |
135 | this.idName = idName;
136 | this.id = savingId;
137 | userNameList.add(idName);
138 | userNameList.remove(null);
139 |
140 | String sendingMessage = sendMessage(ChattingCommand.UR, String.join(",", userNameList).replace("null,", "").replace("null", ""));
141 | this.os.write(sendingMessage.getBytes(StandardCharsets.UTF_8));
142 | sendMessageToEveryOne(sendMessage(ChattingCommand.JR, this.idName));
143 | } catch (Exception e) {
144 | disconnect();
145 | e.printStackTrace();
146 | }
147 | }
148 | }
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/test/Message.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.test;
2 |
3 | public class Message {
4 |
5 | private ChattingCommand command;
6 | private int payloadLength;
7 | private String receiveMessage;
8 |
9 | public ChattingCommand getCommand() {
10 | return command;
11 | }
12 |
13 | public int getPayloadLength() {
14 | return payloadLength;
15 | }
16 |
17 | public String getReceiveMessage() {
18 | return receiveMessage;
19 | }
20 |
21 | public Message (byte[] buffer, int length) {
22 | this.command = ChattingCommand.valueOf(new String(buffer, 0, 2));
23 | this.payloadLength = Integer.parseInt(new String(buffer, 2, 4));
24 | this.receiveMessage = new String(buffer, 6, payloadLength);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/test/SocketWorker.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.test;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.OutputStream;
6 | import java.net.Socket;
7 | import java.nio.charset.StandardCharsets;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | public abstract class SocketWorker {
12 |
13 | protected Socket socket;
14 |
15 | protected InputStream is;
16 |
17 | protected OutputStream os;
18 |
19 | protected Thread listenerThread;
20 |
21 | public void setSocket(Socket socket) {
22 |
23 | this.socket = socket;
24 | }
25 |
26 | public void prepareTalking() throws IOException {
27 |
28 | this.is = socket.getInputStream();
29 | this.os = socket.getOutputStream();
30 |
31 | Listener listener = new Listener();
32 | listenerThread = new Thread(listener);
33 | listenerThread.setDaemon(true);
34 | listenerThread.start();
35 | }
36 |
37 | public abstract void startTalking() throws IOException;
38 |
39 | public abstract void listen(byte[] buffer, int length) throws IOException;
40 |
41 | public void disconnect() throws IOException {
42 |
43 | if (is != null) is.close();
44 | if (os != null) os.close();
45 | if (socket != null) {
46 | socket.close();
47 | }
48 | }
49 |
50 | public String sendMessage(ChattingCommand chattingCommand) throws IOException {
51 | return chattingCommand + "0000";
52 | }
53 |
54 | public String sendMessage(ChattingCommand chattingCommand, String payload) throws IOException {
55 | return chattingCommand + String.format("%04d", payload.getBytes(StandardCharsets.UTF_8).length) + payload;
56 | }
57 |
58 | protected List getUserInfo (String idWithName) {
59 | List list = new ArrayList<>();
60 | list.add(idWithName.substring(0, 4));
61 | list.add(idWithName.substring(4));
62 | return list;
63 | }
64 |
65 | private class Listener implements Runnable {
66 |
67 | @Override
68 | public void run() {
69 |
70 | byte[] buffer = new byte[1024];
71 | int length;
72 |
73 | try {
74 |
75 | while (true) {
76 |
77 | length = is.read(buffer);
78 | if (length < 0) {
79 | disconnect();
80 | break;
81 | }
82 | listen(buffer, length);
83 | }
84 | } catch (Exception e) {
85 |
86 | e.printStackTrace();
87 | }
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/Calculater.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Calculater {
7 |
8 | private int sum = 0;
9 |
10 | private List list = new ArrayList<>();
11 |
12 | public void add (int value) {
13 |
14 | synchronized (list) {
15 | int a = sum + value;
16 | sum = a;
17 | }
18 |
19 | }
20 |
21 | public void method1() {
22 |
23 | synchronized (list) {
24 | list.add("123");
25 | }
26 | }
27 |
28 | public int getSum() {
29 | return sum;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/DaemonThread.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread;
2 |
3 | public class DaemonThread extends Thread {
4 |
5 | @Override
6 | public void run() {
7 |
8 | // for (int i = 0;i < 100;i ++) {
9 | //
10 | // System.out.println(getId() + " : " + i);
11 | // }
12 |
13 | try {
14 |
15 | Thread.sleep(5000L);
16 | } catch (InterruptedException e) {
17 |
18 | e.printStackTrace();
19 | }
20 | }
21 |
22 | public static void main(String[] args) {
23 |
24 | DaemonThread t1 = new DaemonThread();
25 | DaemonThread t2 = new DaemonThread();
26 |
27 | t1.setDaemon(true);
28 | t2.setDaemon(false);
29 |
30 | t1.start();
31 | t2.start();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/MainClass.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread;
2 |
3 | public class MainClass {
4 |
5 | public static void main(String[] args) {
6 |
7 | MyThread t1 = new MyThread();
8 | t1.setName("쓰레드 1");
9 | t1.setPriority(Thread.MAX_PRIORITY);
10 | t1.start();
11 |
12 | System.out.println("t1.getId() : " + t1.getId());
13 | System.out.println("t1.getName() : " + t1.getName());
14 |
15 | Runnable r1 = new MyRunnable();
16 | Thread t2 = new Thread(r1);
17 | t2.setPriority(Thread.MIN_PRIORITY);
18 | t2.start();
19 |
20 | System.out.println("t2.getId() : " + t2.getId());
21 |
22 | try {
23 | Thread.sleep(1000L);
24 | } catch (InterruptedException e) {
25 | e.getStackTrace();
26 | }
27 |
28 | for (int i = 0; i < 100;i ++) {
29 |
30 | System.out.println("Main : " + i);
31 | }
32 |
33 | System.out.println("t1.isAlive() : " + t1.isAlive());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/MyRunnable.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread;
2 |
3 | public class MyRunnable implements Runnable {
4 |
5 | @Override
6 | public void run() {
7 |
8 | for (int i = 0; i < 100;i ++) {
9 |
10 | System.out.println("Runnable : " + i);
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/MyThread.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread;
2 |
3 | public class MyThread extends Thread {
4 |
5 | @Override
6 | public void run() {
7 |
8 | for (int i = 0; i < 100;i ++) {
9 |
10 | System.out.println("Thread : " + i);
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/Stop.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread;
2 |
3 | public class Stop extends Thread {
4 |
5 | // @Override
6 | // public void run() {
7 | //
8 | // try {
9 | // Thread.sleep(Long.MAX_VALUE);
10 | // } catch (InterruptedException e) {
11 | // e.printStackTrace();
12 | // }
13 | // }
14 |
15 | @Override
16 | public void run() {
17 |
18 | while (true) {}
19 | }
20 |
21 | public static void main(String[] args) {
22 | Stop t1 = new Stop();
23 | t1.start();
24 | System.out.println("쓰레드를 시작했습니다.");
25 |
26 | try {
27 | Thread.sleep(1000L);
28 | } catch (InterruptedException e) {
29 | e.printStackTrace();
30 | }
31 |
32 | t1.interrupt();
33 | t1.stop();
34 | System.out.println("쓰레드를 종료했습니다.");
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/SyncThread.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread;
2 |
3 | public class SyncThread extends Thread {
4 |
5 | private int value;
6 |
7 | private Calculater calculater;
8 |
9 | public SyncThread (int value, Calculater calculater) {
10 | this.value = value;
11 | this.calculater = calculater;
12 | }
13 |
14 | @Override
15 | public void run() {
16 |
17 | for (int i = 0;i < 10000; i ++) {
18 |
19 | calculater.add(value);
20 | }
21 | }
22 |
23 | public static void main(String[] args) {
24 |
25 | Calculater calculater = new Calculater();
26 |
27 | SyncThread t1 = new SyncThread(1, calculater);
28 | t1.start();
29 |
30 | SyncThread t2 = new SyncThread(-1, calculater);
31 | t2.start();
32 |
33 | try {
34 |
35 | t1.join();
36 | t2.join();
37 | } catch (InterruptedException e) {
38 |
39 | e.printStackTrace();
40 | }
41 |
42 | System.out.println("sum : " + calculater.getSum());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/WaitThread.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread;
2 |
3 | import java.util.Scanner;
4 |
5 | public class WaitThread extends Thread {
6 |
7 | private Object object;
8 |
9 | public WaitThread (Object object) {
10 |
11 | this.object = object;
12 | }
13 |
14 | @Override
15 | public void run() {
16 |
17 | try {
18 | System.out.println(getId() + " 나를 깨워줘.");
19 | synchronized (object) {
20 | object.wait();
21 | }
22 | System.out.println(getId() + " 아 잘잤다");
23 | } catch (InterruptedException e) {
24 | e.printStackTrace();
25 | }
26 | }
27 |
28 | public static void main(String[] args) {
29 | Object object = new Object();
30 |
31 | WaitThread t1 = new WaitThread(object);
32 | t1.start();
33 |
34 | WaitThread t2 = new WaitThread(object);
35 | t2.start();
36 |
37 | Scanner scanner = new Scanner(System.in);
38 |
39 | scanner.nextLine();
40 |
41 | synchronized (object) {
42 | object.notify();
43 | }
44 |
45 | scanner.close();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/producerConsumer/Consumer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread.producerConsumer;
2 |
3 | import java.util.List;
4 | public class Consumer implements Runnable {
5 |
6 | private String name;
7 |
8 | private List list;
9 |
10 | private Object monitor;
11 |
12 | public Consumer(String name, List list, Object monitor) {
13 | this.name = name;
14 | this.list = list;
15 | this.monitor = monitor;
16 | }
17 |
18 | @Override
19 | public void run() {
20 |
21 | boolean flag = false;
22 |
23 | try {
24 |
25 | while (true) {
26 | synchronized (monitor) {
27 | monitor.wait();
28 | }
29 |
30 | synchronized (list) {
31 | if (list.size() > 0) {
32 | int value = list.remove(0);
33 | System.out.println(name + " : " + value);
34 | flag = true;
35 | }
36 | else {
37 | flag = false;
38 | }
39 | }
40 |
41 | if (flag) {
42 | Thread.sleep(3000L);
43 | }
44 |
45 | }
46 | } catch (InterruptedException e) {
47 | e.printStackTrace();
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/producerConsumer/Producer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread.producerConsumer;
2 |
3 | import java.util.List;
4 | import java.util.Random;
5 |
6 | public class Producer implements Runnable {
7 |
8 | private List list;
9 |
10 | private Object monitor;
11 |
12 | public Producer(List list, Object monitor) {
13 | this.list = list;
14 | this.monitor = monitor;
15 | }
16 |
17 |
18 | @Override
19 | public void run() {
20 | Random random = new Random(System.currentTimeMillis());
21 |
22 | long delay = 0;
23 |
24 | try {
25 | while (true) {
26 | delay = random.nextInt(1700) + 300L;
27 | Thread.sleep(delay);
28 |
29 | synchronized (list) {
30 | int value = random.nextInt(1000);
31 | System.out.println("생산 : " + value + " 재고 : " + list.size());
32 | list.add(value);
33 | }
34 |
35 | synchronized (monitor) {
36 | monitor.notifyAll();
37 | }
38 | }
39 |
40 | } catch (InterruptedException e) {
41 | e.printStackTrace();
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/src/kr/hs/dgsw/javaClass/thread/producerConsumer/ProducerConsumerDoer.java:
--------------------------------------------------------------------------------
1 | package kr.hs.dgsw.javaClass.thread.producerConsumer;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class ProducerConsumerDoer {
7 |
8 | public static void main(String[] args) {
9 |
10 | Object monitor = new Object();
11 | List list = new ArrayList();
12 |
13 | Producer producer = new Producer(list, monitor);
14 | Consumer consumer1 = new Consumer("1번", list, monitor);
15 | Consumer consumer2 = new Consumer("2번", list, monitor);
16 | Consumer consumer3 = new Consumer("3번", list, monitor);
17 |
18 | new Thread(producer).start();
19 | new Thread(consumer1).start();
20 | new Thread(consumer2).start();
21 | new Thread(consumer3).start();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/performance/makeStudent/student.java:
--------------------------------------------------------------------------------
1 | package performance.makeStudent;
2 |
3 | public class student {
4 |
5 | private int studentNum;
6 | private String name;
7 | private String phoneNum;
8 | private String email;
9 | private String address;
10 |
11 | public int getStudentNum() {
12 | return studentNum;
13 | }
14 |
15 | public void setStudentNum(int studentNum) {
16 | this.studentNum = studentNum;
17 | }
18 |
19 | public String getName() {
20 | return name;
21 | }
22 |
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 |
27 | public String getPhoneNum() {
28 | return phoneNum;
29 | }
30 |
31 | public void setPhoneNum(String phoneNum) {
32 | this.phoneNum = phoneNum;
33 | }
34 |
35 | public String getEmail() {
36 | return email;
37 | }
38 |
39 | public void setEmail(String email) {
40 | this.email = email;
41 | }
42 |
43 | public String getAddress() {
44 | return address;
45 | }
46 |
47 | public void setAddress(String address) {
48 | this.address = address;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------