언어/JAVA
-
자바스터디(1)언어/JAVA 2023. 10. 18. 01:00
1. 절차지향 to 객체지향 - 과거의 프로그래밍은 절차지향적이었다. 다른 말로 프로세스 지향적이었다. - 데이터를 조작하는 코드를 별도로 분리(함수 혹은 프로시저)로 쪼개고 각 프로시저들이 데이터를 조작하는 방식이다. - 각 프로시저는 다른 프로시저를 사용할 수 있고, 각 프로시저는 같은 데이터를 사용할 수 있다.(프로시저간 데이터 공유) ex) 평균 계산 프로그램 : 각 과목 점수 데이터 읽어서 합+평균구하기(함수1) -> 화면출력(함수2) 이때 각 프로시저는 데이터를 공유하는 방식 -> 데이터 중심적 구현 - 프로세스를 한눈에 볼 수 있다는 장점이 있지만 명백한 한계점이 존재한다. 1. 프로그램 규모가 커지면, 함수가 너무 많이 증가 2. 데이터 이름 의미 등등 변경이 생기면 함수를 하나씩 다 수정..
-
자바 네트워크 네트워크 입출력 (1) - TCP언어/JAVA 2023. 8. 22. 19:19
1. 네트워크 기초 - 네트워크는 여러 컴퓨터들을 통신 회선으로 연결하는 것 - LAN은 가정,회사,건물,특정 영역에 존재하는 컴퓨터 연결 - WAN은 LAN을 연결한 것이다. (WAN이 흔히 말하는 인터넷이다) - LAN과 LAN을 라우터가 연결 - 라우터와 LAN은 스위치로 연결 1.2 서버와 클라이언트 - 네트워크에서 유무선으로 컴퓨터가 연결되어 있다면, 실제로 데이터 주고받는 행위는 프로그램들이 한다. - 서비스를 제공하는 프로그램을 서버, 서비스 요청하는 프로그램을 클라이언트라 부른다. - 인터넷을 통해서 두 프로그램이 통신하기 위해서는 클라이언트가 서비스 요청, 서버는 처리 결과 응답으로 제공한다. 1.3 ip주소 - 컴퓨터의 고유주소이다. 컴퓨터마다 받는 것이 아니라, 네트워크 어답터(LAN..
-
Java - 일급컬렉션언어/JAVA 2023. 7. 25. 11:40
일급컬렉션이란 Collection을 Wrapping하면서, 그 외 다른 멤버 변수가 없는 상태 1.일급컬렉션 적용 규칙 - 일급컬렉션에는 컬렉션 외 다른 멤버변수 없어야한다. - 각 컬렉션은 자체로 포장돼 있음으로, 콜렉션과 관련된 동작 근거지가 마련됨 - 필터가 일급컬렉션 클래스에 일부가 된다. > 필터는 또한 스스로 함수 객체가 될 수 있다. Map map = new HashMap(); map.put("1","A"); //.. 이를 아래와 같이 클래스 안으로 묶음 public class GameRanking{ private Map ranks; public GameRanking(Map ranks){ this.ranks = ranks; } } List carList = new ArrayList(); pu..
-
Servlet-JSP MVC07 파일 수정하기언어/JAVA 2023. 7. 24. 21:23
- 파일 수정하기 - 파일 수정하기도 회원 가입시 첨부파일을 지정하는 것과 마찬가지로 - 파일 업로드하고 정보 수정 vs 파일 업로드 없이 정보 수정 - 파일 업로드하고 회원 정보 수정시 1. ajax로 먼저 파일을 업로드 시키고, 업로드 된 filename 콜백함수로 받아서 2. hidden타입 id= filename에 value를 return받은 filename으로 바꿔 둔 뒤에 3. 수정하기 누르면, 같이 넘어가도록 한다. 1. 뷰 쪽 수정 function update(){ if($("#file").val() != ''){ var formData = new FormData(); formData.append("file",$("input[name=file]")[0].files[0]); $.ajax({ ..
-
Java - File클래스언어/JAVA 2023. 7. 24. 12:27
- File은 기본적이면서도 가장 많이 사용되는 입출력 대상이다. - file클래스는 파일 혹은 디렉토리를 다룰 수 있도록 다양한 메서드를 정의하고 있다. 1. File클래스 생성자 * 파일과 디렉토리는 같은 방법으로 다룬다. * pathname에는 보통 경로까지 포함새서 지정해줘야하지만, 프로그램이 실행되는 위치와 파일의 위치가 같을 경우 파일명만 사용해도 된다. File f = new File(//path); File dir = new File(//path); //이미 존재하는 파일을 파일 객체로 참조시 File f = new File(//) //없는 파일을 생성할때 f.createNewFile(); *OutputStream에 경우 해당 스트림을 열고 파일을 쓸 때 파일이 없으면 생성해서 쓴다. (F..
-
스트림(2) - 중간 처리언어/JAVA 2023. 7. 14. 14:46
1. 요소 걸러내기(필터링) - 필터링을 위한 메서드는 distinct()와 filter()가 있다. - distinct()는 요소의 중복을 제거한다. >객체 스트림의 경우 equals메소드를 기준으로 판단한다. > IntStream,LongStream 등은 값의 중복을 제거한다. - filter()는 매개값인 Predicate가 true인 요소만 리턴한다. Predicate는 IntPredicate,LongPredicate,DoublePredicate등이 있다. (함수형 인터페이스임) (매개변수로 주어진 값을 통해 조건검사 - true나 false를 리턴하도록 람다식을 짜)[test()메서드] 2. 요소 변환(매핑) -매핑은 스트림을 다른 요소로 변환하는 중간 처리 기능을 한다. - mapXXX(), ..
-
스트림(1) - 스트림이란,리소스로 스트림 얻기언어/JAVA 2023. 7. 14. 13:50
1. 스트림이란? - java8부터 추가된 컬렉션 및 배열의 요소를 반복 처리하기 위해 등장. - 요소들이 하나씩 흘러가면서 처리된다는 의미를 가지고 있다. - 스티림을 통해 List를 반복처리하면 다음과 같다. Stream stream = list.stream(); stream.forEach(item -> //item처리); //StreamEx.ja public class StreamExample{ public static void main(String[] args){ Set set = new HashSet(); set.add("홍길동"); set.add("신용권"); set.add("김자바"); Stream stream = set.stream(); stream.forEach(System.out.pri..
-
- JavaNextStep - 숫자야구게임(1) - 단위테스트언어/JAVA 2023. 7. 10. 17:10
- 학습테스트 > 내가 만든 api를 테스트하는게 아니라, 다른 사람이 구현해 놓은 라이브러리가 어떻게 동작하는지 단위테스트를 통해 알아보는 것 학습테스트이다. > 새로운 라이브러리를 테스트 기반으로 할 수 있다. (빠르게 학습 가능해진다) > 학습 테스트를 통해 - 단위 테스트 방법 학습 - 단위 테스트 도구 사용법 익힐 수 있다. - 사용하는 API에 대한 학습 효과가 있다. 1. String 클래스에 대한 학습 테스트 1.1 요구사항 1에 대해 @DisplayName("split Test") @Test void splitTest(){ String[] input = "1,2".split(","); assertThat(input).contains("1","2"); } @Test void splitTes..