Introduction to programming using JAVA - Lecture 1

20
[email protected] [email protected] 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

description

Introduction to programming using JAVAAbility to program real life computer programs with JAVA

Transcript of Introduction to programming using JAVA - Lecture 1

Page 1: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

1

Introduction to ProgrammingIntroduction to Programming((Using Java)Using Java)

Nandika Kasun

University of Colombo School of Computing (UCSC)University of Colombo School of Computing (UCSC)University of ColomboUniversity of Colombo

Sri LankaSri Lanka

SCS1002

Page 2: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

2

Learning ObjectiveLearning Objective

At the end of this course you should be able to design and implement real life computer programs using Java.

Page 3: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

3

Main ReadingMain 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, TataMcGraw-Hill India, 2001. ISBN 0-07-463290-6.

Page 4: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

4

Web ReadingWeb 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

Page 5: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

5

Evaluation CriteriaEvaluation CriteriaAssignments/Practical – 30•An in class assignment (3rd Week)•A take home assignment

(2nd Week -> must submit in 12th week)

Exam paper – 70• An examination paper (two hours)• 3 questions should be answered out of 4 questions• The first question is compulsory

Page 6: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

6

Programming LanguagesProgramming Languages

• First generation of computer programs– Sequence of machine instructions – Loaded into memory through a set of switches

0110100101010110111101010111………………

………………

Page 7: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

7

Programming LanguagesProgramming 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

0110100101010110111101010111

MOV AX,10ADD AX,BX AssemblerAssembler

Page 8: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 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 CPU’s 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 LanguagesProgramming Languages

Page 9: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

9

0110100101010110111101010111

#include <stdio.h>

main(){printf(“I love C pointers\n”);}

C language program

Compiler (C)Compiler (C) Object CodeObject Code

LinkerLinker

LibraryLibrary

Programming LanguagesProgramming Languages

Page 10: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

10

Introduction to JavaIntroduction 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++ .

Page 11: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 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 JavaIntroduction to Java

Page 12: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 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 JavaIntroduction to Java

Page 13: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 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.comJava.sun.com

Introduction to JavaIntroduction to Java

Page 14: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

14

Running Java ProgramsRunning 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.

Page 15: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

15

0110100101010110111101010111

Class ILoveJava {public static void main(String[] args) {

System.out.println(“I Love Java”);}

}

Java language program

Java CompilerJava Compiler Java Byte CodeJava Byte Code

JavaJavaInterpreterInterpreter

JavaJavaLibraryLibrary

Running Java ProgramsRunning Java Programs

Page 16: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

16

Running Java ProgramsRunning 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”);}

}

Page 17: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 2005. All rights reserved. No part of this material may be reproduced and sold.

17

Running Java ProgramsRunning Java Programs

• Compiling and Running the Source File– First set the Java Environment

Setting The PathSettings->control Panel->System->advanced->Environment VariablesIn case of Java 1.4.1, PATH & CLASSPATH should bePATH …………;\C:\J2SDK1.4.1_01\BIN\…. Indicates any existing pathsCLASSPATH =C:\ J2SDK1.4.1_01\ classes.zip;.;

Page 18: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 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 Compilerwill create aJava byte code file

Running Java ProgramsRunning Java Programs

Page 19: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 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 InterpreterExecute the Java Byte codeclass file

Running Java ProgramsRunning Java Programs

Page 20: Introduction to programming using JAVA - Lecture 1

[email protected]@cmb.ac.lkUCSC 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”);}

}

SummarySummaryToday 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.