












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of the first lecture in a data structures course using java. Topics covered include an introduction to java, its development kit (jdk), and its use cases. The lecture also discusses the programming environment, including the jdk, jcreator editor, and java's primitive types. Students will learn how to create and execute a simple java program.
Typology: Study notes
1 / 20
This page cannot be seen from the preview
Don't miss anything!













Giri NarasimhanECS 389; Phone: x
01/13/
Lecture 1
Midterm & Final Exams
-^
Programming Assignments
-^
Class Participation
01/13/
Lecture 1
packages.
01/13/
Lecture 1
-^
applications
-^
applets
-^
-^
01/13/
Lecture 1
-^
Hello.jcw
-^
Hello.jcp
-^
Hello.java
-^
src_hello.txt
-^
Hello.class
-^
-^
01/13/
Lecture 1
Hello.java public
class
Hello
public
static
void
main(String[]
args)
System.out.println("Hello,
01/13/
Lecture 1
Data Structures & Problem Solving using JAVA/2E
Mark Allen Weiss
© 2002 Addison Wesley
01/13/
Lecture 1
8 primitive types: byte
, short
, int
, long
, float
, double
, char
boolean
-^
Non-primitive types are all reference types
reference types are simply pointersassignments to reference typesdeclaring an object
creating an object
garbage collectionreference types as parameters of methodscasting
String
type: concatenation, length, comparison, sub-string,
conversion
01/13/
Lecture 1
01/13/
Lecture 1
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 ] );} // 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" );} System.out.println( "Done reading" );return resize( array, itemsRead );}
Figure 2.6, 2.7, page 42-
01/13/
Lecture 1
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 ) );} // Read an unlimited number of String; return an ArrayListpublic 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" );return array;} }
Figure 2.8, page 44
01/13/
Lecture 1
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 codeeasier 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/
Lecture 1
Data Structures & Problem Solving using JAVA/2E
Mark Allen Weiss
© 2002 Addison Wesley
01/13/
Lecture 1
-^
-^
-^
-^