finerss's world!

JAVA Level Up

공부/JAVA2015. 8. 20. 16:29

★키워드 : 클래스명이나 변수명으로 사용할 수 있는 것, 없는것 규칙(java 기본문법)

 

Q) 다음 중 변수 선언 문법에 맞는 것을 모두 고르시오?
a. 2variable
b. variable2
c. _whatabariable
d. _3_
e. $anothervar
f. #myvar

 

A) b,c,d,e


[설명]
- 대소문자가 구분되며, 길이에 제한이 없다.
- 예약어를 사용해서는 안 된다.
- 숫자로 시작해서는 안된다.
- 특수문자는 '_' 와 '$' 만 사용할 수 있다.


Q) 다음 중 변수 선언 문법에 틀린 것을 모두 고르시오?
a. volatile
b. _this
c. const
d. Void
e. integer
f. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

 

A) a,c


[설명]
Volatile(객체내에 필드를 동기적 목적으로 사용할것을 알리는 목적), const(상수 선언)는 예약어다

 

[참고] 자바 키워드

abstract   continue   for   new   switch
assert  default  goto  package  synchronized
boolean   do   if   private   this
break   double   implements   protected throw
byte   else   import   public   throws
case   enum   instanceof   return   transient
catch   extends   int   short try
cha  r final   interface   static   void
class   finally   long   strictfp   volatile
const   float   native   super   while

 

 

Q) 다음 중 변수 선언 문법에 틀린 것은?(1개)
a. Synchronized
b. variable2
c. _whatabariable
d. synchronize
e. True
f. goto

 

A) f


[설명]
goto는 java에서 사용할 수 없지만 예약어로 되어있다.

 

 

★키워드 : java Primitive Data Type 에대한 이해

 

Q) 자바 데이터타입은 크게 프리미티브 타입(Primitive Type)과 레퍼런스 타입(Reference Type)으로 구분됩니다. 다음 중 프리미티브 타입이 아닌것은?
1. String
2. byte
3. short
4. boolean

 

A) 1


[설명]
자바의 기본 Primitive Type 8가지를 제외하면 모두 객체다.
기본형인 Primitive Type에는 8가지가 있습니다.
- byte, boolean, short, char, int, float, long, double

 

[참고] 자바 데이터 타입

자바 데이터 타입의 분류 체계도

자바에서 variable의 데이터 타입에 primitive 와 reference type이 존재 한다.
primitive type은 언어에서 사전 정의 되어 있는 데이터 타입이다.
반면 reference type은 primitive type의 wrapper객체로서 object를 상속한 객체형으로 나타난다.
프로그래밍시 둘의 차이점은 reference타입의 Integer나 Double등은 오브젝트로서 가공이 용이 한 반면 단순 대입시에 좀 불편하다.
primitive 타입의 경우 단순 연산에는 좋으나 복잡한 데이터 가공시에 어려움이 있다는 차이점이 있다.

 

<프리미티브 타입의 데이터 표현을 위해 사용되는 메모리>
구분 데이터 타입 사용 메모리 크기
정수 타입 byte 1바이트
short 2바이트
int 4바이트
long 8바이트
char 2바이트
부동소수점 타입 float 4바이트
double 8바이트
불리언 타입 boolean * 정해져 있지 않음

*프리미티브 타입의 데이터 표현을 위해 사용되는 메모리와 같이 데이터 타입마다 사용하는 메모리의 크기는 정해져 있다.