COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

Similar documents
Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

Lecture 1: Overview of Java

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Pace University. Fundamental Concepts of CS121 1

Lesson 01 Introduction

Selected Java Topics

Programming. Syntax and Semantics

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

Character Stream : It provides a convenient means for handling input and output of characters.

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

CHAPTER 1. Introduction to JAVA Programming

13 th Windsor Regional Secondary School Computer Programming Competition

HST 952. Computing for Biomedical Scientists Lecture 8

Lesson 3: Accepting User Input and Using Different Methods for Output

Building Java Programs. Introduction to Programming and Simple Java Programs

Full file at

Course information. Petr Hnětynka 2/2 Zk/Z

2 rd class Department of Programming. OOP with Java Programming

1993: renamed "Java"; use in a browser instead of a microwave : Sun sues Microsoft multiple times over Java

Course Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R.

Introduction to Java

History Introduction to Java Characteristics of Java Data types

needs to be reliable, easy to change, retarget efficiency is secondary implemented as interpreter, with virtual machine

File IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Chapter 10. File I/O. Copyright 2016 Pearson Inc. All rights reserved.

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Lecture 11.1 I/O Streams

Introduction Unit 4: Input, output and exceptions

CS11 Java. Fall Lecture 1

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway

B.V. Patel Institute of BMC & IT, UTU 2014

1. Download the JDK 6, from

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

CompSci 125 Lecture 02

Assumptions. History

Java Input/Output. 11 April 2013 OSU CSE 1

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

Java Professional Certificate Day 1- Bridge Session

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Certified Core Java Developer VS-1036

CSE 143 Au04 Midterm 2 Sample Solution Page 1 of 7

Introduction to Java. Nihar Ranjan Roy.

CS 11 java track: lecture 1

Chapter 1 Introduction to Computers, Programs, and Java

Full file at

Introduction Basic elements of Java

CSPP : Introduction to Object-Oriented Programming

CISC 370: Introduction to Java

CS1092: Tutorial Sheet: No 3 Exceptions and Files. Tutor s Guide

CS Programming Language - JAVA. Fall 2004 Sept. 15th

I/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O

Compiling Techniques

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

CS 231 Data Structures and Algorithms, Fall 2016

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Getting Started in Java. Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park

Course information. Petr Hnětynka 2/2 Zk/Z

Lecture 4: Exceptions. I/O

From C++ to Java. Duke CPS

G52PGP. Lecture oo3 Java (A real object oriented language)

Today. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Introduction to Java Programming

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O

Lec 3. Compilers, Debugging, Hello World, and Variables

TTh 9.25 AM AM Strain 322

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

Modern Programming Languages. Lecture Java Programming Language. An Introduction

Lab 5: Java IO 12:00 PM, Feb 21, 2018

Introduction to Programming Using Java (98-388)

Byte and Character Streams. Reading and Writing Console input and output

7. Java Input/Output. User Input/Console Output, File Input and Output (I/O)

Programming Language Concepts: Lecture 2

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code

1 Shyam sir JAVA Notes

File I/O Array Basics For-each loop

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Special error return Constructors do not have a return value What if method uses the full range of the return type?

Java Refresh Exercises

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

Selected Questions from by Nageshwara Rao

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

AP Computer Science A: Java Programming

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

CHAPTER 7 OBJECTS AND CLASSES

Software and Programming 1

CN208 Introduction to Computer Programming

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

Chapter 14. Exception Handling and Event Handling ISBN

Brief Summary of Java

Programming with Java

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

Java Overview An introduction to the Java Programming Language

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

Data Types and the while Statement

Transcription:

COT 3530: Data Structures Giri Narasimhan ECS 389; Phone: x3748 giri@cs.fiu.edu www.cs.fiu.edu/~giri/teach/3530spring04.html

Evaluation Midterm & Final Exams Programming Assignments Class Participation 01/13/2004 Lecture 1 2

What is Java? Java programming language object-oriented similar to C++ Java platform Java Virtual Machine (JVM) Application Programming Interface (API) Created and licensed by Sun Microsystems Both compiled and interpreted compiler produces Java Bytecodes bytecodes are executed by Java Virtual Machine programs run slightly slower than native code (such as that produced by C++) 01/13/2004 Lecture 1 3

What is Java? Java Development Kit (JDK) compiler, runtime system, debugger, documentation Java Virtual Machine (JVM) executes Java bytecode programs 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 of related classes and interfaces; these libraries are known as packages. 01/13/2004 Lecture 1 4

How Can Java be Used? Write software on one platform and run it on another. applications Create programs to run within a web browser. applets Develop server-side applications for online forums, stores, polls, processing HTML forms, and more. Write applications for cell phones, two-way pagers, and other consumer devices. 01/13/2004 Lecture 1 5

Programming Environment JDK 1.3.1 JCreator is our editor and Integrated Development Environment (IDE) Filenames case-sensitive Source files:.java Compiled code:.class Project files All java source files must be in same directory 01/13/2004 Lecture 1 6

Workspace file Hello.jcw Project file Hello.jcp Source Code Hello.java List of source files src_hello.txt JCreator Files Compiled code (class file) Hello.class A workspace may contain multiple projects A project may contain multiple java source files 01/13/2004 Lecture 1 7

Simple Java Hello -1 // Hello.java public class Hello public static void main(string[] args) System.out.println("Hello, COP 3337"); 01/13/2004 Lecture 1 8

Simple Java Hello -2 Create the project File / New / Empty project Project name: Hello (Workspace created automatically) Create the source file File / New / Java file File name: Hello Build the project Build / Compile project (F7) Execute the project Build / Execute project (F5) 01/13/2004 Lecture 1 9

Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss 2002 Addison Wesley Figure 1.2 The eight primitive types in Java 01/13/2004 Lecture 1 10

Primitive Types 8 primitive types: byte, short, int, long, float, double, char, boolean Non-primitive types are all reference types reference types are simply pointers assignments to reference types declaring an object creating an object garbage collection reference types as parameters of methods casting String type: concatenation, length, comparison, sub-string, conversion 01/13/2004 Lecture 1 11

Static Declarations Storage allocation for static objects, fields, methods. 2 ways to invoke static fields & methods: using an object or using the class name. 01/13/2004 Lecture 1 12

Arrays Reference types; explicitly created using new statement. Index starts at 0. Arrays have length field. Array assignment array copy. Array copy done using clone() multi-dimensional arrays Dynamic arrays automatic using ArrayList 01/13/2004 Lecture 1 13

import java.io.inputstreamreader; import java.io.bufferedreader; import java.io.ioexception; public class ReadStrings public static void main( String [ ] args ) String [ ] array = getstrings( ); for( int i = 0; i < array.length; i++ ) System.out.println( array[ i ] ); Figure 2.6, 2.7, page 42-43 // Read an unlimited number of String; return a String [ ] public static String [ ] getstrings( ) BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ); String [ ] array = new String[ 5 ]; int itemsread = 0; String oneline; System.out.println( "Enter any number of strings, one per line; " ); System.out.println( "Terminate with empty line: " ); try while( ( oneline = in.readline( ) )!= null &&!oneline.equals( "" ) ) if( itemsread == array.length ) array = resize( array, array.length * 2 ); array[ itemsread++ ] = oneline; catch( IOException e ) System.out.println( "Unexpected IO Exception has shortened amount read" ); Implementing arrays of Strings System.out.println( "Done reading" ); return resize( array, itemsread ); 01/13/2004 Lecture 1 14

Figure 2.7, page 43 // Resize a String[ ] array; return new array public static String [ ] resize( String [ ] array, int newsize ) String [ ] original = array; int numtocopy = Math.min( original.length, newsize ); array = new String[ newsize ]; for( int i = 0; i < numtocopy; i++ ) array[ i ] = original[ i ]; return array; 01/13/2004 Lecture 1 15

Same program, but using class ArrayList import java.io.inputstreamreader; import java.io.bufferedreader; import java.io.ioexception; import java.util.arraylist; public class ReadStringsWithArrayList public static void main( String [ ] args ) ArrayList array = getstrings( ); for( int i = 0; i < array.size( ); i++ ) System.out.println( array.get( i ) ); Figure 2.8, page 44 // Read an unlimited number of String; return an ArrayList public static ArrayList getstrings( ) BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ); ArrayList array = new ArrayList( ); String oneline; System.out.println( "Enter any number of strings, one per line; " ); System.out.println( "Terminate with empty line: " ); try while( ( oneline = in.readline( ) )!= null &&!oneline.equals( "" ) ) array.add( oneline ); catch( IOException e ) System.out.println( "Unexpected IO Exception has shortened amount read" ); System.out.println( "Done reading" ); 01/13/2004 return array; Lecture 1 16

Exceptions & Errors An exception is an object that is thrown from the site of an error and can be caught by an appropriate exception handler. Separating the handler from error detection makes the code easier to read and write. Do not use exception as a cheap goto statement. Better to pass it on to calling procedure. More reliable error recovery without simply exiting. User-defined exceptions can be created or thrown. The try region is a guarded region from which errors can be caught by exceptions. Errors are virtual machine problems. OutOfMemoryError, InternalError, UnknownError are examples of errors. Errors are uncrecoverable and should not be caught. 01/13/2004 Lecture 1 17

Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss 2002 Addison Wesley Figure 2.12 Common standard run-time exceptions 01/13/2004 Lecture 1 18

Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss 2002 Addison Wesley Figure 2.13 Common standard checked exceptions 01/13/2004 Lecture 1 19

Input/Output Streams are used for I/O Terminal I/O treated in the same way as File I/O. Predefined streams System.in, System.out, System.err readline and StringTokenizer are useful methods for formatted input; they are part of java.io.bufferedreader and java.util.stringtokenizer respectively. 01/13/2004 Lecture 1 20