Sách Java dành cho người mới học , Sách Java dành cho người mới học , Sách Java dành cho người mới học , Sách Java dành cho người mới học , Sách Java dành cho người mới học , Sách Java dành cho người mới học , Sách Java dành cho người mới học ,Sách Java dành cho người mới học Sách Java dành cho người mới học Sách Java dành cho người mới học
Trang 1Java Programing
Language
SESSION 01 – Introduction to Java
Trang 2• Choosing a development environment
• Writing a simple Java program
• Using the command-line tools
• Using Java NetBeans and Eclipse
Trang 3– Originally called Oak
• Aimed at producing an operating environment for networked devices and embedded systems
– “Write once, run anywhere”
– Java is currently one of the most popular
programming language
Trang 4The Java history timeline
Trang 5Java Virtual Machine
• Java is both a compiled and an interpreted language
– Source code is compiled into Java bytecode
– bytecode is then interpreted by the J ava V irtual M achine
(JVM)
Trang 6Java Virtual Machine (cont)
Java Code
Byte Code (.class)
JVM
Trang 7Java language for Mobile application development
• Android (Java)
• Bada (C++)
• Black Berry (Java)
• iPhone, iPad (Objective-C)
Trang 9Features of Java (cont)
• Simple :
– The syntax is mostly derived from C and C++
– Java has simplified C++ programming by remove some of complicated and difficult from C++
Trang 10Features of Java (cont)
– Java’s support for Object-Orientation includes
inheritance, polymorphism, data access levels…– Not support multiple inheritance
Trang 11Features of Java (cont)
• Platform-independent :
– Java was conceived with the concept of WORA:
“Write once, Run anywhere"
– Java code (.java) is compiled a byte code which is independent of the system
– Java byte code (.class) can run on any device
equipped with a Java Virtual Machine
Trang 12Features of Java (cont)
• Robust : Java can be used to solve some very complex programming problems with the
Trang 13Features of Java (cont)
• Secure :
– No pointers are forged
– No illegal object casts are performed
– There will be no operand stack overflows or underflows
– All parameters passed to functions are of the proper types
– Rules regarding private, protected, and public class membership are followed
Trang 14Features of Java (cont)
• Multi-threaded:
– Multiple, synchronized threads is built directly into the
Java language and runtime environment
– Synchronized threads are useful in creating distributed, network-aware applications
Trang 15Java compared with other languages
Trang 16The popularity of Java
Trang 17JDK and JRE
• The two principal products in the Java SE
platform: J ava Development Kit (JDK) and Java
Runtime Environment (JRE).
– The JRE provides the libraries, Java virtual machine,
and other components necessary for running applets
and applications written in the Java programming
language
– The JDK includes the JRE plus development tools such
as compilers and debuggers that are necessary or
useful for developing applets and applications
Trang 18JDK and JRE
Trang 19Download and install JDK
• The JDK is a development environment for building applications, applets, and components using the Java programming language.
• JDK can be download at http://www.oracle.com
• After downloading the JDK, follow the
platform-dependent installation directions At the time of this writing, they were available at
http://java.sun.com/javase/6/webnotes/install/ind ex.html.
Trang 20Navigating the Java Directories
• The JDK has the directory structure shown
Trang 21Setting the Execution Path
1 Click Start > Control Panel > System on
Windows XP or Start > Settings > Control
Panel > System (on Windows XP.)
2 Click Advanced > Environment Variables.
3 Add the location of bin folder of JDK
installation for PATH in User Variables and
System Variables A typical value for PATH is:
C:\Program Files\Java\jdk1.6.0_<version>\bin
Trang 22Write a simple Java program
The first application will simply display the greeting "Hello world!"
• Step 1: Create a source file
public class Helloworld
• Step 2: Compile the source file into a class file
• Step 3: Run the program
Trang 23Write a simple Java program
Write Java
code using
an editor
javac Helloworld.java
This creates a file of bytecode with a
.class extension
Trang 24Using the Command-Line Tools
• Open a shell indow Go to directory where you
store your Helloworld.java and use javac
Trang 25Using the Command-Line Tools
• The javac has a set of standard options:
Trang 26Choosing a Development Environment
• NetBeans
• Jbuilder
• Eclipse
Trang 27Using Java NetBeans
Trang 28• Create a Java Project:
Using NetBeans
Trang 29• Write a simple program:
Using NetBeans
Trang 30• Program’s output in Console window:
Trang 31• Java has three ways of marking comments:
– The most commonmethod is a //
– Use the /* and */ comment to block off a longer comment
Trang 32• In this session, we learnt:
– History of Java
– Java Virtual Machine
– Types of Java programs
– Features of Java
– JRE and JDK
– Choosing a development environment – Writing a simple Java program
– Using the command-line tools
– Using Java NetBeans and Eclipse
– Basic of Java