본문 바로가기

Programming/Java, Spring98

[Java 기초문법] 자바 쓰레드, thread 상속 받기, runnable 인터페이스 [Java 기초문법] by Programmers school 자바 입문 Thread 클래스를 상속받기 java.langThread 클래스를 상속받고 run() 메소드를 오버라이딩 한다. public class Mythread extends Thread{ @Override public void run(){ super.run(); } } String 메소드를 만들고 run에서 이를 10번 출력하게 해보자. 출력이 너무 빠르기 때문에 텀을 준다. @Override public void run(){ for (int i = 0; i < 10; i++){ System.out.println(str); try { Thread.sleep((int) Math.random()*1000); } catch (Interrupte.. 2022. 10. 21.
[Java 기초문법] 시간 관련 메서드, Date, Calendar, java.time 패키지 [Java 기초문법] by Programmers school 자바 중급 Date import java.text.SimpleDateFormat; import java.util.*; public class Car { public static void main(String[] args) { Date date = new Date(); System.out.println(date.toString()); SimpleDateFormat ft = new SimpleDateFormat ("yyyy.MM.dd 'at' hh:mm:ss a zzz"); System.out.println(ft.format(date)); System.out.println(date.getTime()); // System이 가지고 있는 current.. 2022. 10. 21.
[Java 기초문법] Collections, Set, Hashset, Treeset, List, Map [Java 기초문법] by Programmers school 자바 중급 Set set은 중복이 없고 순서도 없다. Hashser과 Treeset이 있다. import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Car { public static void main(String[] args) { Set set1 = new HashSet(); boolean flag1 = set1.add("kim"); boolean flag2 = set1.add("lee"); boolean flag3 = set1.add("kim"); System.out.println(set1.size()); //저장된 크기를 출력합니다. 3개.. 2022. 10. 21.
[Java 기초문법] 문자열 비교하기 , 필드, 메소드, 변수의 scope와 static, 열거형 (enum) [Java 기초문법] by Programmers school 자바 입문 문자열 비교하기 각 인스턴스가 같은 값을 저장한다고 해서 두 인스턴스가 같은 건 아니다. public class CarExam { public static void main(String[] args) { String str1 = new String("Hello world"); String str2 = new String("Hello world"); if(str1 == str2){ System.out.println("str1과 str2는 같은 인스턴스를 참조합니다."); } else{ System.out.println("str1과 str2는 다른 인스턴스를 참조합니다."); } } } 필드 자바에서는 속성을 필드로 선언할 수 있다. 필.. 2022. 10. 21.
[Java 기초문법] Generic usage case [Java 기초문법] by Professional Java Developer Career Starter: Java Foundations @ Udemy In general, generics allow us to kind of constrain what types of data we can associate with a class. We can use generics on methods and things that return data types as well. And also they can protect us from certain types of runtime errors because if you're not using generics, but you're working with code that i.. 2022. 10. 21.