SlideShare a Scribd company logo
1 of 33
Download to read offline
Fundamental Java
HASUNUMA Kenji
Vice president, GlassFish Users Group Japan

k.hasunuma@coppermine.jp

Twitter: @btnrouge
What’s Java?
Javaの特徴	

• オープンな規格である	

• 常に進化している	

• 互換性を重視している
Javaはオープン規格	

• 言語、標準API、仮想マシン仕様	

• Java Community Processで標準化	

• 現在はオープンソース (GPLv2)
•Write Once, Run Anywhere
•言語レベルでマルチスレッド対応
•厳格な例外処理機構
•Unicodeを全面的に採用
Write Once, Run Anywhere

• OS、Java VM実装に依存しない	

• 古いコードが最新のJavaでも動く	

• Blu-rayから巨大システムまで
当初: OSの差異をJava VMが吸収する
現在: Java VMが多言語の共通基盤へ
Essential Java
Javaのエコシステム
クラスとインタフェース
クラスの継承
Polymorphismとは?
プロセスとスレッド
プロセスとスレッド
Javaの入出力(Stream)
現在では文字列データに特化したReader/Writerや、
高速I/Oを実現するChannelもよく使われている
Javaのパッケージ
クラス名の表記方法
•原則: パッケージを含む完全名

(例) java.util.List
•import宣言: 特定のパッケージを省略可

(方法1) import java.util.List;

(方法2) import java.util.*;
•java.lang…常にパッケージを省略可
Javaクラスの同一性
• クラス名が同一である	

• パッケージ名が完全に一致している	

• 同じクラスローダーから読み込まれた
Java Core Parts
クラスとオブジェクト
• クラスは定義のみ…実体がない	

• オブジェクト(インスタンス)

…クラスから作成した実体のこと	

• フィールドとメソッドはオブジェクトに
属する( staticはクラスに属する)
java.lang.Object
• Javaの全クラスのスーパークラス	

• クラスの根幹に関わるメソッドを持つ	

• プリミティブ型に対してリファレンス型
と呼ばれることもある
java.lang.Object のメソッド
equals 同一チェックに使う	

※原則としてオーバーライドする
hashCode
toString 文字列表現を返す ※用途は様々
wait スレッド制御用メソッド	

※通常はConcurrency Utilitiesを経由
して使用する(オーバーライド不可)
notify
notifyAll
clone コピー(最近は使われない)
finalize 後処理(通常はオーバーライドしない)
Object o = new Object();
Object o = new Object();
Object o = new Object();
右辺と同じクラス
or
スーパークラス
or
実装インタフェース
Object o = new ArrayList();
キャスト
Object o = new ArrayList();

• objの定義はObject、実体はArrayList	

• アクセスは定義を通じて行う	

• 実体への直接アクセス→キャスト
ArrayList list = (ArrayList) o; 

• キャスト=サブクラスの定義でアクセス

• キャスト後は実体に直接アクセス可能
プリミティブ型
• クラスではないデータ型	

• 対応するクラス(ラッパー)を持つ	

• auto-boxing/unboxing:

プリミティブ型とラッパーの相互変換
プリミティブ型 ラッパークラス
boolean Boolean
byte Byte
char Character
short Short
int Integer
long Long
float Float
double Double
配列
• 同じクラスorプリミティブ型の連続	

• 演算子 [ ] で要素にアクセスする	

• 内部的にはjava.lang.Arrayクラス
Object[] o = new Object[8];
o は Objectの配列
(要素数は指定しない)
配列の要素数は 8
(必ず定数=後で変更不可)
配列の場合、左辺と右辺は同じクラス
その他の重要なトピック
• Generics (J2SE 5.0)

• Annotation (J2SE 5.0)

• Project Coin (Java SE 7)

• Collections Framework (J2SE 1.2)

• New I/O (J2SE 1.4 & Java SE 7)

• Concurrency Utilitites (J2SE 5.0 & Java SE 7)
Fundamental Java
HASUNUMA Kenji

k.hasunuma@coppermine.jp

Twitter: @btnrouge

More Related Content

Similar to Fundamental Java

What is java_se_7
What is java_se_7What is java_se_7
What is java_se_7TakumiIINO
 
Java SE 再入門
Java SE 再入門Java SE 再入門
Java SE 再入門minazou67
 
OSvのご紹介 in 
Java 8 HotSpot meeting
OSvのご紹介 in 
Java 8 HotSpot meetingOSvのご紹介 in 
Java 8 HotSpot meeting
OSvのご紹介 in 
Java 8 HotSpot meetingTakuya ASADA
 
OSvのご紹介 in OSC2014 Tokyo/Fall
OSvのご紹介 in OSC2014 Tokyo/FallOSvのご紹介 in OSC2014 Tokyo/Fall
OSvのご紹介 in OSC2014 Tokyo/FallTakuya ASADA
 
LLoT2016 Java Update
LLoT2016 Java UpdateLLoT2016 Java Update
LLoT2016 Java Updatetorutk
 
Swiftアプリ制作入門 かんたんシューティングゲーム
Swiftアプリ制作入門 かんたんシューティングゲームSwiftアプリ制作入門 かんたんシューティングゲーム
Swiftアプリ制作入門 かんたんシューティングゲーム聡 中川
 
全部入り!WGPで高速JavaScript+HML5体験
全部入り!WGPで高速JavaScript+HML5体験全部入り!WGPで高速JavaScript+HML5体験
全部入り!WGPで高速JavaScript+HML5体験AdvancedTechNight
 
クラウド化が進む今だから読み解くHyper-Vアーキテクチャ
クラウド化が進む今だから読み解くHyper-Vアーキテクチャクラウド化が進む今だから読み解くHyper-Vアーキテクチャ
クラウド化が進む今だから読み解くHyper-VアーキテクチャTsukasa Kato
 
「愛されたい!」と思ったときにJavaで書くRubyクラス
「愛されたい!」と思ったときにJavaで書くRubyクラス「愛されたい!」と思ったときにJavaで書くRubyクラス
「愛されたい!」と思ったときにJavaで書くRubyクラスKoichiro Ohba
 
Scalaでのプログラム開発
Scalaでのプログラム開発Scalaでのプログラム開発
Scalaでのプログラム開発Kota Mizushima
 
JVMの中身を可視化してみた
JVMの中身を可視化してみたJVMの中身を可視化してみた
JVMの中身を可視化してみたKengo Toda
 
PlayFramework1.x基礎編
PlayFramework1.x基礎編PlayFramework1.x基礎編
PlayFramework1.x基礎編Asami Abe
 
組み込みスクリプト言語Mrubyを利用したwebサーバの機能拡張支援機構
組み込みスクリプト言語Mrubyを利用したwebサーバの機能拡張支援機構組み込みスクリプト言語Mrubyを利用したwebサーバの機能拡張支援機構
組み込みスクリプト言語Mrubyを利用したwebサーバの機能拡張支援機構Ryosuke MATSUMOTO
 

Similar to Fundamental Java (20)

What is java_se_7
What is java_se_7What is java_se_7
What is java_se_7
 
Java SE 再入門
Java SE 再入門Java SE 再入門
Java SE 再入門
 
OSv噺
OSv噺OSv噺
OSv噺
 
OSvのご紹介 in 
Java 8 HotSpot meeting
OSvのご紹介 in 
Java 8 HotSpot meetingOSvのご紹介 in 
Java 8 HotSpot meeting
OSvのご紹介 in 
Java 8 HotSpot meeting
 
OSvのご紹介 in OSC2014 Tokyo/Fall
OSvのご紹介 in OSC2014 Tokyo/FallOSvのご紹介 in OSC2014 Tokyo/Fall
OSvのご紹介 in OSC2014 Tokyo/Fall
 
LLoT2016 Java Update
LLoT2016 Java UpdateLLoT2016 Java Update
LLoT2016 Java Update
 
Swiftアプリ制作入門 かんたんシューティングゲーム
Swiftアプリ制作入門 かんたんシューティングゲームSwiftアプリ制作入門 かんたんシューティングゲーム
Swiftアプリ制作入門 かんたんシューティングゲーム
 
全部入り!WGPで高速JavaScript+HML5体験
全部入り!WGPで高速JavaScript+HML5体験全部入り!WGPで高速JavaScript+HML5体験
全部入り!WGPで高速JavaScript+HML5体験
 
クラウド化が進む今だから読み解くHyper-Vアーキテクチャ
クラウド化が進む今だから読み解くHyper-Vアーキテクチャクラウド化が進む今だから読み解くHyper-Vアーキテクチャ
クラウド化が進む今だから読み解くHyper-Vアーキテクチャ
 
「愛されたい!」と思ったときにJavaで書くRubyクラス
「愛されたい!」と思ったときにJavaで書くRubyクラス「愛されたい!」と思ったときにJavaで書くRubyクラス
「愛されたい!」と思ったときにJavaで書くRubyクラス
 
Play jjug2012spring
Play jjug2012springPlay jjug2012spring
Play jjug2012spring
 
Nishimotz pycon2011jan
Nishimotz pycon2011janNishimotz pycon2011jan
Nishimotz pycon2011jan
 
Scalaでのプログラム開発
Scalaでのプログラム開発Scalaでのプログラム開発
Scalaでのプログラム開発
 
Harmoware-VIS Tutorial
Harmoware-VIS TutorialHarmoware-VIS Tutorial
Harmoware-VIS Tutorial
 
JVMの中身を可視化してみた
JVMの中身を可視化してみたJVMの中身を可視化してみた
JVMの中身を可視化してみた
 
Fn project爆誕
Fn project爆誕Fn project爆誕
Fn project爆誕
 
Nishimotz osc2011oct-v2
Nishimotz osc2011oct-v2Nishimotz osc2011oct-v2
Nishimotz osc2011oct-v2
 
2014.7 LT java
2014.7 LT java2014.7 LT java
2014.7 LT java
 
PlayFramework1.x基礎編
PlayFramework1.x基礎編PlayFramework1.x基礎編
PlayFramework1.x基礎編
 
組み込みスクリプト言語Mrubyを利用したwebサーバの機能拡張支援機構
組み込みスクリプト言語Mrubyを利用したwebサーバの機能拡張支援機構組み込みスクリプト言語Mrubyを利用したwebサーバの機能拡張支援機構
組み込みスクリプト言語Mrubyを利用したwebサーバの機能拡張支援機構
 

More from Kenji HASUNUMA

How to adapt MicroProfile API for generic Web applications
How to adapt MicroProfile API for generic Web applicationsHow to adapt MicroProfile API for generic Web applications
How to adapt MicroProfile API for generic Web applicationsKenji HASUNUMA
 
Life of our small product
Life of our small productLife of our small product
Life of our small productKenji HASUNUMA
 
Jakarta EE: The First Parts
Jakarta EE: The First PartsJakarta EE: The First Parts
Jakarta EE: The First PartsKenji HASUNUMA
 
Introduction to MicroProfile Metrics
Introduction to MicroProfile MetricsIntroduction to MicroProfile Metrics
Introduction to MicroProfile MetricsKenji HASUNUMA
 
Introduction to JCA and MDB
Introduction to JCA and MDBIntroduction to JCA and MDB
Introduction to JCA and MDBKenji HASUNUMA
 
Basic method for Java EE Web Profile
Basic method for Java EE Web ProfileBasic method for Java EE Web Profile
Basic method for Java EE Web ProfileKenji HASUNUMA
 
Introduction to JavaFX Dialogs
Introduction to JavaFX DialogsIntroduction to JavaFX Dialogs
Introduction to JavaFX DialogsKenji HASUNUMA
 
Brand New Date and Time API
Brand New Date and Time APIBrand New Date and Time API
Brand New Date and Time APIKenji HASUNUMA
 
Virtualization Fundamental
Virtualization FundamentalVirtualization Fundamental
Virtualization FundamentalKenji HASUNUMA
 
JLS Myths - If-then-else statement -
JLS Myths - If-then-else statement -JLS Myths - If-then-else statement -
JLS Myths - If-then-else statement -Kenji HASUNUMA
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4Introduction to Date and Time API 4
Introduction to Date and Time API 4Kenji HASUNUMA
 
Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Kenji HASUNUMA
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3Kenji HASUNUMA
 
Introduction to Date and Time API 2
Introduction to Date and Time API 2Introduction to Date and Time API 2
Introduction to Date and Time API 2Kenji HASUNUMA
 
Introduction to Date and Time API
Introduction to Date and Time APIIntroduction to Date and Time API
Introduction to Date and Time APIKenji HASUNUMA
 

More from Kenji HASUNUMA (15)

How to adapt MicroProfile API for generic Web applications
How to adapt MicroProfile API for generic Web applicationsHow to adapt MicroProfile API for generic Web applications
How to adapt MicroProfile API for generic Web applications
 
Life of our small product
Life of our small productLife of our small product
Life of our small product
 
Jakarta EE: The First Parts
Jakarta EE: The First PartsJakarta EE: The First Parts
Jakarta EE: The First Parts
 
Introduction to MicroProfile Metrics
Introduction to MicroProfile MetricsIntroduction to MicroProfile Metrics
Introduction to MicroProfile Metrics
 
Introduction to JCA and MDB
Introduction to JCA and MDBIntroduction to JCA and MDB
Introduction to JCA and MDB
 
Basic method for Java EE Web Profile
Basic method for Java EE Web ProfileBasic method for Java EE Web Profile
Basic method for Java EE Web Profile
 
Introduction to JavaFX Dialogs
Introduction to JavaFX DialogsIntroduction to JavaFX Dialogs
Introduction to JavaFX Dialogs
 
Brand New Date and Time API
Brand New Date and Time APIBrand New Date and Time API
Brand New Date and Time API
 
Virtualization Fundamental
Virtualization FundamentalVirtualization Fundamental
Virtualization Fundamental
 
JLS Myths - If-then-else statement -
JLS Myths - If-then-else statement -JLS Myths - If-then-else statement -
JLS Myths - If-then-else statement -
 
Introduction to Date and Time API 4
Introduction to Date and Time API 4Introduction to Date and Time API 4
Introduction to Date and Time API 4
 
Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
 
Introduction to Date and Time API 2
Introduction to Date and Time API 2Introduction to Date and Time API 2
Introduction to Date and Time API 2
 
Introduction to Date and Time API
Introduction to Date and Time APIIntroduction to Date and Time API
Introduction to Date and Time API
 

Fundamental Java