Prerequisite: Comp. 110/110L. Introduction to data structures and - - PowerPoint PPT Presentation

prerequisite comp 110 110l introduction to data
SMART_READER_LITE
LIVE PREVIEW

Prerequisite: Comp. 110/110L. Introduction to data structures and - - PowerPoint PPT Presentation

182. Data Structures and Program Design (3) Prerequisite: Comp. 110/110L. Introduction to data structures and the algorithms that use them. Review of composite data types such as arrays, records, strings, and sets. 182.


slide-1
SLIDE 1
  • 182. Data Structures and Program Design (3)
  • Prerequisite: Comp. 110/110L.
  • Introduction to data structures and the

algorithms that use them.

  • Review of composite data types such as

– arrays, – records, – strings, and – sets.

slide-2
SLIDE 2
  • 182. Data Structures and Program Design (3)
  • The role of the abstract data type in

program design.

– Definition, – implementation, and – application of data structures such as

  • stacks,
  • queues,
  • linked lists,
  • trees, and graphs.
slide-3
SLIDE 3
  • 182. Data Structures and Program Design (3)
  • Recursion.
  • Use of time complexity expressions in

evaluating algorithms.

  • Comparative study of sorting and

searching algorithms.

slide-4
SLIDE 4

course 1 1 0 / L Review

  • Introduce Java

– language – libraries – platform

  • Discuss object oriented programming
  • Gain experience through labs
slide-5
SLIDE 5
  • Basics
  • Language
  • Arrays
  • Class
  • References
  • Constructors
  • Static and Final
  • String and StringBuffer
  • Inheritance
  • Dynamic Binding
  • Packages
  • Protection
  • Object
  • Exceptions
  • Interfaces
  • Collections
  • Nested Classes
  • I/O
  • Threads
  • Synchronization
  • Swing
  • Applets
  • Networking

Topics of Java Language

slide-6
SLIDE 6
  • Basics

– What is Java? – Simple application: Hello World

  • Java has:

– Compiler/language – Library – Virtual machine

  • Java Language characteristics

– simple as C++ – object oriented – interpreted

– robust – secure – architecture-neutral – portable – multithreaded – dynamic Topics of Java Language

slide-7
SLIDE 7
  • libraries

–i/o – strings – collections – applets – networking – threads – windowing

  • Java Virtual Machine

Java code both com piled and interpreted – source compiled into bytecodes – bytecodes interpreted by virtual machine (VM) VM and API – hide system specific details – make "write once, run anywhere" possible – called platform Topics of Java Language

slide-8
SLIDE 8
  • All Java code organized

into classes

– class represents concept in application domain – Ex: cl ass A

{ . . . }

program organization

slide-9
SLIDE 9

the m ain( ) m ethod

  • main() is the entry point for Java applications

– arguments passed as array of Strings – definition must be inside a class

cl ass Hel l oW

  • r l d

{ publ i c st at i c voi d m ai n( St r i ng[ ] ar gs) { . . . . . . . . . . . . } }

program organization

slide-10
SLIDE 10

exam ple cl ass Hel l oW

  • r l d

{

publ i c st at i c voi d m ai n( St r i ng[ ] ar gs) { Syst em . out . pr i nt l n ( " Hel l o wor l d" ) ; }

}

program organization

slide-11
SLIDE 11

source files

  • Source files contain classes

– filename must be same as class – with .java extension

  • Source files can contain several classes

– they are in a sequence, at most one class designated "public" – filename must be same as public class

program organization

slide-12
SLIDE 12

Object files created by compiler from source file – one for each class – have .class extension – contain bytecodes

  • bject files
slide-13
SLIDE 13
  • JDK (Java Development Kit) comes with compiler

– javac.exe

  • Usage

– pass name of source file – case sensitivity determined by file system

C: > C: > C: > C: > j avac j avac j avac j avac Fi l enam e Fi l enam e Fi l enam e Fi l enam

  • e. j ava

. j ava . j ava . j ava

– if source is stored in Unicode

C: > C: > C: > C: > j avac j avac j avac j avac – – – –encodi ng encodi ng encodi ng encodi ng uni code uni code uni code uni code Fi l enam e Fi l enam e Fi l enam e Fi l enam

  • e. j ava

. j ava . j ava . j ava

java com piler

slide-14
SLIDE 14
  • JDK comes with interpreter

– java.exe

  • Usage

– pass name of object w/o suffix .class – object name is case sensitive even on case insensitive file system C: C: C: C: \ \ \ \ > j ava > j ava > j ava > j ava O bj ect Nam e O bj ect Nam e O bj ect Nam e O bj ect Nam e

java interpreter ( VM)

slide-15
SLIDE 15
  • Language constructs

– comments – primitive types – variables – scope – operators – expressions – control constructs

java language

slide-16
SLIDE 16

// comment

the comment will stop at the end of the current line

/* comment */

– can span multiple lines, – can overwrite // comments – cannot be nested

/** comment */

– It is used in javadoc Where to use them in program?

com m ents

slide-17
SLIDE 17

– byte, short, int, long – float, double – boolean –char Examples: int age, books; double gpa; boolean sexType; char letterGrade;

Prim itive types

slide-18
SLIDE 18
  • made from Unicode characters

– letters, digits, underscore, etc. – case is significant – no operators (+-*/; etc.) – cannot start with digit

  • Variables can be initialized when defined

– assign value of appropriate type – note that float constants require suffix 'F' or 'f‘ Examples: int id = 1002; double Π Π Π Π= 3.14; float gpa = 4.0f; boolean isMale = true; char grade = 'B';

Variable

slide-19
SLIDE 19
  • block scope: curly braces define a scope

– Variables can be defined in a block – accessible only within block

  • Class block

scope

slide-20
SLIDE 20
  • Standard mathematical operations available

– operators + - * / Precedence * / higher than + - Parentheses can be used to force an association

  • Shorthand operators

– increment ++ – decrement -- – assignment +=, -=, *=, /=,

expressions

slide-21
SLIDE 21
  • Int division yields an integer

– fractional part lost – modulus operator % gives remainder

  • Mixed type expressions allowed

– operands automatically converted to common type – smaller type converted to larger – called promotion – result is of the larger type

  • A cast is a forced type conversion

– type name put in parentheses ex: f =((float) i)/j; // to have a float division

  • Notes:

– promotion occurs automatically – demotion requires explicit cast

Types conversion

slide-22
SLIDE 22
  • choice:
  • if
  • If < > then < >
  • If <> then <> else <>
  • Loops

– while –do –for

  • break
  • continue
  • switch

Control keyw ords

slide-23
SLIDE 23

< less than <= less than or equal > greater than >= greater than or equal == equal != not equal

Relational operators

slide-24
SLIDE 24

Logical operators used to combine expressions && and ||

  • r

! not

Logical operators

slide-25
SLIDE 25

w hile

  • while loop provides iteration

– loop condition evaluated before entering while (conditions) { }

do

  • do loop executed at least once

do { } while (conditions);

LOOPS

slide-26
SLIDE 26

for

  • for loop centralizes control information

for (int i =0 ; i <5 ; i++) { }

break

  • break statement used to exit loop

continue

  • continue shortcuts loop iteration

skips rest of body for that iteration

LOOPS

slide-27
SLIDE 27

sw itch

  • switch selects one option from several choices

switch (grade) {

case 'A': sum + = 4 .0 ; break; case 'B': sum + = 3 .0 ; break; case ‘C’: case 'D': sum + = 1 .0 ; break; case 'F': sum + = 0 .0 ; break; default : / / none of above

}

LOOPS