Vous êtes sur la page 1sur 40

Fundamentals of Software

Development
CT010-3-1
Introductory Programming Skills

Prepared by: FSK First Prepared on:09 th August 2005 Last Modified on:08th September 2005
Quality checked by: GTK
Copyright 2005 Asia Pacific University College of Technology and Innovation

Topic & Structure of the lesson


Introductory Programming Skills
Using the Integrated Development Environment
What is Java?
Why Java is popular?
Java and the Internet
The structure of a program
A simple Java program
How program code is executed by a computer
A look at JDK
Applets and Applications
API Documentation
CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 2 (of 40)

Learning Outcomes
At the end of this topic, you should be able to:
Create, edit, compile and run simple Java
programs using input and output statements
Appreciate the use of Java programming
language as a development environment
Explain the definition of the various Java
commands listed in the JDK
Write simple Java programs

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 3 (of 40)

Key Terms
If you have mastered this topic, you should be able to use
the following terms correctly in your assignments and
exams:
Application - A complete, self-contained program that
performs a specific function directly for the user.
Applet - A Java program which can be distributed as an
attachment in a World-Wide Web document and executed
by a Java-enabled web browser such as Sun's HotJava,
Netscape Navigator version 2.0, or Internet Explorer.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 4 (of 40)

Key Terms
If you have mastered this topic, you should be able to use
the following terms correctly in your assignments and
exams:
Platform - the hardware / software environment in which a
program runs.
Java platform - a software-only platform that runs on top of
other, hardware-based platforms.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 5 (of 40)

Key Terms
Java Virtual Machine (Java VM)
A virtual CPU including instruction set, register set,
class file format, stack, garbage collected memory
heap & memory area
Every Java interpreter, whether its a Java
development tool or a Web browser that can run
Java applets is an implementation of Java VM.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 6 (of 40)

Key Terms
Java Application Programming Interface (Java API)
A large collection of ready-made software components
that provide many useful capabilities such as graphical
user interface (GUI) widgets.
The Java API is grouped into libraries (packages) of
related components

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 7 (of 40)

What is Java?
Let us examine what Java is in terms of
Language comparison
Platform independence
Language features

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 8 (of 40)

What is Java?
Language comparison
SmallTalk
First true OO Language.
Secure type-checking.

C++
Powerful systems language.
Familiar to many programmers.

JAVA
( Combines the best of both, leaving out the difficulties)

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 9 (of 40)

What is Java?
Platform Independence
JAVA

Programming
Language

CT010-3-1 Fundamentals of Software Development

Platform

Introductory Programming Skills

Slide 10 (of 40)

What is Java?
Language features
Java is a High-Level Programming Language that is :
Simple
- powerful functionality without the confusing features (eg.
pointers)
- reduce 50 % of the bugs
Objected oriented
- implements the basic object technology of C++ with
enhancement
Distributed
- built-in extensive TCP/IP networking capabilities
CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 11 (of 40)

What is Java?
Language features
Java is a High-Level Programming Language that is :
Robust
- check for problems at compile and run-time - help
catch the bugs at the early stage of development
- handles own memory - no worries on freeing &
corrupting memory
- reduce development time
Secure
- Java codes passes several tests before executing
on machine
- eg. Byte-code verifier, class loader

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 12 (of 40)

What is Java?
Language features
Java is a High-Level Programming Language that is :
Multithreaded
- threads - light-weighted processes
- allows many simultaneous activities in 1 program
- better interactive performance and real-time behaviour
Portable
- basic portability of being architecture neutral /
independent
- Java builds its user interfaces via an abstract window
system so the windows can be implemented on UNIX,
PC & MAC environments
CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 13 (of 40)

What is Java?
Language features
Java is a High-Level Programming Language that is :
Architecture Neutral (Special Feature)
both compiled and interpreted
with compiler, a Java program is translated into Java
bytecodes
with interpreter,each Java bytecode instruction is parsed and
run on computers

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 14 (of 40)

What is Java?
Architecture Neutral (Special Feature)

Java Bytecodes - machine code instructions for the


Java Virtual Machine (Java VM).

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 15 (of 40)

What is Java?
Architectural Neutral

Portable (abstract
window)

Write Once, Run Anywhere - Platform Independent

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 16 (of 40)

What is Java?
Platform - the hardware / software environment in which a
program runs.
Java platform - a software-only platform that runs on top of
other, hardware-based platforms.
The Java platform has 2 components :
1. The Java Virtual Machine (Java VM)
2. The Java Application Programming Interface (Java API)

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 17 (of 40)

What is Java?
Java Virtual Machine (Java VM)
A virtual CPU including instruction set, register set,
class file format, stack, garbage collected memory
heap & memory area
Every Java interpreter, whether its a Java
development tool or a Web browser that can run
Java applets is an implementation of Java VM.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 18 (of 40)

What is Java?
Java Application Programming Interface (Java API)
A large collection of ready-made software components
that provide many useful capabilities such as graphical
user interface (GUI) widgets.
The Java API is grouped into libraries (packages) of
related components

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 19 (of 40)

Quick Review Question


1. Name 2 OOP languages
2. Is Java a language or a platform?
3. Give 3 features of the Java Programming language
4. Is a Java program compiled or interpreted?
5. What is the JVM
6. How does Java achieve platform independence?

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 20 (of 40)

Why Java is Popular?


It is platform independent.
It is machine independent.
Provides a compiler and a software system
called JVM to run on all computers without the
need to compile it separately.the bytecodes are
independent of the type of computer system.
Local compilers for each system that will
compile a bytecode file into an executable
image for faster running.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 21 (of 40)

Java and The Internet


Java is becoming a computing platform-base for
software developers to build applications
these applications can execute on any computing
platform
a variety of applications can be built eg. critical
applications used by big companies, accounting, asset
management, databases, human resources and sales

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 22 (of 40)

Quick Review Question


1. List the 5 differences between Java and C/C++
2. Which of these differences are between C and Java?
3. Which are between C++ and Java?

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 23 (of 40)

Applets and Applications


The most common types of Java programs are :
Applets
- A Java program that adheres to certain conventions
that allow it to run within a Java-enabled web
browser.
Applications
- A standalone Java program that runs directly on a java
platform.
- As Java is a general purpose, high-level programming
language and a powerful software platform, we can
write many types of programs.
CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 24 (of 40)

The structure of the program


Java Development Kit (JDK)
The JDK contains what one needs to start building and
executing JAVA applications and applets.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 25 (of 40)

The Java Development Kit (JDK)


Here is how you can set up and program in Java
1. Download the Java Development Kit (JDK)
J2SE 1.4.1 : http://java.sun.com/j2se/1.4.2
2. Download/bookmark the Java API Documentation
J2SE 1.4.1 :
http://java.sun.com/j2se/1.4.2/download.html#docs

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 26 (of 40)

The Java Development Kit (JDK)


3. JAVA run in the MS-DOS box under Win95.
The environment needs to be set up for JAVA to find the
necessary files.
a. Create a batch file under the JDK subdirectory : eg.
setj.bat NotePad can be used to create this file.
set CLASSPATH=c:\j2sdk1.4.2\lib; .;
set
PATH=c:\j2sdk1.4.2\bin;c:\windows\command;c:\windows;
doskey
This assumes that the JDK has been installed in
directory j2sdk1.4.2.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 27 (of 40)

The Java Development Kit (JDK)


b. Under the JDK directory, create a working directory.
eg. try.
This is where youll put your programs and compile
them.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 28 (of 40)

The Java Development Kit (JDK)


c. For convenience, setup a special DOS Prompt icon to
start DOS and run the setj.bat commands.
Using Windows Explorer, find the Dosprompt icon,
under the Windows directory.
Right click to copy, drag & drop the icon this icon to the
desktop.
Rename it to something like DOS for Java.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 29 (of 40)

The Java Development Kit (JDK)


Right click on the icon, to see the properties. Under the
Program tab, fill up the following information.
Working:
c:\j2sdk1.4.0_01\try
(That is where you will code your programs.
This can be any folder name you want)
Batch File: c:\j2sdk1.4.0_01\setj.bat

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 30 (of 40)

The Java Development Kit (JDK)


The JAVA API documentation is the standard on-line
help for the JAVA platform. You will get most of what
you need from this API (onlline :
http://java.sun.com/products/jdk/1.2/docs/index.html).

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 31 (of 40)

The Java Development Kit (JDK)

Packages
Detail of
Classes/
Interfaces
- Methods
/Variables

Classes/
Interfaces

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 32 (of 40)

Quick Review Question


Here are a couple quick questions before we plunge into our
first Java program.
1. What is the difference between an applet and an application?
2. Does an application need the JVM for execution?
3. Does an applet need the JVM for execution?
4. Does a browser need the JVM for executing Java applets?
5. How does the JVM get embedded/installed in a browser
or CPU?
CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 33 (of 40)

A simple Java program


1. Create a Java Source File
Using a text editor (eg. Notepad), create a file named
HelloWorldApp.java with the following Java code:
/*
* The HelloWorldApp class implements an application
* that simply displays "Hello World!" to the standard
* output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}
CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 34 (of 40)

A simple Java program


2. Compile the Source File
Compile the source file using the Java compiler
like this:
javac HelloWorldApp.java

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 35 (of 40)

A simple Java program


If the compilation succeeds, the compiler creates a
file named HelloWorldApp.class in the same
directory (folder) as the Java source file
(HelloWorldApp.java). This class file contains Java
bytecodes, which are platform-independent codes
interpreted by the Java runtime system.
If the compilation fails, make sure you typed in and
named the program exactly as shown above, using
the capitalization shown. If you can't find the
problem, the compiler might be able to help you.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 36 (of 40)

A simple Java program


3. Run The Application
Run the application using the command like this;
java HelloWorldApp
Note: For the UNIX and Windows JDK, the argument
to the Java interpreter is the name of the class to
run, not the name of a file. Be sure to capitalize the
class name exactly as shown above.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 37 (of 40)

Follow Up Assignment
Using any text editor, write a Java application that
display the message:
Surely the best Java programmers come from Java!
Test your application.
Show your application on the board at the beginning of
the next lesson.

CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 38 (of 40)

Summary of Main Teaching Points


Introductory Programming Skills
Using the Integrated Development Environment
What is Java?
Why Java is popular?
Java and the Internet
The structure of a program
A simple Java program
How program code is executed by a computer
A look at JDK
Applets and Applications
API Documentation
CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 39 (of 40)

Next Lesson
Understanding Programming Language Constructs
Variable declarations, definitions, keywords,
constant primitive data types
User-defined data types
Syntax and professional programming practices
Planning and implementing program testing
Testing strategies
Program walkthroughs
Whitebox and blackbox testing
Debugging strategies
Syntax and logic errors
Program tracing
Debugging tools
CT010-3-1 Fundamentals of Software Development

Introductory Programming Skills

Slide 40 (of 40)

Vous aimerez peut-être aussi