Back end/Java 기본
-
대입 연산자Back end/Java 기본 2023. 11. 14. 12:33
자바에서 대입 연산자(=)는 변수에 값을 할당하는 데 사용됩니다. 이 연산자를 통해 변수에 특정 값을 저장하거나 다른 변수의 값을 할당할 수 있습니다. package chap_02; public class _02_Operator2 { public static void main(String[] args) { // 대입 연산자 int num = 10; num = num + 2; System.out.println(num); // 12 num = num - 2; System.out.println(num); // 10 num = num * 2; System.out.println(num); // 20 num = num / 2; System.out.println(num); // 10 num = num % 2; Sys..
-
산술 연산자Back end/Java 기본 2023. 11. 14. 12:32
자바에서 산술 연산자는 기본적인 수학적 계산을 수행하는 연산자들입니다. 다양한 산술 연산자가 제공되며, 주로 숫자형 데이터 타입(int, double 등)에 대해 사용됩니다. 주요 산술 연산자는 다음과 같습니다: package chap_02; import java.time.temporal.ValueRange; public class _01_Operator1 { public static void main(String[] args) { // 산술 연산자 // 일반 연산 System.out.println(4 + 2); //6 System.out.println(4 - 2); //2 System.out.println(4 * 2); // 8 System.out.println(4 / 2 ); // 2 System.o..
-
형 변환Back end/Java 기본 2023. 11. 14. 12:30
형변환(Casting)은 변수나 값의 데이터 타입을 다른 데이터 타입으로 변경하는 과정을 말합니다. 자바에서는 크게 두 가지 형변환, 즉 명시적 형변환과 암시적 형변환이 있습니다. package chap_01; public class _07_TypeCasting { public static void main(String[] args) { // 형변환 TypeCasting // 정수형에서 실수형으로 // 실수형에서 정수형으로 // int to float, double int score = 93; System.out.println(score); // 93 System.out.println((float) score); // 93.0 System.out.println((double) score); // 93.0..
-
상수Back end/Java 기본 2023. 11. 14. 12:29
자바에서 상수(Constant)는 프로그램 내에서 값이 항상 고정되어 변하지 않는 변수를 의미합니다. 상수는 한 번 선언되면 그 값을 변경할 수 없으며, 주로 프로그램에서 변경되지 않아야 하는 값들을 표현하는 데 사용됩니다. 상수는 final 키워드를 사용하여 선언됩니다. package chap_01; // 상수는 대문자로 이름을 지어줘야함! public class _06_Constants { public static void main(String[] args) { final String KR_COUNTRY_CODE = "+82"; //국가 번호 (빨리) //KR_COUNTRY_CODE = "+8282"; System.out.println(KR_COUNTRY_CODE); final double PI = ..
-
변수 이름 짓는 법Back end/Java 기본 2023. 11. 14. 12:27
package chap_01; public class _05_VariableNaming { public static void main(String[] args) { // 변수 이름 짓는 법 // 1. 저장할 값에 어울리는 이름 // 2. 밑줄(_), 문자(abc), 숫자(123) 사용 가능 (공백 사용 불가) // 3. 밑줄 또는 문자로 시작 가능 // 4. 한 단어 또는 2개 이상 단어의 연속 // 5. 소문자로 시작, 각 단어의 시작 글자는 대문자로 (첫 단어는 제외) // 6. 예약어 사용 불가 (public, static, void , int, double, float, ...) // 입국 신고서(여행) String nationality = "대한민국"; // 국적 String firstName ..
-
주석Back end/Java 기본 2023. 11. 14. 12:27
자바에서 주석(Comment)은 소스 코드에 프로그램의 동작을 설명하거나 다른 개발자들과 소통하기 위해 추가되는 설명문입니다. 주석은 컴파일러에 의해 무시되기 때문에 프로그램 실행에는 아무런 영향을 주지 않습니다. 주석은 코드의 가독성을 높이고, 코드를 이해하거나 유지보수하는 데 도움이 됩니다. package chap_01; public class _04_Comment { public static void main(String[] args) { // System.out.println("(10분 전) 잠시 후 결혼식 시작 예정이오니 착석 부탁드립니다."); // System.out.println("(5분 전) 잠시 후 결혼식 시작 예정이오니 착석 부탁드립니다."); System.out.println("지금..
-
변수?Back end/Java 기본 2023. 11. 14. 12:26
자바에서 변수(Variable)는 데이터를 저장하기 위한 메모리 공간의 이름이라고 할 수 있습니다. 변수는 프로그램에서 사용되는 값이나 객체를 참조하거나 저장하는 데에 이용됩니다. 변수는 그 값을 나타내는 데이터의 유형에 따라 다양한 자료형을 가질 수 있습니다. 자바에서 변수를 선언할 때는 다음과 같은 구문을 사용합니다 package chap_01; public class _03_Variables { public static void main(String[] args) { String name = "나도코딩"; int hour = 15; System.out.println(name + "님, 배송이 시작됩니다." + hour +"시에 방문 예정 입니다."); System.out.println(name + ..
-
자료형Back end/Java 기본 2023. 11. 14. 12:24
자바(Java)는 정적 타입 언어로서, 변수를 선언할 때 해당 변수의 데이터 타입을 명시적으로 지정해야 합니다. 이것이 자바에서의 "자료형" 개념입니다. 자바의 자료형은 크게 기본 자료형(Primitive Data Types)과 참조 자료형(Reference Data Types)으로 나뉩니다. package chap_01; public class _02_DataTypes { public static void main(String[] args) { System.out.println("Hello World"); System.out.println("안녕하세요?"); System.out.println(12); System.out.println(-34); System.out.println(3.14); System..