Module 1
Java introduction
1
History overview
1992 - Green Project – project of Sun Microsystems to create a
language for the embeddable systems – Oak. Author –
James Gosling.
2
History overview
1992 - First demo device on new platform – PDA Star 7.
3
History overview
1994 - Internet epoch is coming. Java is refocused to applets
development. Language is renamed to Java.
4
History overview
1996 - Java Development Kit.
5
Versions overview
1996 – Java Development Kit.
1997 – JDK 1.1
1998 – JDK 1.2, “Java 2”, introducing ME/SE/EE editions
2000 – J2SE 1.3
2002 – J2SE 1.4
2004 – J2SE 5.0, numeration has changed.
2006 – Java SE 6, leaving “J2SE”.
2011 – Java SE 7
2014 – Java SE 8
6
7
Java features
Simplicity
Portability
Multithreading support
Garbage collection
Safety
8
Virtual machine
WORE: Write Once – Run Everywhere
Code in Code in
Java programming language Scala programming language
C/C++ Java complier Scala compiler
program to the byte code to the byte code
[Link]
universal same byte code
compiler to the BYTE CODE for different OSs
code of OS
BYTE CODE BYTE CODE BYTE CODE
Java Virtual Machine JVM for JVM for
(JVM) for Windows Mac OS X Linux
[Link] [Link]
Windows Mac OS X Linux
9
High and low level languages
High level languages: quick and easy to write code, but code is running slower
Natural language: algorithms, technical tasks
JavaScript PHP
Java
c c
C / С++ o o
d d
Compiling e e
Assembler to the
Byte
code
compiling
Java virtual PHP
Browser
machine interpreter
0101000100110 0101000100110
0010010101010
0010010101010
1100010100101 1100010100101 Machine code
Hardware level
Low level languages: more difficult to write code, code works faster
Platform andPlatform = environment + libraries
Platform defines which commands to be executed
language Language = syntax: defines how to call commands
platform command
Windows API CreateWindow()
.NET New Window2().Show()
Java new JFrame().setVisible(true)
JavaScript [Link]()
Java platform .NET platform
Java language: Java for .NET:
public static void main() { public static void main() {
JFrame frame = new JFrame(“Alert"); Window2 win = new Window2();
[Link](true); [Link]();
} }
Scala: Scala for .NET:
def main(args: Array[String]) { def main(args: Array[String]) {
var frame: JFrame = new JFrame(“Alert”) var win: Window2 = new Window2(“Alert”)
[Link](true) [Link]()
} }
11
Build tools
Apache ANT
Apache Maven
12
IDE – Integrated development environments
Eclipse IDE
NetBeans
IntelliJ IDEA
13
Java implementation
Oracle Java
[Link]
14
Java implementations
Oracle Java - official implementation
[Link]
OpenJDK
[Link]
Iced Tea
[Link]
JRockit
[Link]
15
JVM-running languages
Groovy Code in Code in
Java programming language Scala programming language
JRuby
Java complier Scala compiler
Jython to the byte code to the byte code
Clojure [Link]
universal same byte code
Scala
BYTE CODE for different OSs
Kotlin
Rhino
Ceylon BYTE CODE BYTE CODE BYTE CODE
Phantom Java Virtual Machine JVM for JVM for
etc. (JVM) for Windows Mac OS X Linux
[Link]
Windows Mac OS X Linux
16
Java editions
Java SE (Standard Edition)
Java ME (Micro Edition)
Java EE (Enterprise Edition)
17
Java modes
Client mode
The Client VM compiler does not try to execute many of the
more complex optimizations performed by the compiler in
the Server VM, but in exchange, it requires less time to
analyze and compile a piece of code. This means the Client
VM can start up faster and requires a smaller memory
footprint.
Server mode java -client
The Server VM contains an advanced adaptive java -server
compiler that supports many of the same types
of optimizations performed by optimizing C++
compilers, as well as some optimizations that
cannot be done by traditional compilers, such as
aggressive inlining across virtual method
invocations.
In "client" mode JVM gives some unused memory back to the operating system -
whereas with "server" mode, once the JVM grabs the memory, it won't give it back.
A 64-bit capable JDK currently ignores this option and instead uses the Java Hotspot Server VM.
[Link]
[Link]#CBBIJCHG 18
JDK overview
JDK can be downloaded at [Link]/technetwork/java.
JDK is installed to C:\Program Files\Java by default
JDK also contains JRE
19
JDK tools overview
javac - compiler
java – JVM implementation
jar – .class archiver
javadoc – documentation generator
jdb – debugger
20
javac
Java Compiler
Compiles Java code (*.java) to byte code (*.class)
javac [Link] [Link]
javac -d classes [Link]
javac -classpath [Link] -d classes [Link]
javac -version
21
JavaDoc
JavaDoc tags list
@author Author of class/interface
@version Version of the class/interface
@since Since which version accessible
@see Link to another place in documentation
@param Method parameter
@return Returned value
@throws Exception description
@deprecated Marks old code
22
JavaDoc
/**
* This is the simplest Java class. It prints the “Hello, World”
message.
* @author Peter Pan
*/
public class HelloWorld {
/**
* Definition for hello world message.
*/
public static final String HELLO_MESSAGE = "Hello, World";
/**
* Main methods which is executed by JVM and prints the message.
* @param args Command line arguments
*/
public static void main(String[] args) {
[Link](HELLO_MESSAGE);
}
}
javadoc [Link]
[Link] will be generated
23
Exercise
Lab guide:
• Exercise 1
• Exercise 2
24