TIL (Today I Learned)

TIL) Oracle - Java Tutorial로 기본기 배우기

Won's log 2023. 5. 31. 23:57

TIL 기준

1. 어떤 문제가 있었는지

2. 내가 시도해 본 것들

3. 어떻게 해결했는지

4. 뭘 새롭게 알았는지

=문시해알

 

튜터님의 소개로 Oracle에서 제공하는 Java Tutorial을 알게 되었다

https://docs.oracle.com/javase/tutorial/java/concepts/index.html

 

Lesson: Object-Oriented Programming Concepts (The Java™ Tutorials > Learning the Java Language)

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See Java Language Changes for a summary of updated

docs.oracle.com

 

오늘은 1가지 문제에 봉착하여 이를 해결한 과정을 찾는 여정을 적었다

아주 기초적인 자바에 대해서 공부하였고 마지막에 문제를 푸는 과정에서 틀린 부분도 있어서 공유하고자 한다

 

[문제]

Questions and Exercises: Object-Oriented Programming Concepts

Questions

  1. Real-world objects contain ___ and ___.
  2. A software object's state is stored in ___.
  3. A software object's behavior is exposed through ___.
  4. Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data ___.
  5. A blueprint for a software object is called a ___.
  6. Common behavior can be defined in a ___ and inherited into a ___ using the ___ keyword.
  7. A collection of methods with no implementation is called an ___.
  8. A namespace that organizes classes and interfaces by functionality is called a ___.
  9. The term API stands for ___?

Exercises

  1. Create new classes for each real-world object that you observed at the beginning of this trail. Refer to the Bicycle class if you forget the required syntax.
  2. For each new class that you've created above, create an interface that defines its behavior, then require your class to implement it. Omit one or two methods and try compiling. What does the error look like?

[답안]

*붉은/검은 굵은 글씨가 답

*빨간 얋은 글씨는 틀린 답

 

Questions

1. Real-world objects contain state and behavior.

2. A software object's state is stored in Api application platfrom interface? fields.

3. A software object's behavior is exposed through methods.

4. Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data 못 적음 encapsulation.

5. A blueprint for a software object is called a Interface? class.

6. Common behavior can be defined in a Common class? superclass and inherited into a Mother class? subclass using the extends keyword.

7. A collection of methods with no implementation is called an 못 적음 interface.

8. A namespace that organizes classes and interfaces by functionality is called a Object? package.

9. The term API stands for Application platformed interface? Application Programming Interface.

Exercises

1. Public class changPedal;

Void chagnePedal(Va);

 

2.Public void class sportsbicycle implements bicycle

Void Chargespeed(speed);

speed= 100

Void Changepeddal(pedal);

Pedal = Nike

 

오늘의 문시해알은 내가 틀린 답을 다시 한 번 상기하고 특별히 Exercise 문제를 다시 공부하는 것으로 대체하고자 한다.

특별히 튜토리얼에서 제공한 예시를 그냥 다 암기하였다.

내 나름의 시도인데 솔직히 자바공부 3주차에 아직까지 클래스, 인터페이스, 추상 클래스가 너무 헷갈렸고 위기 신호라고 느껴졌다.

내가 자신있는 부분이 통암기이니 우선 클래스, 인터페이스를 통암기하고 그것을 내 것으로 다 만들어보고자 한다.

그래서 혹여 코딩테스트, 알고리즘 문제를 풀게 될 때 가벼운 것은 술술 나올 수 있도록 나를 단련할 것이다.

 

[외워버린 답안] -Class

// class
Class Bike {

int gear = 0;
    int speed = 0;
    int cadence = 0;
    
    void changeGear (int newValuee);
    gear = newValue;
    
    void speedUp(int increase);
    speed = speed + increase;
    
    void speedDown(int descendant);
    speed = speed + descendant;
    
    void changeCandence(int newValue);
    candence = newValue;
}

// two bikes
Class Bikedemo {

// main method를 빼먹었다

	Bike bike1 = new bike();
    Bike bike2 = new bike();
    
    bike1.changeGear(10);
    bike2.changeGear(20);
    
    bike1.changeCandence(30);
    bike2.changeCandence(40);
    
    bike1.speedUP(20);
    bike2.speedUP(30);
}

//////////////////////여기서부터는 외운 구간이 아니라서 더 암기할 예정////////////////////
// interface
Class MountainBike implements Bike {

	int speed = 0;
    int gear = 0;
    
}

interface Bike {

void changeGear(newValue); 
void chnageCandence(newValue);
void speedUP(increase);
void speedDown(descendant);
// (int) 포함하기
}