1.1 パッケージとは

1.1㻌 䝟䝑䜿䞊䝆䛸䛿
㻝㻚㻝
ࣃࢵࢣ࣮ࢪ࡜ࡣ
ࣃࢵࢣ࣮ࢪࡣࠊ」ᩘࡢࢡࣛࢫࢆࢢ࣮ࣝࣉ໬ࡋࡓࡶࡢ࡛ࡍࠋࣃࢵࢣ࣮ࢪࢆ฼⏝ࡍࡿ୺࡞࣓ࣜࢵࢺ
ࡣḟࡢ㏻ࡾ࡛ࡍࠋ
͑ ࢡࣛࢫࢆᙺ๭ࡈ࡜࡟ࡲ࡜ࡵࠊࢡࣛࢫࡢព࿡ࢆࢃ࠿ࡾࡸࡍࡃࡍࡿ
͑ ࣃࢵࢣ࣮ࢪࡈ࡜࡟ࢡࣛࢫྡࢆ⟶⌮࡛ࡁࡿࡢ࡛ࠊࢡࣛࢫྡࡀࡘࡅࡸࡍࡃ࡞ࡿ
͑ ࣃࢵࢣ࣮ࢪ༢఩࡟࢔ࢡࢭࢫไᚚ࡛ࡁࡿ
௨ୗࡢࢧࣥࣉࣝࣉࣟࢢ࣒࡛ࣛࠊࣃࢵࢣ࣮ࢪࡢᐃ⩏᪉ἲ࡜౑࠸᪉ࢆ☜ㄆࡋࡲࡋࡻ࠺ࠋ
䖃
ࢧࣥࣉࣝࣉࣟࢢ࣒ࣛࡢᴫせ
WHVW ࣃࢵࢣ࣮ࢪࡢ 8VH7HVW3DFNDJH ࢡࣛࢫ࡜ WHVWVDPSOH ࣃࢵࢣ࣮ࢪࡢ 7HVW3DFNDJH ࢡࣛࢫࢆ
౑࠸ࠊ࣓ࢵࢭ࣮ࢪࢆ⾲♧ࡋࡲࡍࠋ
䖃
ࢥࣥࣃ࢖࣭ࣝᐇ⾜⤖ᯝ
!MDYDFG7HVW3DFNDJHMDYD
!MDYDFG8VH7HVW3DFNDJHMDYD
!MDYDWHVW8VH7HVW3DFNDJH
7KLVLVWHVWPHVVDJH
3
➨ 1 ❶㻌 Java 䛾䝷䜲䝤䝷䝸
䖃
ࢯ࣮ࢫࣉࣟࢢ࣒ࣛ
7HVW3DFNDJHMDYD
㸸 WHVWVDPSOH࡟ࣃࢵࢣ࣮ࢪ໬
㸸 SDFNDJHWHVWVDPSOH
㸸 㸸 7HVW3DFNDJHࢡࣛࢫࡢᐃ⩏
㸸 SXEOLFFODVV7HVW3DFNDJH^
㸸 SXEOLFVWDWLFYRLGSULQW0HVVDJH ^
㸸 6\VWHPRXWSULQWOQ 7KLVLVWHVWPHVVDJH 㸸 `
㸸 `
8VH7HVW3DFNDJHMDYD
㸸 WHVW࡟ࣃࢵࢣ࣮ࢪ໬
㸸 SDFNDJHWHVW
㸸 㸸 7HVW3DFNDJHࢡࣛࢫࢆ࢖࣏࣮ࣥࢺ
㸸 LPSRUWWHVWVDPSOH7HVW3DFNDJH
㸸 㸸 8VH7HVW3DFNDJHࢡࣛࢫࡢᐃ⩏
㸸 SXEOLFFODVV8VH7HVW3DFNDJH^
㸸 SXEOLFVWDWLFYRLGPDLQ 6WULQJ>@DUJV ^
㸸 7HVW3DFNDJHࢡࣛࢫࡢ࣓ࢯࢵࢻ࿧ࡧฟࡋ
㸸 7HVW3DFNDJHSULQW0HVVDJH 㸸 `
㸸 `
4
1.1㻌 䝟䝑䜿䞊䝆䛸䛿
㻝㻚㻝㻚㻝
ࣃࢵࢣ࣮ࢪࡢᐃ⩏㻌
ࢡࣛࢫࢆࣃࢵࢣ࣮ࢪ໬ࡍࡿ࡟ࡣࠊSDFNDJH ᩥࢆ౑⏝ࡋࡲࡍࠋ
࠙ࣃࢵࢣ࣮ࢪࡢᣦᐃࠚ
SDFNDJHࣃࢵࢣ࣮ࢪྡ
SDFNDJH ᩥࡢグ㏙࡟ࡣࠊḟࡢ࣮ࣝࣝࡀ࠶ࡾࡲࡍࠋ
͑
SDFNDJHᩥࡣࢯ࣮ࢫࣇ࢓࢖ࣝࡢඛ㢌࡟グ㏙ࡍࡿ
͑
ࡘࡢࢯ࣮ࢫࣇ࢓࢖ࣝ࡟SDFNDJHᩥࡣࡘࡋ࠿ᣦᐃ࡛ࡁ࡞࠸
7HVW3DFNDJHMDYD㸦ᢤ⢋㸧
WHVWVDPSOH࡟ࣃࢵࢣ࣮ࢪ໬
SDFNDJHWHVWVDPSOH
7HVW3DFNDJHࢡࣛࢫࡢᐃ⩏
SXEOLFFODVV7HVW3DFNDJH^
䝁䞊䝕䜱䞁䜾つ⣙
ࣃࢵࢣ࣮ࢪྡ
࣭ࣃࢵࢣ࣮ࢪྡࡣࡍ࡭࡚ᑠᩥᏐ࡟ࡍࡿ
࣭࢖ࣥࢱ࣮ࢿࢵࢺࢻ࣓࢖ࣥࢆ㏫࡟ࡋࡓࡶࡢࢆࣃࢵࢣ࣮ࢪྡࡢඛ㢌࡟ࡘࡅࡿ
౛㸧࢖ࣥࢱ࣮ࢿࢵࢺࢻ࣓࢖ࣥࡀࠕQHFFRPࠖࡢሙྜ
SDFNDJHFRPQHF[[[
5
➨ 1 ❶㻌 Java 䛾䝷䜲䝤䝷䝸
㻝㻚㻝㻚㻞
ࣃࢵࢣ࣮ࢪ໬ࡋࡓࢡࣛࢫࡢࢥࣥࣃ࢖ࣝ㻌
ࣃࢵࢣ࣮ࢪ໬ࡋࡓࢡࣛࢫࡢࢡࣛࢫࣇ࢓࢖ࣝࡣࠊࣃࢵࢣ࣮ࢪྡ࡟ᑐᛂࡍࡿࣇ࢛ࣝࢲ࡟㓄⨨ࡋࡲࡍࠋ
‫ࢪ࣮ࢣࢵࣃڦ‬໬ࡋࡓࢡࣛࢫࡢ㓄⨨ࣇ࢛ࣝࢲ
䝟䝑䜿䞊䝆
䝹䞊䝖
SDFNDJHWHVWVDPSOH
FODVV7HVW3DFNDJH^
㸸
`
test
TestPackage.java
䝁䞁䝟䜲䝹
㓄⨨
sample
TestPackage.class
TestPackage.class
MDYDF ࢥ࣐ࣥࢻ࡟G ࢜ࣉࢩࣙࣥࢆࡘࡅ࡚ࢥࣥࣃ࢖ࣝࡍࡿ࡜ࠊḟࡢసᴗࢆ⮬ື໬࡛ࡁࡲࡍࠋ
ࣃࢵࢣ࣮ࢪࡢ࣮ࣝࢺࣇ࢛ࣝࢲ࡟ࣃࢵࢣ࣮ࢪྡ࡟ᑐᛂࡋࡓࣇ࢛ࣝࢲࢆసᡂࡍࡿ
ࣃࢵࢣ࣮ࢪྡ࡟ᑐᛂࡋࡓࣇ࢛ࣝࢲࡀᏑᅾࡍࡿሙྜࡣఱࡶ⾜ࢃ࡞࠸
ࢡࣛࢫࣇ࢓࢖ࣝࢆ⏕ᡂࡋࠊࣃࢵࢣ࣮ࢪྡ࡟ᑐᛂࡋࡓࣇ࢛ࣝࢲ࡟㓄⨨ࡍࡿ
G ࢜ࣉࢩࣙࣥࢆᣦᐃࡋࡓሙྜࡢ MDYDF ࢥ࣐ࣥࢻࡢ᭩ᘧࡣḟࡢ㏻ࡾ࡛ࡍࠋ
࠙G ࢜ࣉࢩࣙࣥࠚ
!MDYDFGࣃࢵࢣ࣮ࢪࡢ࣮ࣝࢺࣇ࢛ࣝࢲࢯ࣮ࢫࣇ࢓࢖ࣝྡ
6
1.1㻌 䝟䝑䜿䞊䝆䛸䛿
㻝㻚㻝㻚㻟
ࣃࢵࢣ࣮ࢪ໬ࡋࡓࢡࣛࢫࡢ࢖࣏࣮ࣥࢺ㻌
ࣃࢵࢣ࣮ࢪ໬ࡋࡓࢡࣛࢫࢆูࡢࣃࢵࢣ࣮ࢪࡢࢡࣛࢫࡀ฼⏝ࡍࡿሙྜࡣࠊ
ࢡࣛࢫྡࡢ๓࡟ࣃࢵࢣ
࣮ࢪྡࢆ௜ࡅࡲࡍࠋࣃࢵࢣ࣮ࢪྡ࡜ࢡࣛࢫྡࡢ㛫࡟ࡣ༊ษࡾ࡜ࡋ࡚ࠕࠖࢆධࢀࡲࡍࠋ౛࠼ࡤࠊ
WHVWVDPSOH ࣃࢵࢣ࣮ࢪࡢ 7HVW3DFNDJH ࢡࣛࢫࡣࠕWHVWVDPSOH7HVW3DFNDJHࠖ࡜ᣦᐃࡋࡲࡍࠋ
ࣃࢵࢣ࣮ࢪྡࢆ௜ࡅࡓࢡࣛࢫྡࢆ᏶඲ಟ㣭ࢡࣛࢫྡ࡜࠸࠸ࡲࡍࠋ
᏶඲ಟ㣭ࢡࣛࢫྡࢆ⏝࠸ࡿ࡜ࠊࣉࣟࢢ࣒ࣛࡀ㛗ࡃ࡞ࡾࠊㄞࡳ࡟ࡃࡃ࡞ࡾࡲࡍࠋࡇࡢࡼ࠺࡞ሙྜ
ࡣࠊLPSRUW ᩥࢆ౑⏝ࡋࡲࡍࠋLPSRUW ᩥࡣࠊࣃࢵࢣ࣮ࢪྡ࡞ࡋ࡛௚ࡢࣃࢵࢣ࣮ࢪࡢࢡࣛࢫࢆ฼⏝
࡛ࡁࡿࡼ࠺࡟ࡋࡲࡍࠋ
࠙ࣃࢵࢣ࣮ࢪ໬ࡋࡓࢡࣛࢫࡢ࢖࣏࣮ࣥࢺࠚ
LPSRUWࣃࢵࢣ࣮ࢪྡࢡࣛࢫྡ
WHVWVDPSOHࣃࢵࢣ࣮ࢪࡢ$ࢡࣛࢫࢆ࢖࣏࣮ࣥࢺ
LPSRUWWHVWVDPSOH$
FODVV8VH,PSRUW^
SXEOLFYRLGIXQF ^
$D QHZ$ ࢖࣏࣮ࣥࢺࡋࡓࢡࣛࢫ
WHVWVDPSOH%E QHZWHVWVDPSOH% ࢖࣏࣮ࣥࢺࡋ࡚࠸࡞࠸ࢡࣛࢫ
WHVWVDPSOH&F QHZWHVWVDPSOH& ࢖࣏࣮ࣥࢺࡋ࡚࠸࡞࠸ࢡࣛࢫ
ࣃࢵࢣ࣮ࢪ࡟ྵࡲࢀࡿࡍ࡭࡚ࡢࢡࣛࢫࢆ࢖࣏࣮ࣥࢺࡍࡿሙྜࡣࠊLPSRUW ᩥࡢࢡࣛࢫྡࡢ㒊ศ
࡟ࠕ ࠖࢆᣦᐃࡋࡲࡍࠋ
࠙ࣃࢵࢣ࣮ࢪ࡟ྵࡲࢀࡿࡍ࡭࡚ࡢࢡࣛࢫࢆ࢖࣏࣮ࣥࢺࠚ
LPSRUWࣃࢵࢣ࣮ࢪྡ WHVWVDPSOHࣃࢵࢣ࣮ࢪࡢ඲ࢡࣛࢫࢆ࢖࣏࣮ࣥࢺ
LPSRUWWHVWVDPSOH FODVV8VH,PSRUW^
SXEOLFYRLGIXQF ^
$D QHZ$ %E QHZ% &F QHZ& 7
➨ 1 ❶㻌 Java 䛾䝷䜲䝤䝷䝸
㻝㻚㻞
ᶆ‽ࣛ࢖ࣈࣛࣜ
ᶆ‽ࣛ࢖ࣈࣛࣜ࡜ࡣࠊ-DYD ࡛࠶ࡽ࠿ࡌࡵᐃ⩏ࡋ࡚࠸ࡿࢡࣛࢫࣛ࢖ࣈ࡛ࣛࣜࡍࠋᶆ‽ࣛ࢖ࣈࣛ
ࣜࢆ౑⏝ࡍࡿ࡜ࠊࢹ࢕ࢫࣉࣞ࢖࡬ࡢฟຊࡸᩥᏐิ᧯సࠊ'% 㐃ᦠ࡞࡝ࡢฎ⌮ࢆ⡆༢࡟グ㏙࡛ࡁࡲ
ࡍࠋ
㻝㻚㻞㻚㻝
௦⾲ⓗ࡞ࣃࢵࢣ࣮ࢪ㻌
-DYD ࡢᶆ‽ࣛ࢖ࣈࣛࣜࡣࠊྠࡌᙺ๭ࡸ┠ⓗࢆᣢࡗࡓࢡࣛࢫࡸ࢖ࣥࢱࣇ࢙࣮ࢫࢆ ࡘ࡟ࡲ࡜ࡵ
࡚ࣃࢵࢣ࣮ࢪ໬ࡋ࡚࠸ࡲࡍࠋࡇࡇ࡛ࡣࠊ௦⾲ⓗ࡞ࣃࢵࢣ࣮ࢪࢆ⤂௓ࡋࡲࡍࠋ
ࣃࢵࢣ࣮ࢪྡ
MDYDODQJ
ㄝ᫂
ᩥᏐิࡢ᧯సࡸࢩࢫࢸ࣒࣮࣮࢜࣌ࣞࢩࣙࣥ࡞࡝ࠊᇶᮏⓗ࡞ᶵ⬟ࢆᢅ࠺ࢡࣛ
ࢫࢆᥦ౪ࡍࡿࠋ
MDYDXWLO
ࢥࣞࢡࢩࣙࣥࣇ࣮࣒࣮ࣞ࣡ࢡࠊ࢖࣋ࣥࢺࣔࢹࣝࠊ᪥᫬ᶵ⬟ࠊᅜ㝿໬ࠊ࠾ࡼ
ࡧࡉࡲࡊࡲ࡞࣮ࣘࢸ࢕ࣜࢸ࢕ࢡࣛࢫࢆᥦ౪ࡍࡿࠋ
MDYDLR
ࢫࢺ࣮࣒ࣜࠊ┤ิ໬ࠊධฟຊ࡟౑⏝ࡍࡿࢡࣛࢫࢆᥦ౪ࡍࡿࠋ
MDYDVTO
ࢹ࣮ࢱࢯ࣮ࢫ ㏻ᖖࡣ࣮ࣜࣞࢩࣙࢼࣝࢹ࣮ࢱ࣮࣋ࢫ ࡢࢹ࣮ࢱࢆᢅ࠺ࢡࣛ
ࢫࢆᥦ౪ࡍࡿࠋ
MDYDDZW
࣮ࣘࢨ࢖ࣥࢱࣇ࢙࣮ࢫࡢసᡂཬࡧࢢࣛࣇ࢕ࢵࢡࢫ࡜࢖࣓࣮ࢪࡢ࣌࢖ࣥࢺ⏝
ࢡࣛࢫࢆᥦ౪ࡍࡿࠋ
MDYDQHW
ࢿࢵࢺ࣮࣡ࢡᶵ⬟ࢆᢅ࠺ࢡࣛࢫࢆᥦ౪ࡍࡿࠋ
8
1.2㻌 ᶆ‽䝷䜲䝤䝷䝸
㻝㻚㻞㻚㻞
㻭㻼㻵ࢻ࣓࢟ࣗࣥࢺ㻌
ᶆ‽ࣛ࢖ࣈࣛࣜࡢࢡࣛࢫࢆ౑࠸ࡇ࡞ࡍ࡟ࡣࠊࢡࣛࢫࡀᣢࡘ࣓ࢯࢵࢻࡸࣇ࢕࣮ࣝࢻࡢ௙ᵝ㸦$3,
௙ᵝ㸧ࢆ▱ࡿᚲせࡀ࠶ࡾࡲࡍࠋᶆ‽ࣛ࢖ࣈࣛࣜࡢ $3, ௙ᵝࡣ $3, ࢻ࣓࢟ࣗࣥࢺ࡜ࡋ࡚⏝ពࡉࢀ࡚
࠸ࡲࡍࠋ
$3, ࢻ࣓࢟ࣗࣥࢺࡣࢡࣛࢫࡸ࢖ࣥࢱࣇ࢙࣮ࢫࡢ௙ᵝࢆࡲ࡜ࡵࡓ +70/ ᙧᘧࡢࢻ࣓࢟ࣗࣥࢺ࡛ࡍࠋ
ࡇࡢࢻ࣓࢟ࣗࣥࢺࢆ฼⏝ࡍࡿ࡜ࠊᶆ‽ࣛ࢖ࣈࣛࣜࡢࢡࣛࢫࡸ࢖ࣥࢱࣇ࢙࣮ࢫࡢヲ⣽ࢆㄪ࡭ࡽࢀࡲ
ࡍࠋࡇࡇ࡛ࡣࠊ$3, ࢻ࣓࢟ࣗࣥࢺࡢཧ↷᪉ἲࢆ⤂௓ࡋࡲࡍࠋ
௨ୗࡣࠊ$3, ࢻ࣓࢟ࣗࣥࢺࡢ⏬㠃࡛ࡍࠋ
85/KWWSGRFVRUDFOHFRPMDYDVHMSDSL
䐟
䐡
䐠
ձ
ղ
ճ
ࣃࢵࢣ࣮ࢪࣇ࣮࣒ࣞ
ࣃࢵࢣ࣮ࢪࡢ୍ぴࡀ⾲♧ࡉࢀ࡚࠸ࡿࠋㄪ࡭ࡓ࠸ࢡࣛࢫࠊ࢖ࣥࢱࣇ࢙࣮ࢫࢆྵࡴࣃࢵࢣ࣮
ࢪࢆ㑅ᢥࡍࡿࠋ
ࢡࣛࢫࣇ࣮࣒ࣞ
ձ࡛㑅ᢥࡋࡓࣃࢵࢣ࣮ࢪ࡟ྵࡲࢀࡿࢡࣛࢫࠊ࢖ࣥࢱࣇ࢙࣮ࢫࡢ୍ぴࡀ⾲♧ࡉࢀࡿࠋ㉳ື
᫬ࡣࡍ࡭࡚ࡢࢡࣛࢫࠊ࢖ࣥࢱࣇ࢙࣮ࢫࡀ⾲♧ࡉࢀ࡚࠸ࡿࠋㄪ࡭ࡓ࠸ࢡࣛࢫࢆ㑅ᢥࡍࡿࠋ
ࢡࣛࢫࢹ࣮ࢱࣇ࣮࣒ࣞ
ղ࡛㑅ᢥࡋࡓࢡࣛࢫࠊ࢖ࣥࢱࣇ࢙࣮ࢫࡢヲ⣽࡞ㄝ᫂ࡀ⾲♧ࡉࢀࡿࠋ㉳ື᫬ࡣࣃࢵࢣ࣮ࢪ
ࡢㄝ᫂ࡀ⾲♧ࡉࢀ࡚࠸ࡿࠋ
9
➨ 1 ❶㻌 Java 䛾䝷䜲䝤䝷䝸
㻝㻚㻟
MDYDODQJࣃࢵࢣ࣮ࢪ
MDYDODQJ ࣃࢵࢣ࣮ࢪࡣᇶᮏⓗ࡞ࢡࣛࢫࢆᥦ౪ࡍࡿࣃࢵࢣ࣮ࢪ࡛ࡍࠋࡇࡇ࡛ࡣࠊMDYDODQJ ࣃ
ࢵࢣ࣮ࢪ࡟ྵࡲࢀࡿࢡࣛࢫࡢ୰࠿ࡽࠊḟࡢࢡࣛࢫࢆ⤂௓ࡋࡲࡍࠋ
͑
2EMHFWࢡࣛࢫ
͑
6WULQJࢡࣛࢫ
͑
6WULQJ%XLOGHUࢡࣛࢫ
͑
,QWHJHUࢡࣛࢫ
MDYDODQJ ࣃࢵࢣ࣮ࢪ࡟ྵࡲࢀࡿࡍ࡭࡚ࡢࢡࣛࢫࠊ࢖ࣥࢱࣇ࢙࣮ࢫࡣ⮬ືⓗ࡟࢖࣏࣮ࣥࢺࡉࢀ
ࡿࡓࡵࠊ᫂♧ⓗ࡞ LPSRUW ᩥࡢグ㏙ࡸࣃࢵࢣ࣮ࢪྡ࡟ࡼࡿࢡࣛࢫࡢಟ㣭ࡣ୙せ࡛ࡍࠋ
㻝㻚㻟㻚㻝
㻻㼎㼖㼑㼏㼠ࢡࣛࢫ㻌
2EMHFW ࢡࣛࢫࡣࡍ࡭࡚ࡢࢡࣛࢫࡢࢫ࣮ࣃ࣮ࢡࣛࢫ࡛ࡍࠋࢡࣛࢫࢆᐃ⩏ࡍࡿ㝿࡟ࢫ࣮ࣃ࣮ࢡࣛ
ࢫࢆᣦᐃࡋ࡞࠿ࡗࡓሙྜࡣࠊࢥࣥࣃ࢖ࣛࡀࠕH[WHQGVMDYDODQJ2EMHFWࠖࡢグ㏙ࢆ㏣ຍࡋࡲࡍࠋ
2EMHFW ࢡࣛࢫ࡟ᐃ⩏ࡉࢀ࡚࠸ࡿ࣓ࢯࢵࢻࡣࠊࡍ࡭࡚ࡢ࢜ࣈࢪ࢙ࢡࢺ࡛฼⏝ྍ⬟࡛ࡍࠋ
MDYDODQJ2EMHFW ࢡࣛࢫࡢ࣓ࢯࢵࢻ
SXEOLFERROHDQHTXDOV 2EMHFWREM ㄝ᫂
ࡇࡢ࢜ࣈࢪ࢙ࢡࢺ࡜ᘬᩘ࡛ᣦᐃࡋࡓ࢜ࣈࢪ࢙ࢡࢺࡀࠊࠕ➼ࡋ࠸ࠖ࢜ࣈࢪ࢙ࢡࢺ࡛࠶
ࡿ࠿࡝࠺࠿ࢆุᐃࡍࡿࠋᚲせ࡟ᛂࡌ࡚ࠊࢧࣈࢡࣛࢫ࡛࣮࢜ࣂ࣮ࣛ࢖ࢻࡍࡿࠋ
ᘬᩘ
REM
ẚ㍑ᑐ㇟ࡢ࢜ࣈࢪ࢙ࢡࢺ
SXEOLFLQWKDVK&RGH ㄝ᫂
ࡇࡢ࢜ࣈࢪ࢙ࢡࢺࡢࣁࢵࢩࣗࢥ࣮ࢻ್ࢆ㏉ࡍࠋ୍⯡࡟ࡣࣁࢵࢩࣗࢸ࣮ࣈ࡛ࣝ౑⏝ࡍ
ࡿࡓࡵ࡟⏝ពࡉࢀ࡚࠸ࡿࠋ
SXEOLF6WULQJWR6WULQJ ㄝ᫂
ࡇࡢ࢜ࣈࢪ࢙ࢡࢺࡢᩥᏐิ⾲⌧ࢆ㏉ࡍࠋࡍ࡭࡚ࡢࢧࣈࢡࣛࢫ࡛࣮࢜ࣂ࣮ࣛ࢖ࢻࡍࡿ
ࡇ࡜ࡀ᥎ዡࡉࢀ࡚࠸ࡿࠋ
10
1.3㻌 java.lang 䝟䝑䜿䞊䝆
㻝㻚㻟㻚㻞
ཧ↷ᆺࡢ್ࡢẚ㍑㸦㻩㻩₇⟬Ꮚ࡜㼑㼝㼡㼍㼘㼟࣓ࢯࢵࢻ㸧㻌
ࠕ
ࠖࢆ⏝࠸ࡓẚ㍑࡛ࡣࠊ ࡘࡢኚᩘࡀྠࡌ࢜ࣈࢪ࢙ࢡࢺࢆཧ↷ࡋ࡚࠸ࡿሙྜࡣ WUXHࠊ␗࡞
ࡿ࢜ࣈࢪ࢙ࢡࢺࢆཧ↷ࡋ࡚࠸ࡿሙྜࡣ IDOVH ࡟࡞ࡾࡲࡍࠋ
䕔 ==₇⟬䛾⤖ᯝ䛜㼠㼞㼡㼑䛻䛺䜛ሙྜ
str1
String str1 = "Hello";
String str2 = str1;
Hello
str1 == str2 э true
str2
䕔㻌==₇⟬䛾⤖ᯝ䛜㼒㼍㼘㼟㼑䛻䛺䜛ሙྜ㻌
str1
Hello
String str1 = new String("Hello");
String str2 = new String("Hello");
str2
str1 == str2 э false
Hello
࢜ࣈࢪ࢙ࢡࢺࡀ➼ࡋ࠸࠿࡝࠺࠿ࡢุᐃᇶ‽ࡣࠊ࢜ࣈࢪ࢙ࢡࢺࡢᣢࡘព࿡࡟ࡼࡗ࡚ኚࢃࡾࡲࡍࠋ
ࡑࡢࡓࡵࠊࠕ
ࠖ࡟ࡼࡿẚ㍑࡛ࡣࠊ࢜ࣈࢪ࢙ࢡࢺࡀ➼ࡋ࠸࠿࡝࠺࠿ࢆṇࡋࡃุᐃ࡛ࡁ࡞࠸ሙྜ
ࡀ࠶ࡾࡲࡍࠋ౛࠼ࡤࠊ6WULQJ ࢜ࣈࢪ࢙ࢡࢺࡣྠࡌᩥᏐิࢆᣢࡗ࡚࠸ࢀࡤ➼ࡋ࠸࢜ࣈࢪ࢙ࢡࢺ
࡜ุᐃࡍ࡭ࡁ࡛ࡍࠋࡋ࠿ࡋࠊࠕ
ࠖࢆ⏝࠸ࡓẚ㍑࡛ࡣྠࡌᩥᏐิࢆᣢࡘ ࡘࡢ࢜ࣈࢪ࢙ࢡࢺࢆ
␗࡞ࡿ࢜ࣈࢪ࢙ࢡࢺ࡜ุᐃࡋࡲࡍࠋ
࢜ࣈࢪ࢙ࢡࢺࡀ➼ࡋ࠸࠿࡝࠺࠿ࡢุᐃ࡟ࡣࠊࠕ
࡛ࠖࡣ࡞ࡃ HTXDOV ࣓ࢯࢵࢻࢆ౑࠸ࡲࡍࠋ
⮬ศ࡛ࢡࣛࢫࢆᐃ⩏ࡍࡿ࡜ࡁࡣࠊ➼ࡋ࠸࢜ࣈࢪ࢙ࢡࢺ࡛࠶ࢀࡤࠕWUXHࠖࢆ㏉ࡍࡼ࠺࡟ HTXDOV
࣓ࢯࢵࢻࢆ࣮࢜ࣂ࣮ࣛ࢖ࢻࡋࡲࡍࠋ
䕔㻌equals䝯䝋䝑䝗䛻䜘䜛䜸䝤䝆䜵䜽䝖䛾ẚ㍑㻌
str1
str2
Hello
Hello
str1.equals(str2) э true
11