프로그래머스 - 핸드폰 번호 가리기 Java
·
코테 문제 풀이/프로그래머스
문제 설명프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.제한 조건phone_number는 길이 4 이상, 20이하인 문자열입니다. class Solution { public String solution(String phone_number) { int len = phone_number.length(); String answer = phone_number.substring(0, len-4).replaceAll("\\d","*") ..
Spring의 JPA와 Entity 이해하기
·
Spring
👇🏻 이전 글2024.08.06 - [Spring] - Spring의 IoC(제어의 역전), DI(의존성 주입) 이해하기  ORM과 JPA ORM : Object-Relational Mapping 객체와 데이터베이스를 매핑해주는 도구  JPA는 자바 ORM 중 대표적인 표준 명세이다.JPA는 애플리케이션과 JDBC 사이에서 동작되며 DB 연결 과정을 자동으로 처리해주고, 객체를 통해 간접적으로 DB 데이터를 다룰 수 있어 DB 작업을 보다 쉽게 처리 할 수 있다.  Entity Entity란 JPA에서 관리되는 객체. Entity는 DB의 테이블과 매핑되어 JPA에 의해 관리 됨. Memo Entity@Entity // JPA가 관리할 수 있는 Entity 클래스 지정@Table(name = "mem..
Spring의 IoC(제어의 역전), DI(의존성 주입) 이해하기
·
Spring
👇🏻이전 글2024.08.06 - [Spring] - Spring을 3 Layer Architecture로 역할 분리하기 IoC(제어의 역전)와 DI(의존성 주입)란? 좋은 코드, 즉 중복을 제거하고 표현이 명확한 코드, 처음 보는 사람도 쉽게 이해하고 수정할 수 있는 코드, 새로운 기능을 추가하더라도 구조에 큰 변화가 없는 코드를 만들기 위해서는 결합도와 의존성을 최소화 해야 한다.메모장 프로젝트 속 제어의 흐름은 Controller → Service → Repository 순서로 흐르게 되는데 이 때문에 한 부분에서의 코드 추가나 수정이 연쇄적으로 다른 부분들과도 이어져 개발에 있어 피로함과 비효율성을 일으킨다. 의존성 주입을 사용해 역순으로 흐르게 하면 결합도와 의존성이 최소화되어 이러한 문제를..
Spring을 3 Layer Architecture로 역할 분리하기
·
Spring
👇🏻 이전 글2024.08.05 - [Spring] - Spring과 MySQL로 CRUD 기능이 있는 메모장 만들기 Spring 프로젝트를 3 Layer Architecture로 역할 분리하기 3 Layer Architecture 란 처리 과정을 크게 Controller, Service, Repository 로 나누는 것을 뜻함.Controller : 클라이언트에서 온 요청을 받아 Service로 넘겨주고 처리 완료된 결과를 클라이언트에게 보여주는 역할Service : 사용자의 요구 사항을 처리. 비즈니스 로직 구현하는 곳. DB 저장 및 조회가 필요한 경우 Repository에 요청.Repository : DB 관리. CRUD 작업 처리.  Controller에서 Service 분리하기 Contr..
Spring과 MySQL로 CRUD 기능이 있는 메모장 만들기
·
Spring
스파르타 코딩의 를 수강하며 스프링 입문 강의에 나와있는 메모장 프로젝트에 대해 정리. MySQL 설치 및 Spring 프로젝트에 연결 후 테이블 생성하기https://dev.mysql.com/downloads/mysql/ 접속 후 자신의 OS에 맞는 버전을 다운 받아 설치터미널을 열어  cd /usr/local/mysql/bin  입력하여 위치로 이동  ./mysql -u root -p  입력 후  MySQL 설치 시 설정한 비밀 번호로 접속 CREATE DATABASE memo;  로 memo 테이블 생성 후  show databases;  명령어로 잘 생성되었는지 확인Intellij 오른쪽 상단의 DB 누른 후 + 버튼 → Data Source → MySQL 선택 → DB 아이디와 비밀번호 및 테..
Java 정리 4
·
JAVA
Properties and actions Classes and instances are two important object-oriented programming concepts. In fact, "instance" is another name for an object and a "class" is a blueprint of an instance An instance has a properties and actions and we define them in a class. Creating instances we create an instance from a class as follow : new ClassName( ); ex ) class Main { public static void main(Strin..
Java 정리 3
·
JAVA
Using methods : a method is a section of code to which we assign a specific task. ex ) class Main { public static void main(String[] args) { hello(); //Hello method is called } public static void hello() { System.out.println("Hello World"); } } Colored by Color Scripter cs If you define a method outside of a class, there will be an error. To call a method, just write methodName( ) An argument is..
JAVA 정리 2
·
JAVA
Boolean can only be either true or false. Do not use double quotes. && = and, || = or Control flow class Main { public static void main(String[] args) { System.out.println("Hello Java"); if(condition) { //Run this code; } else if (condition) { //Run this code; } else { //Run this code; } } } Colored by Color Scripter cs Switch statements. class Main { public static void main(String[] args) { Sys..