Computer Programming I
Computer Programming I CS 121
Popular in Course
Popular in ComputerScienence
This 16 page Class Notes was uploaded by Kylee VonRueden on Wednesday September 30, 2015. The Class Notes belongs to CS 121 at Pace University - New York taught by Staff in Fall. Since its upload, it has received 11 views. For similar materials see /class/217106/cs-121-pace-university-new-york in ComputerScienence at Pace University - New York.
Reviews for Computer Programming I
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/30/15
CS121IS232 Review for Midterm l Expressions 7 Review worksheet Problems occur with integer and double division left to right association and casts 2546but2540625 25426212 double 25 4 60 but 25 double 4 625 2 Identi ers Identi ers begin with a letter which may be followed by any number of letters and digits They may also have one underscore character 3 Print statements Systemoutp1int prints the contents of the parentheses and stays on the same line Systemoutp1intln prints the contents of the parentheses and goes to the neXt line A plus sign is used to concatenate two strings so that one is attached to the end of the other 4 If 7 else statement if condition Statement else Statement The Statement may also be an ifelse statement You can put them together in many different ways Compound statements use ampamp and H or and not if birthmonth month ampamp birthday gt day age age 7 l 5 Short answers Review the lecture sheets There may be questions on datatypes classes methods constructors etc 6 SyntaX errors One question with two classes and a lot of syntaX errors Find the errors circle them and indicate what is wrong 7 Short assignments and print statements Questions like Write a statement that will print out your animal s name and age Questions 8 9 and 10 Program with parts to write You are to ll in the code in the three methods in the Panda class that are empty The question will not be the same as the one below but it will be similar package zoo An application that calculates a panda s body mass indeX public class ZooKeeper public static void mainSt1ing args Panda panda new Panda 0 pandagetData pandacalculateBlH pandadisplayData 0 main ZooKeeper package zoo import javautilScanner public class Panda private String name private double weight height bmi Scanner scan new Scanner Systemin public void getData getData public void calculateBMI calculateBMI public void displayData displayData Panda Pace University Fundamental Concepts of CS1 21 Dr LiXin Tao httpcsispaceeduliXin Computer Science Department Pace University October 12 2005 This document complements my tutorial Introduction to Java Programming It serves as a review outline All questions in quizzes and exams will be based on concepts listed in this document Most of the skills that you need for writing Java programs are also listed in this document Make sure that you can answer all the questions or understand the listed concepts for each section that we have covered I Copyright Dr Lixin Tao Pace University ltao paceedu This document should not be copied partially or in full or published in any form without the permission of the author 1 11 959 908994P N Elk59 9959 gt1 gt0 Computer Systems and Programming Languages Problem vs problem instances What are the differences between a problem and a problem instance for the problem Is a computer program supposed to solve a problem or a problem instance What is the function of a computer program in problemsolving What do we mean when we say that a program is correct What do we mean when we say that a program is robust Structure of a personal computer What is a machine language program What are the relationship among computer hardware software and data What are the functions of CPU main memory hard disk keyboard and display Can data in CPU and main memory survive power failure Can data in hard disk survive power failure How many devices can send data through the system bus simultaneously How many devices can receive data through the system bus simultaneously Why we need the main memory instead of letting CPU run programs on the hard disk directly CPU Which computer device de nes and implements the machine language of a computer architecture What is the function of the program counter What is the function of generalpurpose registers in a CPU Which are the major phases for the CPU to execute a machine instruction How are activities of a CPU synchronized Memory For a computer what is a bit a byte or a word How is the main memory organized What is memory address What is the smallest memory address What is memory value corresponding to a memory address When a value is written into a memory cell what happens to the original value in that cell When a value is read out of a memory cell is the current value in the memory cell modified The main memory is used to store programs or data Even though memory hardware can only store binary bits how can a memory store different types of data like integers oatingpoint numbers strings and programs 15 9959 QMerN Disk le system What is the basic unit for storing programs or data on a hard disk What components a le name may contain What is the function of a le name extension What is a le system directory Can a directory contain another directory Should we use short and encrypt le names or concise le names that convey the purpose ofthe les 7 What is a le system directory tree 8 What is the working directory for a Command Prompt window 9 What is the absolute path ofa le 10 What is the relative path ofa le 11 Which directory does period represent 12 Which directory do double periods represent 16 Display 1 What is the main function of a computer display 2 What is a pixel 3 What is the resolution of a display 4 What are the text mode and graphics mode of a display 5 In the text mode of a display what is the function of a display cursor 6 Which key strike will cause the display cursor to terminate the current line and move to the beginning of the following line 7 In the graphics mode of a display what kind of coordinate system is used to de ne the position of a pixel 17 Keyboard 1 What is the function of a keyboard 2 What is an active window 3 Which keys can generate white space characters 18 Computer Software 1 What is computer software 2 What are the two major types of software Give examples 3 Can you list the names of three highlevel programming languages 19 Java programming language What is a Java keyword or reserved word Why we need highlevel programming languages What is source code What is executable code What is a bytecode le What is a class le What is an interpreted programming language 2 N 509 NHHHHHHHHHH owoo ombwmwo What is a compiled programming language How is Java program source code translated into machine instructions to be executed by a CPU What is Java virtual machine What is the name of the command for compiling Java source les into bytecode les What is the name of the command for executing the Java bytecode les Is a Java bytecode le hardware or operating system dependent Java was launched by which company and in which year What is the syntax structure of an identi er What is good practice for identi ers so Java program maintenance can be easier What are Java reserved words or keywords Does a Java class s name capitalize its rst letter Does a Java method s name capitalize its rst letter Does a Java variable s name capitalize its rst letter Software Installation 908994P N O D ID ID ID I LAND 039 What is JZSE Java 2 Standard Edition for What is JZSE SDK Software Development Kit also called JDK for What is JZSE JRE Java Runtime Environment for What is the current version of JZSE What is the base URL for downloading Sun JZSE SDK Does the installation of JZSE SDK also install JZSE JRE as part of it Where are commands javacexe and javaexe located in a JZSE SDK installation What is the composition and function of environment variable PATH What is the composition and function of environment variable CLASSPATH How to temporarily change the value of CLASSPATH in a Command Prompt window If we don t set any value for CLASSPATH what is CLASSPATH s default value How to start a Command Prompt window Inside a Command Prompt window how to change the working directory how to compile and run a Java program Java Basics 59 H 9939 gt1 Basic Hello World program How to write the basic Hello World program as simple as possible but it can compile and run Are public class static and void Java s reserved words Are Java programs casesensitive What le name should be used for holding the declaration of a public class named Welcome Can a Java source code le contain more than one public class To print a message to the display and then move the display cursor to the beginning of the following line use SystemoutprintlnquotMessageToBeDisplayedquot Each statement must terminate with semicolon 000 O 32 l N V39 509080 A Java program contains one or more classes and a class contains one or more methods The body ofa class or a method is enclosed in a pair of curly braces Java character string constants literals are enclosed in straight double quotes as quotHello worldquot When a Java program is run its method main is the rst method to be called and executed Method main must read as public static void mainString args Code style and command line arguments On any source code line signi es the beginning of a Java comment and the comment ends at the end of the line A comment will be replaced by the compiler with a white space character It is important to add proper comments inside a source le so people can understand the program s logic Comment is an important form of software documentation Space Tab and Enter keys generate white space characters and in a Java source code le a single white space is equivalent to any number of white space characters How source code should be indented for supporting a good source code style What are the two main styles of writing Java source code as to the position of the opening curly braces Should we use a mixture of the two source code styles in the same project What are commandline arguments of a Java program How to access the commandline arguments inside method main How to print a message and then leave the display cursor to the right of the last character printed 10 How can operator concatenate a few strings into a single one 33 QMerN 9 3 5 bP N Java package What are Java packages for Can a Java package contain another package How to declare that a class belongs to a particular package Where must the package declaration be in a source code le Does a package declaration need a semicolon to terminate it How is Java package implemented in a le system If a class belongs to package cs121 in which directory that the bytecode le for the class must be kept What is the most convenient way to compile a Java class into a speci ed class base directory and generate the necessary directories for the corresponding packages on the package path for the class automatically How to run a class that belongs to a package Best practice for organizing multiple class projects What is the best practice for organizing multiple class projects Where should we save the source les for classes belonging to some Java packages What is the advantage of separating Java source code from the bytecode les How should we set up CLASSPATH value so that we can run the projects from any working directory 9939 509 D lb lb Nt IO In which working directory should we compile a project Do we need to compile explicitly each Java class source code le in a multipleclass project How can we compile a project so that the bytecode les are stored in the same directories as their corresponding Java source les Can the classlevel variables ofa class be accessed by all methods ofthe class If a classlevel variable has no value initialization during declaration what will be its default value If a variable has value null what is the meaning How can we access a public and static variable of a class What is the meaning for a method to invoke another method 35 Local variables expressions and assignment QMerN Where can local variables be declared The local variables will be accessible in which scope Why a variable needs to be declared to have a xed data type What do people mean when they say that Java is a stronglytyped language Will the value stored in a variable be modi ed if we read the variable s value out Will the value stored in a variable be modi ed if we store a new value into the variable If a local variable is declared with no initial value is the variable going to have a default initial value How to declare local variables with initial values How to declare multiple local variables of the same type in the same Java declaration Can we declare the type of a variable more than once in the same method Can we read the value of a variable before it is declared Can we read the value of a variable before it is initialized What is the difference between the operator in a Java assignment from the mathematical relational operator How is an assignment statement executed Can the left side of operator in an assignment statement be anything other than a variable What is the meaning for a variable to appear to the right side of operator in an assignment statement Assume x 1 What is the value of variable x after the execution of expression x Assume x 1 What is the value of expression x Assume x 1 What is the value of variable x after the execution of expression x Assume x 1 What is the value of expression x What is the result of applying operator to a string value and an integer value like quotCSquot 121 What kind of expressions has side effects 36 Basic built in data types and type casting 959 List four popular Java builtin data types Do Java data types have fixed lengths on all hardware and operating system platforms How many bits are used to store a Java int value How many bits are used to store a Java double value How many bits are used to store a Java char value 5 9080 0 b D lb ib ib ib D lD i IONUIAUJNt O39 NNNNND l bUJNb OW NNN IONUI LANN 0000 What is the data type for literal 12 What is the data type for literal 120 What is the value of 72 What is the value of 702 What is 5 2 What is type promotion How can we change the operator evaluation order in an arithmetic expression Literal values of type char must be enclosed in what kind of delimiters What is implicit data type casting Can we assign a double value into an int type variable What is explicit data type casting When do we need to use explicit data type casting 18 Is a relational expression also a boolean expression What is the value of1 gt 1 What are the three most important Boolean operators When will the conjunction of two Boolean expressions be true What is the value of i lt 5 ampamp i gt 5 When will the disjunction of two Boolean expressions be false What is the value of i lt 5 H i gt 5 How to convert a stringform int value into an int value How to convert a stringform double value into a double value How to convert a stringform boolean value into a boolean value How to retrieve the second character of a string How to convert a lowercase letter into its uppercase counterpart 3 1 What are the valid values of a boolean type variable What are the values of the following method invocations against class Math abs2 ceil15 oor15 exp00 logo max1 2 min10 20 pow20 30 sqrt40 random Bertram 990w 37 Command line arguments and loops N E 8094 How to specify a commandline value that contains space characters Assume the method main has parameter args Which commandline argument will be stored in args0 If there is no commandline arguments used for a run what is the value of expression argslength Which Java library class can be used to sort an array of numbers or strings What is a compound statement Can a compound statement contain local variable declarations Where Is the body of a method a compound statement 6 509 Is the body of a class a compound statement Can we replace any statement in a program with a compound statement without violating the syntax speci cation for Java If we declare a local variable inside a compound statement can we access that variable outside of the compound statement When will a while loop terminate Can the body of a while loop be a single statement Enumerate the steps for a while loop to be executed What is a loop iteration What is a loop variable Where should the loop variable for a while loop be declared and initialized What will happen if we don t modify the value of the loop variable for a while loop during its iteration What is the control block of a for loop What is the function of each of the three components of the control block of a for loop Which character should be used to separate the three components of the control block of afor loop If we declare the loop variable in afor loop s control block can we access this loop variable outside the loop body Enumerate the steps for a for loop to be executed Normally where do we declare a loop variable and initialize it for a for loop If a program runs into an in nite loop for some special input data can the program still be a correct program What is lexicographic order for character strings 38 Calculator with if else statements 1 2 3 4 5 6 7 8 9 l 0 How to find the length of a onedimensional array What is n for in a string literal What is t for in a string literal How is an ifstatement executed Is the pair of parentheses for the Boolean expression of an if statement optional How to chain a list of several if statements together What is Systemexitint for What is the meaning of values for variable x in Systemexitx When must we use Systemexitint When can we use as a commandline argument 39 Calculator with switch statement 1 4 V39 Variables of which data types can be used for the switch expression of a switch statement Can we omit the pair of parentheses around the switch expression Do we need a semicolon at the end of a compound statement Can the case values of the case labels be of different data types from that of the switch expression Can multiple case labels have the same case value 7 Hewwsa Is the default case mandatory Is the order of the cases important Can a statement have multiple case labels in a switch statement What is the meaning of a break statement in a switch statement How is a switch statement executed What will happen if the statements for a switch case is not terminated with a break statement or a System exitint statement 310 Calculator with exception processing WP ws w D ID ID ID I LAND 039 14 UI What is a Java exception Give two examples that Java code will throw exception objects If a method receives an exception object not caught by a trycatch block what will happen What is a trycatch block for Is the try clause of a trycatch block optional Are the catch clauses of a trycatch block optional Is the nally clause of a trycatch block optional What statements should be put in the try clause What is the parameter of a catch clause for When will a catch clause be executed When will a nally clause be executed What kind of exceptions will be caught by catch Exception e How does a trycatch block work What will happen if an exception is thrown to method main and it is not caught by a catch clause What is the difference between Java comments delimited by and those delimited by 4420 and gt7 What will happen if form of comments are embedded inside a pair of and 311 Conditionally interrupting loops 1 If a loop executes statement break what will happen 2 If a loop executes statement continue what will happen 312 Arrays 1 How to declare 1000 inttype variables on one Java source code line 2 How to declare that variable x is of type array of ints 3 How many bits will be used to implement an array variable 4 Does the declaration of an array variable also allocate space for the array 5 How to allocate an array for 10 integers and connect this array with an int array variable x 6 If an array has length 10 what are its valid index values 7 What is the easiest way to declare y to be an int array variable and connect it with an int array of length 1 containing value 1 i ooo LA How to declare a 2D int array variable with name 2 How to allocate space for a 4 X 4 square int array and connect it with variable 2 To access the cell at row 2 and column 3 of array 2 should we use expression z2 3 or z32 or z2 3 How to declare that 23 is a 3D int array variable How to allocate space for a 4 X 5 X 6 int array and connect it with a 3D int array variable 23 To access the cell on plane 1 row 2 and column 3 should we use eXpression z3l23 or z332l or z3l 2 3 313 Method declaration and invocation H gt P gtP Nt b D lb ib lb i ONUIAUJN NHHH 00001 What are Java methods for What is a method s signature Are parameter names parts of a method s signature What is method return type What do we mean if we say that a method has void as its return type What is method parameter list What is a method declaration What is a method invocation What is a method s body If a method has no parameters do we still need the pair of parentheses for the parameter list If a method has two parameters x and y both of type int can we declare them as in int X y Can we declare local variables inside a method declaration Where Can we declare the type of a variable more than once in the same method What are the differences between method parameters and method arguments How are the values of method arguments passed to method parameters Can a method invocation contain different number of arguments that the number parameters in that method s declaration How is a method invocation eXecuted Are parameters of a method part of the local variables of the method Where can the method parameters be accessed If a method contains only one statement can we omit the enclosing curly braces for the method body Should we capitalize the initial letter of a method s name What character is used to separate the successive parameters declarations in a method s parameter list How can we change the name of a parameter without changing the containing method s signature or function If a method s body eXecutes statement retum what will happen If a method s body eXecutes statement return 22 what will happen If method a calls method b which in turn calls method c what is the order for the three methods to complete their eXecutions Is the order of method declarations in a class important Can a static method s body invoke a nonstatic method What is the value of eXpression l gt 2 l 2 9 314 Java documentation comments How to write aJava doc comment What are Java doc comments for Where should Java doc comments be located What is the general structure of aJava doc comment Which tag should be used to specify a parameter in aJava doc comment Which tag should be used to specify the method return value in aJava doc comment How to generate Java documentation HTML les for all the Java source code les in the current working directory Which generated le is the root le for the resulting HTML documentation How to let the Java documentation list both public and private methods QMerN 509 93 H Ul Scopes of local variables 1 Where can the method parameters be accessed What is the scope of a local variable Can a local variable declared in a compound statement be accessed from a nested compound statement after this declaration 4 If a loop variable is declared in the control block of a for statement can we access that variable outside of the for loop 9 316 Formatting output 1 What is the purpose of method Systemoutprintf 2 What is the rst parameter of Systemoutprintf for 3 What does 42f stand for as part of the rst argument to Systemoutprintf 4 What does 6d stand for as part of the first argument to Systemoutprintf 5 If the rst argument of Systemoutprintf contains 3 substrings of form similar to 42f or 6d how many total arguments must be used in this method invocation 6 What is the major difference between a variable of type int and a variable of type Random 7 How can we generate random integers between 0 and 9 inclusive 8 How can we generate random double values between 00 inclusive and 100 exclusive 9 What is the meaning ofz39mportz39ng a class 10 How to declare that a class needs to import a particular class from a particular package 317 Timing the evaluation of 71 1 Can Java double typed variables store all accurate oatingpoint numbers 10 2 What may happen if a loop is controlled by a Boolean expression that checks whether a double variable has a particular value What value will be returned by an invocation to method SystemcurrentTimeMillisO How many bits are used to store a Java long typed variable 5 318 Matrix multiplication 1 What is the function of method setSeedz39nt of class Random 2 How to check the number columns that a twodimensional array a has 3 How to avoid repeating similar code in a program 319 Interactive command line data input 1 How to use class javautz39lScanner to get the next integer from a Command Prompt window 2 How to use class javautz39lScanner to get the next double value from a Command Prompt window 3 How to use class javautz39lScanner to get the next line from a Command Prompt window What should we do before we wait for some user input from a Command Prompt window 4 320 Window based data inputoutput 1 How to pop up a window and request the user to input a string 2 How to pop up a window to print out some message 3 When should we use Systemexitint to terminate a program s execution 321 Text le inputoutput Ni How to open a text le for reading its contents line by line How to open a text le for writing text data into it with methods print printan or print How to check whether a le is in existence already How to close a le Why do we need to close a le When should we use a clause like throws IOException for a method How to remove the leading and trailing white space characters in a string How to parse a string into whitespaceseparated tokens strings that don t contain white space characters 9 How to import all classes in a package 10 What type of exception that the le manipulation methods may throw 9 89 er 322 Recursive vs iterative methods factorial ll Elk WP 0 90gtl 323 2 N 5 908994P N What kind of methods are iterative methods What kind of methods are recursive methods What is an activation record for a method s invocation Can we have multiple un nished invocations to the same method Are the local variables of a method shared by multiple unfinished invocations to the method What will happen if a method executes statement throw new Exception reason for this exception When should we use recursive solutions When should we use iterative solutions Recursive vs iterative methods Fibonacci numbers Why the recursive solution for Fibonacci numbers is much slower than that based on a loop Which version of the solution is easier to write and read Algorithm and Towers of Hanoi What is an algorithm Does an algorithm have to stop for any valid input data What is the time complexity of an algorithm What is the space complexity of an algorithm What is the Towers of H anoi problem Bubble sort What do we mean for sorting an array of integers What is the main idea of bubble sort What is the function of the outside loop of the bubble sort method What is the function of the inner loop of the bubble sort method The running time of the bubble sort method will be proportional to what expression of the input size Binary search What is a data record What is the key field of a data record Can different data records have the same value for their key field What is the data search problem How does sequential search work What are the best case and worst case time complexities of sequential search How does binary search work What are the best case and worst case time complexities of binary search 12 CS121IS232 Review for Final 1 Expressions 7 One expression with a division remainder modulus and a cast 1452while1454 int 28 2 double 14 5 20 2 for loops 7 what do they print See the second midterm 3 If 7 else statement if condition Statement else Statement The Statement may also be an ifelse statement You can put them together in many different ways Compound statements use ampamp and H or and not if birthmonth month ampamp birthday gt day age age 7 l 4 Short answers on the most recent lectures 5 Array questions Read a for loop and ll in an array Modify the array using another for loop Write a for loop and a while loop that do something with the array 6 More array questions 7 ones like those on arrays of Strings in worksheet 7 7 Fill in the code for three methods similar to the ones you did for the rst Attendance class the one with a single array of integers and not the one that computed the gate 8 Multiple choice and ll in the blanks questions from the department These are cumulative
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'