Sie sind auf Seite 1von 0

Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

1
Introduction to Programming
Introduction to Programming
(
(
Using Java)
Using Java)
Nandika Kasun
University of Colombo School of Computing (UCSC)
University of Colombo School of Computing (UCSC)
University of Colombo
University of Colombo
Sri Lanka
Sri Lanka
SCS1002
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
2
Learning Objective
Learning Objective
At the end of this course you should
be able to design and implement real
life computer programs using Java.
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
3
Main Reading
Main Reading
Teach Yourself Java 2 platform by Laura Lemay,
and Rogers Cadenhead, Techmedia India, 1999.
ISBN 81-7635-243-8.
Program Design, 4th edition by Peter Juliff,
Prentice Hall India, 2000. ISBN-81-203-1622-3.
The Java Handbook by Patrick Naughton, Tata
McGraw-Hill India, 2001. ISBN 0-07-463290-6.
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
4
Web Reading
Web Reading
Thinking in Java (3rd Edition) Bruce Eckel
(Downloadable)
http://www.mindview.net/Books/TIJ/
Official Sun Java site (Downloadable)
http://java.sun.com/docs/books/tutorial/index.html
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
5
Evaluation Criteria
Evaluation Criteria
Assignments/Practical 30
An in class assignment (3
rd
Week)
A take home assignment
(2
nd
Week -> must submit in 12
th
week)
Exam paper 70
An examination paper (two hours)
3 questions should be answered out of 4 questions
The first question is compulsory
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
6
Programming Languages
Programming Languages
First generation of computer programs
Sequence of machine instructions
Loaded into memory through a set of switches
01101001010101
10111101010111

Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
7
Programming Languages
Programming Languages
Second Generation Computer Programs
introduction of assembly languages
enables the programmers to use mnemonic names
for the machine instructions and symbolic names
for memory locations.
A translator called the assembler converts
assembly language programs into machine code
01101001010101
10111101010111
MOV AX,10
ADD AX,BX
Assembler
Assembler
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
8
Third Generation Languages :
High level languages such as BASIC, Fortran,
Pascal, and C eliminate the close ties to the CPUs
machine instructions
Provide standard data types such as integers,
floating point numbers, and characters etc.,
Instructions are user friendly
Compilers are available to translate these high- level
language instructions to machine instructions.
Programming Languages
Programming Languages
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
9
01101001010101
10111101010111
#include <stdio.h>
main()
{
printf(I love C pointers\n);
}
C language program
Compiler (C)
Compiler (C)
Object Code
Object Code
Linker
Linker
Library
Library
Programming Languages
Programming Languages
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
10
Introduction to Java
Introduction to Java
Java was developed by James Gosling at Sun
Microsystems in 1991.
His Original Aim was to develop a low cost,
Hardware Independent Language based on C++.
Due to technical reasons that idea was dropped .
A new programming Language called Oak was
developed based on C++ .
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
11
The language oak was developed by removing
undesirable features of C++.
Those features include:
Multiple inheritance
Automatic type conversions
Use of pointers & memory management.
By 1994 the World Wide Web Emerged and Oak was
Re-named as Java.
Introduction to Java
Introduction to Java
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
12
The Java language was successfully used to develop a
web browser called WebRunner and Java/Hotjava project
was commenced.
In early 1995, Hotjava,Java,Java Documentation and
Source code was made available over the web as an
alpha version.
In December 1995, beta version2 of Java was released.
Introduction to Java
Introduction to Java
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
13
On January 23, 1996 Java 1.0 was officially released
and made available to download over the net.
Latest version of Java 2 SDK. And Documentation can
be downloaded at
Java.sun.com
Java.sun.com
Introduction to Java
Introduction to Java
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
14
Running Java Programs
Running Java Programs
Introduction to Java Development Kit (JDK)
JDK provides core set of tools that are necessary to
develop professional Java applications
These tools are discussed in detail later
JDK tools are also written in Java.
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
15
01101001010101
10111101010111
Class ILoveJava {
public static void main(String[] args) {
System.out.println(I Love Java);
}
}
Java language program
Java Compiler
Java Compiler
Java Byte Code
Java Byte Code
Java
Java
Interpreter
Interpreter
Java
Java
Library
Library
Running Java Programs
Running Java Programs
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
16
Running Java Programs
Running Java Programs
Creating a Java Source File
Any plain text editor or text editor capable of saving
in ASCII format can be used to create a Source file
Examples are DOS EDIT, Notepad etc.
Source File should be saved with a .java extension
/* This program display I Love Java on the computer
screen
*/
Class ILoveJava {
public static void main(String[] args) {
System.out.println(I Love Java);
}
}
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
17
Running Java Programs
Running Java Programs
Compiling and Running the Source File
First set the Java Environment
Setting The Path
Settings->control Panel->System->advanced
->Environment Variables
In case of Java 1.4.1, PATH & CLASSPATH should be
PATH ;\C:\J2SDK1.4.1_01\BIN\
. Indicates any existing paths
CLASSPATH =C:\ J2SDK1.4.1_01\ classes.zip;.;
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
18
Compiling and Running the Source File contd..
Assuming you saved your source file in JavaPrg
Directory;
C:\JavaPrg>Javac ILoveJava.java
Java
Compiler
Source File Name
ensure to use Same
name as the class Name
Java Compiler
will create a
Java byte code file
Running Java Programs
Running Java Programs
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
19
Compiling and Running the Source File contd..
To execute byte code file
C:\JavaPrg>Java ILoveJava
Java
Interpreter
Class Name
Java Byte Code Interpreter
Execute the Java Byte code
class file
Running Java Programs
Running Java Programs
Kasun@cmb.ac.lk Kasun@cmb.ac.lk UCSC 2005. All rights reserved. No part of this material may be reproduced and sold.
20
/* This program displays I Love Java on the computer
screen
*/
Class ILoveJava {
public static void main(Strin args[]) {
System.out.println(I Love Java);
}
}
Summary
Summary
Today we learned how to write a simple Java Program
Exercise:
Exercise:
Write a simple Java program which displays following two lines on the
screen.
I like Java programming.
So I do practical.

Das könnte Ihnen auch gefallen