Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming
Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose this D. Glinos COP3330 Object Oriented Programming 2
You may take the exam at any time during the day, but you must finish before midnight No class or office hours on exam days D. Glinos COP3330 Object Oriented Programming 3
D. Glinos COP3330 Object Oriented Programming 4
Exam Format 25 multiple choice questions 45 minutes to answer all of them average 1.8 minutes (108 seconds) per question approximately half will involve looking at code and answering questions about it output of snippet statement to complete remaining questions will ask questions about concepts choose correct Java statement D. Glinos COP3330 Object Oriented Programming 5
Topic Coverage Java application programming Java as an interpreted programming language compiling and running from the command line using command line arguments Object-oriented programming concepts classes and objects basic features of encapsulation, inheritance, and polymorphism D. Glinos COP3330 Object Oriented Programming 6
Topic Coverage (2) Data types and variables primitive and reference data types Constants Declaring and Initializing variables Default Values Class and Instance Variables Converting Strings to Numeric Data Types Java operators arithmetic, relational, and logical operators, including the remainder operator operator precedence integer division casting and automatic conversions to String type D. Glinos COP3330 Object Oriented Programming 7
Topic Coverage (3) Classes and objects access control basics multi-file programs constructors, including default constructors class and instance variables and methods Control flow if, if-else, and switch statements while, do-while, and for statements break and continue enhanced for statement (in arrays lecture) D. Glinos COP3330 Object Oriented Programming 8
Topic Coverage (4) Characters using charat() to read characters from a String how characters are read in as ints when read from a text file casting an int to a char comparing chars using == using single quotes for literals using Character.equals() to compare Strings reference type using double quotes for literals using length(), charat(), and trim() instance methods using + to concatenate using StringBuilder() using equals() instance method to compare finding elements and substrings converting between numbers and strings D. Glinos COP3330 Object Oriented Programming 9
Topic Coverage (5) Basic I/O processing command line arguments using a Scanner, including nested scanners how we use nasnext(), next(), nextline(), nextint() and nextdouble() methods string output using print() and println() formatted output using printf() Random number generation using Random class object generating an integer within a range generating real numbers within a range D. Glinos COP3330 Object Oriented Programming 10
Topic Coverage (6) Arrays what an array is and its characteristics how we access its elements using an integer index how we declare, create, and initialize arrays using multi-dimensional arrays default values for array elements obtaining the length of an array using array initializers passing arrays to methods difference between iterating using for-loop and enhanced for-loop D. Glinos COP3330 Object Oriented Programming 11
Not on Exam Installing Java and Eclipse Using Eclipse testing and verifying programs from the command line command line navigation Java naming conventions big numbers short-circuit evaluation Math class methods NumberFormat class code points and code units regular expressions exception handling (e.g., when reading a file, or array index out of bounds) Arrays utility class methods D. Glinos COP3330 Object Oriented Programming 12
Pop Quiz (1) D. Glinos COP3330 Object Oriented Programming 13
Pop Quiz (1) D. Glinos COP3330 Object Oriented Programming 14
Pop Quiz (2) D. Glinos COP3330 Object Oriented Programming 15
Pop Quiz (2) A 2-D array in Java is just a 1-D array where each element is itself a 1-D array The length of a 2-D array is just the length of its first dimension D. Glinos COP3330 Object Oriented Programming 16
Integer Arithmetic Basic rule: Arithmetic operations on integer variables produce integer results, even if we assign those results to double or float variables Example: int a = 5; int b = 2; int c = a / b; ß the value of c is 2, not 2.5 double d = a / b; ß the value of d is 2.0, not 2.5 To get a double result, we must use a double in the computation part of the expression. We can do this by casting one of the values, but we must be careful: double e = (double) ( a / b ); ß the value of e is still 2.0 double f = ( (double) a ) / b; ß the value of f is 2.5 (finally!) D. Glinos COP3330 Object Oriented Programming 17
Default Values Default values depend on the data type numeric data types: 0 boolean: false char: \u0000 all reference types: null When do variables get their default values? class and instance variables: when created arrays: when created, even if local local variables (other than arrays): must be explicitly initialized Output: Note: c[0] is null because the second dimension was never allocated D. Glinos COP3330 Object Oriented Programming 18
De Morgan s Laws De Morgan's Laws may be helpful when evaluating logical expressions:! ( a && b ) is equivalent to! a! b! ( a b ) is equivalent to! a &&! b For more info, see the Wikipedia page D. Glinos COP3330 Object Oriented Programming 19
Evaluating Logical Expressions Suppose we are given: boolean a = true; boolean b = false; boolean c = true; Q1: What is the value of! ( b && a )? Q2: What is the value of! ( b c )? Q3: What is the value of! ( b (! c ) )? D. Glinos COP3330 Object Oriented Programming 20
Evaluating Logical Expressions Suppose we are given: boolean a = true; boolean b = false; boolean c = true; Q1: What is the value of! ( b && a )? Answer: true, since b && a is false Q2: What is the value of! ( b c )? Q3: What is the value of! ( b (! c ) )? D. Glinos COP3330 Object Oriented Programming 21
Evaluating Logical Expressions Suppose we are given: boolean a = true; boolean b = false; boolean c = true; Q1: What is the value of! ( b && a )? Answer: true, since b && a is false Q2: What is the value of! ( b c )? Answer: false, since b c is true Q3: What is the value of! ( b (! c ) )? D. Glinos COP3330 Object Oriented Programming 22
Evaluating Logical Expressions Suppose we are given: boolean a = true; boolean b = false; boolean c = true; Q1: What is the value of! ( b && a )? Answer: true, since b && a is false Q2: What is the value of! ( b c )? Answer: false, since b c is true Q3: What is the value of! ( b (! c ) )? Answer: true, since!c is false, which makes b (!c) also false D. Glinos COP3330 Object Oriented Programming 23
Sample Code Output Question (1) Question: What is the output of the following program? D. Glinos COP3330 Object Oriented Programming 24
Sample Code Output Question (1) Question: What is the output of the following program? Answer: p = 102 D. Glinos COP3330 Object Oriented Programming 25
Sample Code Output Question (2) Question: What does the following method do? D. Glinos COP3330 Object Oriented Programming 26
Sample Code Output Question (2) Question: What does the following method do? Answer: It computes the average value of an array of doubles D. Glinos COP3330 Object Oriented Programming 27