자바언어의 3가지 타입

※ 자바의 문자열 타입은 클래스 타입이지만 분리해서 설명합니다.

기본타입, 배열타입, 문자열 타입(String 클래스), 클래스 타입

 

기본타입

<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<html>
<body>
<%
	// 기본타입 변수
	byte a;
	short b;
	int c; // 정수
	long d; // 정수
	float e; // 부동소수점방식
	double f; // 실수
	char g; // 문자 한자
	boolean h; // true , false
	
	c = 10; // = 대입연산자 : 오른쪽값이 왼쪽으로 복사
	out.print(c+"<br>");
	d = 20;
	out.print(d+"<br>");
	f = 0.7;
	out.print(f+"<br>");
	g = 'a';
	out.print(g+"<br>");
	h = true;
	out.print(h+"<br>");

%>
</body>
</html>

문자열 타입

<%
	String str1 = new String("goodee"); // new 만들어진 새로운 메모리 공간의 참조값이 str1에 복사
	out.print(str1);
	out.print("<br>");
	
	String str2 = new String("goodee"); // new 만들어진 새로운 메모리 공간의 참조값이 str2에 복사
	out.print(str2);
	out.print("<br>");
	
	out.print(str1 == str2);
%>

배열타입

<%
	int[] arr = new int[3];
	out.print(arr);
	out.print("<br>");
	out.print(arr[0]); // 0
	out.print(arr[1]); // 0
	out.print(arr[2]); // 0
	arr[0] = 33;
	arr[1] = 44;
	arr[2] = 55;
	out.print(arr[0]); // 33
	out.print(arr[1]); // 44
	out.print(arr[2]); // 55
%>

클래스 타입

<%!
public class Student {
	public int age;
	public char gender;
	public boolean isJob;
}
%>

<%
	Student kht = new Student(); // age:0, char:'', isJob:false
	out.print(kht);
	out.print("<br>");
	kht.age = 23;
	kht.gender = 'M';
	kht.isJob = false;
	
	out.print(kht.age);
	out.print("<br>");
	out.print(kht.gender);
	out.print("<br>");
	out.print(kht.isJob);
	out.print("<br>");
%>

+ Recent posts