Final

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

float

A float data type in Java stores a decimal value with 6-7 total digits of precision. So, for example, 12.12345 can be saved as a float, but 12.123456789 can't be saved as a float. float a = 2.356f;

Which is the Java library that will help you access more tools to manipulate and sort arrays? java.util.Arrays java.util.Array java.list.Array java.list.Sort

A.

You are developing a user interface for a software application. How would you proceed with this process? You would perform user analysis, and collect functionality requirements. You would determine the security measures, and collect functionality requirements. You would perform hypothesis testing, and secure user data. You would determine the usability testing, and security measures. You would determine the scope testing, and user information generation.

A. Determining security measures, conducting scope testing, and performing hypothesis testing are not part of user interface development.

Examine the following code. What control statement would fit best in the else block (the what goes here? question)? for(int beancounter = 0; beancounter < 25; beancounter++) { if(beancounter == 23) { break; } else { //what goes here? } } A. Continue B. Return C. Break D. Void

A. Explanation Because we are using the break if the value is 23, the logical opposite would be to continue processing. In this case it is not necessary, but it does provide a clear view of your intention with this loop.

Why is the word final used to describe a constant in Java? A. The value of the constant cannot change through the execution of the program B. The value of the constant cannot change for any of the Java programs C. The constant gets a final value at run time D. The constant gets a final value at print out

A. Explanation The word final is used to describe a constant in Java because once declared the value of the constant cannot change through the execution of the program.

What is the purpose of the following Java code in context of a doubly-linked list? Node myNode = new Node(element); Node end = head; while(end.next != null) { update } Looping until the last node is found. This code will result in an error. Looping to find the first node of the list. Rotating the head and the tail.

A. Explanation This code loops until it finds the last node; if the last node has a next value of null, it is the tail.

Which statement is true? Regular queues use the first-in, first-out structure while priority queues remove elements based on priority. The first-in, first-out structure is used for regular and priority queues. The first-in, first-out structure is mandatory for both regular and priority queues. The first-in, first out structure is mandatory for regular queues, and optional for priority queues.

A. Explanation Unlike regular queues, the first-in, first-out structure does not apply to priority queues. Priority queues remove elements based on the highest priority. remove items based on their priority. The highest priority is removed first.

If you were to create a rounded rectangle, which option correctly creates the shape? A.RoundRectangle2D newRect = new RoundRectangle2D.Float(5, 20, 200, 43, 2, 2); B. RoundRectangle2D newRect = new RoundRectangle2D.Float(5, 20, 200); C. RoundRectangle2D newRect = new RoundRectangle2D.Float(5, 20, 200, 43); D. RoundRectangle2D newRect = new RoundRectangle2D.Float(5, 20, 200, 43, 2, 2, 15, 1);

A. Rounded rectangles include starting and ending x, y coordinates as well as the angle of the arc/sweep on the corners.

Which is the correct way to specify input from the console using the BufferedReader constructor? BufferedReader(new InputStreamReader(System.in)) BufferedReader(System.in) BufferedReader(new InputStreamReader()) BufferedReader(new Console())

A. The correct answer is 'BufferedReader(new InputStreamReader(System.in))' because the constructor takes Reader as a parameter and System.in specifies the standard input stream.

Which of the following translates and executes program code line by line rather than the whole program in one step? A. Interpreter B. Translator C. Assembler D. Compiler E.Executor

A. An interpreter translates and executes program code line-by-line.

Which is true about an interface definition? The methods have no bodies. The method definitions do not have parameters. It cannot be public. There are no variables.

A. Explanation An interface is like a blueprint. The method's parameters and return type are defined, but there is no method body.

Which method retrieves and removes the first element from a deque? pollFirst removeFirst remove peek

A. Explanation The pollFirst method will both retrieve and remove the head item.

What is the output of the below code: public class Example3 { public void action(char[] num, char x) { num[2] = 'b'; x = 'a'; } public static void main(String[] args) { Example3 ex = new Example3(); char[] vals = new char[] {'a', 'b', 'c'}; char x = 'c'; vals[0] = 'c'; System.out.println(''x='' + x + '' vals= '' + vals[0] + '' '' + vals[1] + '' '' + vals[2]); ex.action(vals, x); System.out.println(''x='' + x + '' vals= '' + vals[0] + '' '' + vals[1] + '' '' + vals[2]); } } A. x=c vals= c b c x=c vals= c b b B. x=c vals= c b c x=a vals= c b b C. x=c vals= a b c x=a vals= c b b D. x=c vals= c b c x=c vals= c b c

A. The correct answer is: x=c vals= c b c x=c vals= c b b When an array is passed to a function, the local variable gets the array reference and the changes to the array are done to the memory location. A simple variable such as character variable only stores the value passed and so any changes are to the local variable only.

The process of manually setting components' properties without the use of the layout manager is known as? Manual positioning Absolute positioning Absolute sizing Manual posizing

Absolute Positioning Explanation While it is highly recommended that layout manager of the container is set as the basis for the components' properties, it is entirely possible to do without it by laying out components. This is known as absolute positioning.

WindowListener

Acts on events in the window

When creating a JLabel that has an icon instead of text, what do you need to create first? An empty JLabel with no text An instance of ImageIcon You can only have a text-based JLabel A new FlowLayout object

An instance of ImageIcon Explanation ImageIcon logo = new ImageIcon(Location of image); JLabel lbl = new JLabel(logo);

If all elements of an array are of the same type, the array is said to be _____. A. uniform B. homogeneous C. heterogeneous D. linear

B.

What is one of the characteristics of a non-static method in Java? A non-static method belongs to the class A non-static method belongs to an instance of the class A non-static method can access a static method by creating an instance of the class A non-static method can access a static variable by creating an instance of the class

B. Explanation A non-static method, belongs to an instance of the class, and not to the class. Since static methods and static variables belong to the whole class, they can be accessed by a non-static method without having to create an instance of the class.

Which of the following correctly checks to see if the current node is the head of a doubly linked list? Node myNode = new Node(element); (if(myNode.next == null) { } Node myNode = new Node(element); (if(myNode.prev == null) { } Node myNode = new Node(element); (if(myNode == null) { } Node myNode = new Node(element); (if(myNode.next == tail) { }

B. Explanation If the previous pointer is null, it means that the current node is the head of the list.

What is the requirement for an internal sort? A computer that is fast enough. Enough memory to hold all the data. Enough disk space. A Quick Sort program

B. Explanation Internal sorting is where the memory provided is large enough to hold the entire data set.

To print an integer right justified with a width 15, the correct format string for System.out.printf method would be: A. "%15r'' B. ''%15d'' C. ''%15rd'' D. ''%15.0d''

B. Explanation The correct answer is ''%15d'' where 15 specifies the width and since it is positive it is right justified and d specified integer

What is missing from the following Java code? A. An instance of the Random class B. An integer for the upper value C. Integer variable v1 is invalid D. An integer for the lower value

B. Explanation We would need to pass an integer to the nextInt(int n) function (e.g., r.nextInt(50)). The lower bound (min) isn't required, since Java would just use zero.

Which of the following Java statements best depicts the instantiation of the first element within a stack? public int push(); private Node top; private Node tail; public int pop;

B. Explanation We use a class (usually called Node) to represent an element in our linked list. Since the head of the list is the one we can use in a stack, we can name it top.

Which statement is not true about the static methods? Static methods can have multiple parameters Static methods can be overridden Static methods can be overloaded Static methods can return a value

B. The correct answer is 'Static methods can be overridden'. Since static methods are resolved at compile time, even if the child class has an identical method as the parent, it is not overridden but rather hidden.

Which command in a Java switch statement is the catch-all for values that don't meet the criteria? A. return B. default C. exit D. break

B. Explanation Always use default! It doesn't matter how air-tight the code is, there is always opportunity for a value to slip in that doesn't pass the expression and then you will have errors.

Examine the following code. What is the default value of the variable validEntry? boolean validEntry; A. True B. False C. 0 D. No value

B. Explanation Java cannot read your mind when it comes to boolean variable declarations. That said, the default for the boolean primitive type is FALSE. If you do not declare your variables with an initial value, it could give you headaches later!

Which data types are allowed in a Java switch statement? A. int, short, byte, double B. string, int, long, char C. double, float, int D. string, float, double

B. Explanation Doubles and floats are not allowed because of precision and rounding issues. However, the switch statement is a very powerful tool for evaluating int, long, char, or Strings.

The main method is called from _____ after your Java program is loaded into memory. another method in your program the Java Virtual Machine an error handler the operating system

B. JVM Explanation The operating system (such as Windows or Linux) first loads the Java Virtual Machine (JVM) into memory. The JVM then loads your compiled Java program and passes control to its main method.

What happens when you compile and run the following Java program? Class HelloWorld{ public static void main (String[] args){ System.out.println("Goodbye") } } A. HelloWorld is printed on the screen B. There is an error during compiling C. Goodbye is printed on the screen D. Nothing is printed on the screen

B. the semicolon is missing

If f(n) is the function then O(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. } is true for which of the following symptotic notations ? Big Oh Theta Omega Big Q

Big Oh

RandomSet <Integer > j = new HashSet(); j.add(9343); j.add(93); j.add(3); Based on the following code, in what order will the values display after iterating through the set? A. 9343 847 0 -52 B. -52 0 847 9343 C. Undetermined until compiled and run D. Random

C.

When writing a program that will do bookkeeping for a small business, the document review step should include going through _____. A. programs that competing businesses use B. what the business owner wants the program to do C. a list of documents to be input into the system D. customer surveys E. a list of user requirements

C.

Which of the following code snippets illustrates a method of multiple inheritance in Java? public class Z extends A, B { } private void Z implements A, B { } public class Z implements A, B { } private class Z extends A, B, implements C { }

C.

Which of the following Java classes is used to create and render 2-dimensional graphics? A. 2DGraphics B. Java2DGraphics C. Graphics2D D. RenderableImage

C. Explanation The Graphics2D class is used to render 2-dimensional shapes, text and images, as well as provide color management, and text layout in Java GUI applications.

In the code below what gets printed after 2: 5? class Main { public static void main(String args[]) { int outerLoop = 2; while(outerLoop <5) { int innerLoop = 4; while(innerLoop < 7) { System.out.println(outerLoop + ': ' + innerLoop); innerLoop++; } outerLoop++; } } } A. 3: 4 B. 3: 5 C. 2: 6 D. 2: 4

C. The outer loop starts from 2 and goes up to 4. The inner loop starts from 4 and goes to 6. After the first iteration of the outer loop (in this case 2), all of the iterations of the inner loop are printed before the next iteration of the outer loop (3). So after 2: 5 will be printed 2: 6

The _____ statement tells the computer to skip to the end of the switch statement A. default B. return C. break D. exit

C. Explanation Using break is not required, but it improves processing time, as the computer doesn't have to go through the whole statement.

In Java, the nextInt(int n) function generates a random number: it is a number between _____ and _____. A. 0; 100 B. 1; a specified number (n) C. 0; a specified number (n) D. 1; 100

C. Explanation By default, the range is 0 to the specified number(e.g. r.nextInt(5) would generate a random number between 0 and 5).

How would you draw a rectangle that is a solid color? g.drawRect(10, 10, 250, 250); g.fillRect(0, 0); g.fillRect(10, 20, 100, 100); g.drawRect(0, 0);

C. Explanation The fillRect method takes a starting and ending x, y coordinate. If you set the fill for the Graphics object (in this case g), it will be filled with that color.

A Java String is a _____. A. method B. void C. class D. primitive data type

C. The string class has several methods for working with strings; when declaring a string you're creating a new instance of the string class.

Which symbols handles calculations, analysis, or other functions? A. Diamond B. weird shape C. rhombus D. rectangle

D.

int [] scores = new int[13]; for(int i = 0; i < scores.length; i++){ ///fill values } In the following code, how many times will the for loop process? A. 12 B. 14 C. 13 D. 10

D.

Which of the following options will allow users to select as many items as they want? A. JCheckRadio B. ButtonGroup C. JComboBox D. JCheckBox

D. Explanation The JCheckBox allows multiple selections; if you want to limit, create a JComboBox, or group elements using ButtonGroup.

Which of the following is NOT a drawback to using recursive functions? Possible program overflow/crash Data types not able to store values Use of system resources Violation of OOP principles

D. Explanation A recursive function can be a powerful tool that performs a large number of calculations in a few short lines of code. But you run the risk of overflow, system resource usage, and overflow of data types.

What is the result of x = 5.0 / 0.0 in Java? A. Error B. 0.0 C. 0 D. Infinity

D. Explanation In Java you can divide a double by 0.0 and the result will be Infinity.

The following code declares a character array with 3 rows and 5 columns: A. int matrix = new char[3][5]; B. char [] [] matrix = [3,5] C. matrix = new char[3, 5]; D. char [] [] matrix; matrix = new char[3][5];

D. Explanation First, declare the multidimensional array Next, set aside the space needed for the array be declaring the rows/columns

What is the output of the below code: public class Example3 { public void action(char[] num, char x) { num = new char[3]; num[2] = 'b'; x = 'a'; } public static void main(String[] args) { Example3 ex = new Example3(); char[] vals = new char[] {'a', 'b', 'c'}; char x = 'c'; vals[0] = 'c'; System.out.println(''x='' + x + '' vals= '' + vals[0] + '' '' + vals[1] + '' '' + vals[2]); ex.action(vals, x); System.out.println(''x='' + x + '' vals= '' + vals[0] + '' '' + vals[1] + '' '' + vals[2]); } } A. x=c vals= c b c x=c vals= c b b B. x=c vals= c b c x=a vals= c b b C. x=c vals= a b c x=a vals= c b b D. x=c vals= c b c x=c vals= c b c

D. The correct answer is: x=c vals= c b c x=c vals= c b c After the array reference is passed to the method, the local array variable is reallocated with new storage and any changes are now made to that local array. The local variable of data type char only changes the local storage so it also does not impact the value in main method.

Which of the following correctly imports only the FileFilter interface of the java.io API? A. import java.FileFilter.*; B. import java.io.*; C. import java.*.FileFilter; D. import java.io.FileFilter;

D. Explanation Using the asterisk after the io will import the ENTIRE API; if we just want the FileFilter tool, we can specify this after the io command. It saves some overhead, especially if you have lot of interfaces and/or a complex program.

What type of statement is the following? int max = 10; A. Integer B. Void C. Control D. Assignment

D. Assignment

What symbol would you use to say 'If the Box is empty'? A. Diamond B. weird shape C. rhombus D. rectangle

DIamond

_____ is an abstract class to map keys to values. Every key in the _____ can only have at most one value and keys and values have to be non-null

Dictionary

A shop has a number of printers each with a different serial number. Some of the printers are on sale. What gets printed out after the following code is executed: costPrinter.put ('HP101', '$195'); costPrinter.put('HP203', '$204')' costPrinter.put('HP101', $159'); System.out.println(costPrinter.size()): 3 2 Error Null

Explanation 2 will be printed out. The Map data type has 2 different values put into the same key and only one value will be saved. So the Map costPrinter() contains only 2 key-value pairs.

Which of the following is a compiled programming language? A. C# B. JavaScript C. Perl D. Python E. Ruby

Explanation C# is a compiled programming language. The others are interpreted languages.

Which type of queue can be used as a queue or a stack? Double-ended queue Regular queue Priority queue Ordered queue

Explanation Double-ended queues can be used as either a queue or a stack.

In order to create a polygon, what do you need to do first? Set the x,y of all points Create a for loop to set the points Manually set the location Create an instance of the Polygon class

Explanation Polygon has its own class and you need to create a new instance of the Polygon class, and then set the points for each part of the shape.

Sally is writing some Object-Oriented Program code for a vehicle which contains the attributes (manufacturer, color, and price), along with what she wants the vehicle to be able to do (start, drive, and park). This is known as a _____. class method function template Template

Explanation Sally is creating a class which is a blueprint of an object. If the class is a 'vehicle', Sally will then provide the guidelines, or blueprints, about this class containing attributes and functions.

Consider a situation where the minimum number of swap operation is required. Which sorting algorithm is best for this use-case? Merge Sort Selection Sort Heap Sort Insertion Sort

Explanation Selection sort requires fewer swap operations as compared to other sorting algorithms.

Which of the following correctly appends a new value specifically to the tail of the following linked list: LinkedList l = new LinkedList(); l.add("M"); l.add("A"); l.add("R"); l.add("S"); l.remove("S"); l.addLast("S"); l.addFirst("S");

Explanation The addLast method will add to the end (tail) of the linked list.

A two-dimensional Java array is allocated all as a single block of memory. True False

Explanation The correct answer is 'False'. A Java two-dimensional array is an array of arrays so the 'row' array is one block and each element's array is a block.

The BufferedReader class has a smaller buffer than the Scanner class True False

Explanation The correct answer is 'False'. BufferedReader has a default 8KB buffer whereas Scanner only has a 1KB buffer. BufferedReader also lets you provide a bigger buffer than the default, if needed.

Dictionary allows null keys and values. True False

Explanation The correct answer is 'False'. Only non-null values are allowed and put method will throw a NullPointerException for null input.

When retrieving an Enumeration of keys from the Dictionary, the keys are in sorted order. True False

Explanation The correct answer is 'False.' The order of the keys is not guaranteed and depends on how the implementing class handles it.

Dictionary in Java is _____. an interface an abstract class an implementing class of HashTable an extension of Map

Explanation The correct answer is 'an abstract class.' It has a number of abstract methods to support mappings of key/value.

Map in Java is _____. an interface an abstract class an implementing class of HashTable an extension of Dictionary

Explanation The correct answer is 'an interface.' It is a newer structure that is meant to replace Dictionary with the same basic functionality, but it has many implementing classes and additional functionality such as computing a mapping based on a mapping function.

The following are examples of GUI classes in Java EXCEPT? JCheckBox ButtonGroup JButtonChecker JRadioButton

Explanation There is no such Java Swing or AWT class for JButtonChecker

Tool Tips are: Classes Constructors Methods Objects

Explanation Tooltip, unlike JTextField and JButton, is not a class in Java. It is, rather, a functionality that is available to GUI components and is implemented as a method.

How can the text in a label component be changed? Text editing at run time Using JFrame Cannot be changed at all Programatically at run time.

Explanation Values of label components can only be changed programatically at run time.

hen you add a new element to the tail of a circularly linked list, what is true of the current tail? It is the first item It connects to the head It has no connections Its value is set to 0

Explanation tail.next = head; This is the code that tells Java that the new tail's next element is now the head, so it keeps the circular list in sync.

What does the binarySearch method allow us to do? Use only the number we're looking for in the array Find the position of the item we're looking for in the array Use both the number and the index we're looking for Find a sub-array with the results of your search

Find the position of the item we're looking for in the array

you wanted to know if a user selected ''Oranges'' from a list of check boxes, which event listener is most appropriate? ItemListener ActionListener MouseListener ContainerListener

ItemListener

Which of the following is required before adding text fields, labels, buttons, or tool tips? JFrame JTextFields JButtons JTextArea

JFrame Explanation The very first task to perform in Java GUI programming is to create an object using the JFrame class.

The layout manager object is an implementation of which interface? JPanel BorderLayout Container layout manager LayoutManager interface

LayoutManager interface Explanation The layout manager object implements the LayoutManager interface.

AdjustmentListener

Listens for adjustments (like a scroll bar being engaged)

ComponentListener

Listens for changes to components (like a label being moved, hidden, shown, or resized in the program)

ContainerListener

Listens for container (like JFrame or JPanel) events

ItemListener

Listens for individual item changes (like a checkbox)

KeyListener

Listens for keyboard interaction

MouseListener

Listens for mouse events (like double-click, right-click, etc.)

MouseMotionListener

Listens for mouse motion

Polymorphism means _____ Data hiding Multiple inheritance Shape-bending Many forms

Many forms

What is the time complexity of the following ? i=0; while(i<n) { j=i; while(j<n && j<i+5) { /* code */j++;} i=j; } O(N) O(N2) O(2N) O(1)

O(N) In this case i goes from 0 to N, but j never goes back to starting from 0, as it always starts from i. This means that the loop always moves forward and doesn't form a quadratic function. The function formed is linear and the time complexity is linear, hence O(N).

Polymorphism supports _____, which is several methods with the same name but different arguments. Overriding Overclocking Overloading Overarching

Overloading Explanation If we have three methods called assembleSandwich() but with different arguments, we've effectively overloaded the method. Java knows which one to use, based on the arguments we send it.

ActionListener

Responds to actions (like a button click or text field change)

T or F For overloading you can have two methods with the same number of arguments, but they can't both be double values, since we already have two of them

T

To print a floating point number with a precision of 2 and a width of 6, the correct format string for System.out.printf would be: ''%2.6f'' ''%6w'' ''%6.2d'' ''%6.2f''

The correct answer is ''%6.2f'' where 6 specifies the width, .2 the precision, and f the floating point number.

When using the Scanner class to read data from the console, in order to read data which is a double and assign it directly to a double variable you can use the method: nextLine() hasNextDouble() getDouble() nextDouble()

The correct answer is 'nextDouble()' which will obtain the next value and convert it to double data type and return it as such.

When we declare a two-dimensional array 10 by 5 of data type 4 bytes long, how much memory will be allocated? 200 bytes 216 bytes 336 bytes 616 bytes

The correct answer is 336 bytes. We have an array header 12 bytes plus 10 elements times 4 bytes. (10 x 4 ) + 12 = 52. We need to pad it up to a multiple of 8, adding 4 bytes (52 + 4 = 56). That's the outer array. Now, the each of the other 5 elements is its own entity, so you can multiply 5 x 56 (our outer array was 56, and the inner ones will be as well). Therefore, 56 + (5 x 56) = 336.

For a given array of [32, 44, 12, 15], the number of iterations performed using selection sort algorithm are: 4 3 5 2

The number of iterations performed in case of selection sort is (n - 1) where n is the length of the array. Since this is 4 element array, the number of iterations will be 3.

Mike is working on a graphical user interface. How would he describe the most important aspect of the graphical user interface design to his colleagues? Usability is important so that the product can be used by specified users. Color selection is important to distinguish between different parts of the screen. Menu organization is important for navigation. Language is important to convey the right message. Consistency is important because it ensures that people understand the information.

Usability is the most important aspect of graphical user interface design, so that the product can be used by specified users.

Notice the points A, B, C, and D. These points or dots are called _____ in graph theory.

Vertices

long data type

can hold the largest integer values. It takes up 64 bits of memory and accepts a range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Overriding Example

class Animal { public void makeSound() { System.out.println("Grr..."); } } class Cat extends Animal { public void makeSound() { System.out.println("Meow"); } } class Program { public static void main(String[] args) { Cat c = new Cat(); c.makeSound(); } }

constant function

indicated by f(n) = c or O(1). The idea is that regardless of the number of inputs (n), the time taken to complete the work will always be a constant (c). The input can be a simple basic operation like addition or comparing two variables. The input can involve one step or multiple steps.

Overloading Example

int max(int a, int b) { if(a > b) { return a; } else { return b; } } The method shown above will only work for parameters of type integer.However, we might want to use it for doubles, as well. For that, you need to overload the max method: class Program { static double max(double a, double b) { if(a > b) { return a; } else { return b; } } static int max(int a, int b) { if(a > b) { return a; } else { return b; } } public static void main(String[] args) { System.out.println(max(8, 17)); System.out.println(max(3.14, 7.68)); } }

entry1 = enterV.nextFloat(); entry2 = enterV.nextFloat(); System.out.println(entry1 + entry2); Based on the following code, what data types could be entered without error? char, float, double float, double, byte integer, float boolean, float, double, char

integer, float Java will accept an integer in a float field (would just make it something like 25.0). But, if you try to enter other data types it will fail (although double may also work, depending on the length and precision). It's best to check for valid values or allow double from the start.

An experimental analysis depends on the _____ results, so an algorithm cannot be measured unless an _____ is implemented. output; equivalent program input; equivalent program output; opposite program input; opposite program

output; equivalent program As an experimental analysis depends on the output results, an algorithm cannot be measured unless an equivalent program is implemented.

Inputs

the ingredients for a computer's 'recipe'

procedure

the steps in a computer's 'recipe'

What is a quicker way to iterate through this? for (String s: trees) { System.out.println("Tree = " + s); }

tree.forEach(System.out::println);

_______ occur when the hash function assigns a hash key that was already assigned

Collisons

____ ____ then is about studying this graph and seeing what is the best possible route to take between any two points in this graph. Public transportation companies can use this graph to find the best possible route between points A and C, for example.

Graph Theory

What keyword do you use to use an interface

Implements

int data type

In Java, a variable using the int data type consumes 32 bits in memory. An int is a whole number (no decimals) and the valid number range is -2,147,483,648 to 2,147,483,647.

Overloading vs Overriding

In Java, we can overload a method by using the same name, but different parameters. Parameters are the variables that the method can accept. If we override a method, we do that in the child class using a parent class's method but different actions.

You create an ____ by using the keyword ______ after which comes a block of code with methods defined, but without bodies.

Interface

Which implementation method provides the best efficiency? A.Sorted list B.Unsorted List C.Array List D.Ordered List

A. Implementing a priority queue with a sorted list gives us greater efficiency. Since the elements are stored in priority order, removing the highest priority item is a quick process.

What is one major drawback of experimental analysis? A. Implementation of programs B. Too many outcomes C. Lacks practicality, as it is theoretical D. Calculation based

A. Implementation of algorithms may take a lot of time depending upon the complexity of the algorithms.

What is the structure used for storing data in a Hash Table? A. Key-value B. Indexing C. Index-bit D. Hash-value

A. The structure is known as Key-Value: HashTable (k,V)

To define a queue in Java, we use the ______ ________

Queue Interface

When multiplying a matrix, you start at the first ___ of the first matrix, and down the first ___ of the second, and then repeating for all for the rest of the values. Each pair (row/column) is multiplied and then added to the total for that row/column pair.

Row, column

algorithm analysis

a technique that's used to measure the performance of the algorithms. Speed is one of the key parameters in determining the potential of an algorithm. There are some other factors, like user-friendliness, security, maintainability, and usage space, that determine the quality of an algorithm. Space and time complexity are metrics used to measure parameters.

O(1)

bool findingNull(ArrayList<String> str) { return str[0] == null; } The code snippet above has time and space complexity of O(1). As you can see the return statement doesn't depend on the input size. Therefore, the time and space complexity of this algorithm will be O(1).

experimental analysis

experimental analysis in which various data points, like number of loops and sample input sizes, are plotted on a graph to understand the behavior of the algorithm. these data points are plotted on a graph to understand the behavior of the algorithm. We consider the worst-case running times.

short data type

is the smallest type of the three we cover in this lesson. It's only 2 bytes (16 bits). Like the other data types, it is signed, meaning it accepts both negative and positive values. Of the three data types covered in this lesson, it is the smallest. It accepts values from -32,768 to 32,767.

Polymorphism

which refers to the idea of "having many forms", occurs when there is a hierarchy of classes related to each other through inheritance.A call to a member method will cause a different implementation to be executed, depending on the type of the object invoking the method.Here is an example: Dog and Cat are classes that inherit from the Animal class. Each class has its own implementation of the makeSound() method. class Animal { public void makeSound() { System.out.println("Grr..."); } } class Cat extends Animal { public void makeSound() { System.out.println("Meow"); } } class Dog extends Animal { public void makeSound() { System.out.println("Woof"); } }

5 elements of Pogramming

Input: getting data and commands into the computer Output: getting your results out of the computer Looping and conditionals: testing to see if a condition is true of false, and cycling through a set of instructions until some condition is met Mathematical operations (arithmetic): Performing mathematical calculations on your data Variables and data structures: storing information, which may change over time

An _______ is an object that enables to cycle through a collection, obtain or remove elements.

Iterator

The ___ data type stores key-value pairs in an array. Each key is unique, and each key is associated with a value in the map. The ____data type is implemented by different Java classes: HashMap, HashTable, and TreeMap.

Map

Big Oh (O)

Measures the upper bound (worst case or maximum time). For an algorithm represented by f(n) where n is the input size, O(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. }, where g(n) is the upper bound calculated.

Surveys

Fred and I developed a customer survey to find out what his customers thought and wanted.

Observation

I spent time in the kitchen so I could see what she does - and doesn't - do.

Start/end symbol

a flowchart symbol which can be used to represent either the beginning or ending of a program... OVAL SHAPED

Decision symbol

- a flowchart symbol which signifies that the user must choose an option based on a specified criteria>>> DIAMOND

If you want to define the way a certain type of data behaves and is structured, but not how those behaviors and structures are implemented, you should use an _________ ________ _________

abstract data type

Which two methods add an element to the back of the queue? A.add, offer B. add, insert C. add, inject D. add, append

A. Both the add and offer methods add an element to the back of the queue. The add method will throw an exception if the queue is full, while the offer method will not.

The average case performance of selection sort is: A. O(n) B. O(n2) C. O(n log n) D. O(2n)

B. The performance of selection sort as per Big-O notation is O(n2).

In order for matrix multiplication to work, the number of _____ in the first matrix must match the number of _____ in the second matrix A. Rows, rows B. Rows, columns C. Columns, rows D. Columns, columns

C.

_____ algorithm is an algorithm that is used to solve the shortest distance problem. That is, we use it to find the shortest distance between two vertices on a graph. Depending on what the graph represents, we can find shortest routes, minimum costs, etc. all using this algorithm. The algorithm works by starting at the end vertex and visiting vertices by finding the shortest distance from that vertex to the ending vertex. Once we've gotten to the beginning vertex, we can identify the shortest path and its length.

Dijsktra's

This will work the same way as a regular hash table but will run a probe sequence when adding values to find an empty bucket to insert it into. There are multiple probing strategies, overall, and they will be more efficient than linked lists. But once the size of the populated hash table reaches around 80%, the time spent on probing will grow exponentially.

Open Addressing

If you are already familiar with queues, you'll remember that they use a first-in, first-out structure. _______ queues remove items based on their priority. The highest priority is removed first. Priority is based on natural order which means numerically, alphabetically, or based on a priority we define. Unlike regular queues, the first-in, first-out structure does not apply to priority queues.

Priority

Quick Sort

The Quick Sort is one of the best performing and efficient internal exchange sorts. Exchange sorts operate by repeatedly comparing and exchanging elements in the list. A Quick Sort is most easily implemented with a recursive routine. It is one of the most efficient sorting algorithms with an average Big O ratings of O(n log n). 1. If the list to be sorted is length 1, then finish 2. Pick an item within the list to act as a pivot. Usually left-most item. 3. Split list into two parts - one with items equal to or larger than the pivot and the other contains items smaller than the pivot 4. Repeat process on the two halves

double

The double data type stores decimal values with 15-16 digits of precision. Remember that the default value is 0.0d, so this means that if you don't append f or d to the end of the decimal, the value will be stored as a double in Java

Input/output symbol

a flowchart symbol which represents actions such as entering, displaying, or printing data>>> RHOMBUS

A _____ linked list is a linked list where nodes are connected both forward and backward. In other words, a given node can point both to the next node and the previous node. If the node has no previous node, it is the head; without a following node, it is the tail. When creating _____ linked lists, you need to create a Node class that has a constructor, to create the node. The class uses next and prev to maintain the previous and next connections. When inserting a head node, all nodes shift right, and a tail node shifts all down.

doubly

Logarithmic Function f(n) = log n or O log (n)

has the form f (n) = log n to the base b for some constant b. The value of b has to be greater than 1. This function is defined as x = log n to base b, if and only if bx = n. As an example, log 81 to the base 3 is 4 since 81/3/3/3/3 = 1 (81 divided by 3 four times). Similarly, the log of 12 to the base 2 is less than 4 since dividing 12 by 2 four times to gives a number less than one, 0.75. Some algorithms are complex and the logarithmic function helps to determine the time it takes to complete the code.

O(2N)

int FibonacciSeries(int num) { if (num <= 1) return num; return FibonacciSeries(num - 2) + FibonacciSeries(num - 1); } This function is a recursive function. So, the recursive equation is F(n) = F( n - 2) + F(n - 1) . The time complexity of this algorithm is O(2N). This means that it doubles with each data set.

Stack operation is based on what approach? A.FIFO B. LIFO C. LOFI D. FOLI

B. The operations in Stack data structure is based on last-in-first-out, and it is predicated on the fact that there is only one entry point which also serves as exit point and called top.

When creating a JLabel that has an icon instead of text, what do you need to create first? A. An empty JLabel with no text B. An instance of ImageIcon C. You can only have a text-based JLabel D. A new FlowLayout object

B. ImageIcon logo = new ImageIcon(Location of image); JLabel lbl = new JLabel(logo);

Merge Sort

A list is split into individual lists, these are then combined (2 lists at a time). Big-O notation classifies an algorithm based on how the execution time and space requirements grow with the growth in the input size. Merge sort has these performance characteristics: Best case: Ω(n log(n)) Average case: θ(n log(n)) Worst case: 0(n log(n))

Selection Sort

A sort algorithm that repeatedly scans for the smallest item in the list and swaps it with the element at the current index. The index is then incremented, and the process repeats until the last two elements are sorted. The average case performance for selection sort in terms of Big-O notation for time complexity is O(n2) as there are two nested loops. Since it takes fewer O(n) swap operations, it has greater performance over other sorting algorithms like merge sort, insertion sort, and heap sort.

Bubble Sort

A sort in which the first two items to be sorted are examined and exchanged if necessary to place them in the specified order; the second item is then compared with the third (exchanging them if required), the third is compared with the fourth, and the process is repeated until all pairs have been examined and all items are in the proper sequence. The performance is O(n2) which means the sort time increases as the length of the array increases by a power of two. This is not a calculation of how long it will take to search but rather the relationship of the search to the length of the array.

Which of the following Java statements is correct with a queue name of 'myQueue' and the data of type integer? A. myQueue.add(319); B. add(myQueue, 319); C. add(myQueue.319); D. myQueue.add('319');

A. The dot notation is used to call the add() method on the 'myQueue'' queue. The number 319 is passed as the integer to add to the queue.

Which type of queue can be used as a queue or a stack? A. Double-ended queue B. Regular queue C. Priority queue D. Ordered queue

A. Double-ended queues can be used as either a queue or a stack.

Map in Java is _____. A. an interface B. an abstract class C. an implementing class of HashTable D. an extension of Dictionary

A. The correct answer is 'an interface.' It is a newer structure that is meant to replace Dictionary with the same basic functionality, but it has many implementing classes and additional functionality such as computing a mapping based on a mapping function.

The char data type is most closely related to the _____ data type A. integer (Int) B. double C. float D. short

A. Because the char stores an integer value, it is most like the integer data type. The integer value (2 bytes) is the Unicode representation of the character.

Insertion Sort

An insertion sort algorithm in Java re-sorts an array by continually moving elements until they are in a numeric order. The more complex the array, the longer it will take to complete the insertion sort. Computer scientists use the Big-O Notation to indicate how much horsepower a given algorithm may take. For the insertion sort, the formula is O(N2), meaning that the time increases exponentially as the data set increases. A simple sorting algorithm that builds the final sorted array (or list) one item at time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

When using a linked list to represent a stack, which element(s) do you have access to within the stack? A. The bottom (head) B. The top (tail) C. All nodes in the stack D. All nodes before the top (tail)

B. A stack is last-in-first-out, meaning you only have access to the top of the stack and therefore have to remove items from the top if you wanted to get to any other nodes.

Which of the following correctly checks to see if the current node is the head of a doubly linked list? A. Node myNode = new Node(element); (if(myNode.next == null) { } B. Node myNode = new Node(element); (if(myNode.prev == null) { } C. Node myNode = new Node(element); (if(myNode == null) { } D. Node myNode = new Node(element); (if(myNode.next == tail) { }

B. If the previous pointer is null, it means that the current node is the head of the list.

Out of a random bunch of last years' holiday greeting cards, Clara wants to find the one her mother sent her. The optimal algorithm to use will be _____. A. f(n) = log n B. N-log-N C. Linear D. Exponential

B. The ideal algorithmic function for this would be N-log-N where Clara has n number of greeting cards, and so n choices for the initial selection. Based on that selection she can move forward or backward to continue the search.

When creating a stack data type in Java, which methods are most appropriate for the interface to the Stack? A. Push, poke, peek, size, isEmpty B. Push, pop, peek, size, isEmpty C. Push, peek, size, isEmpty D. isEmpty, pop, size

B. We must be able to add (push) and remove (pop) elements from the stack. We should also be able to view the top option (peek) without moving it, check the size, and determine if it is an empty stack.

Dictionary in Java is _____. A. an interface B. an abstract class C. an implementing class of HashTable D. an extension of Map

B. The correct answer is 'an abstract class.' It has a number of abstract methods to support mappings of key/value.

Dictionary's elements() method returns _____. A. set of values B. enumeration of values C. enumeration of key/value mapping D. set of keys

B. The correct answer is 'Enumeration of values.' There is also a method to return enumeration of keys keys from which a corresponding value can be obtained using the get method.

Which of the following is NOT true about a method in Java? A. Java methods can have no parameters B. Java methods can return more than one value C. Java methods can return no values D. Java methods can have more than one parameter

B. Methods in Java can return only one value. If an attempt is made to return more than one value, it will generate an error on compilation.

When passing an array to the function? A.The argument name and parameter name must match. B. The parameter variable stores the reference to the array. C. The method parameter is a global variable. D. The method parameter is a local variable so changes to the array are local.

B. The correct answer is 'The parameter variable stores the reference to the array'. When method is called, the array argument is evaluated to its reference and that is what is passed and stored in the method's parameter

How is the return value declared in a method? A.By the data type and the variable name following the method name B. By the data type alone before the method name C. By the data type and variable names in parentheses D. By the data type alone after the method name

B. The data type of the value returned by the method (if any) is declared before the name of the method

After completing the matrix multiplication, the resulting matrix will have the same number of _____ as the first matrix, and the same number of _____ as the second matrix. A. Rows, rows B. Rows, columns C. Columns, rows D. Columns, columns

B. The resulting matrix will have the same number of rows as the first matrix and the same number of columns as the second matrix. Given the method for multiplying matrices (walking across rows, then down the columns), this makes sense from a Java perspective as well.

Rule 1: Each node may contain a maximum of two child nodes: a left node and a right node. Rule 2: Either of the child nodes may be missing at any point in time. Rule 3: The child nodes on the left must have a search key value less than that of the root node. Rule 4: The child nodes on the right must have search key values greater than that of the root node.

BST Binary Search Tree

Which of the following Java code snippets correctly starts at the end of a Node called m? A. if(m.prev == null) B. while(m != null) C. if(m.next == null) D. while(m.end == null)

C. If you have reached the last node, there is no next node.

If you call an overloaded method that doesn't exist, what will happen? A. Java will use a default method B. Java will display a warning C. The program will not compile D.Nothing

C. Overloading is fine, but you have to have the methods in the first place! Trying to call a method that does not exist cannot work.

Which of these is not a method for drawing shapes? A. fillOval B. drawRect C. fillLine D. fillArc

C. A line can have the stroke size set, and so you don't need to fill it.

Which of the following GUI classes allows you to add all of the elements discussed in this lesson? A. JCheckBox B. JButtonGroup C. JFrame D. ButtonGroup

C. The JFrame is the foundation of GUI output. Without it, you have nothing to add the check boxes, drop-down lists or button groups!

Which of the following code snippets illustrates a method of multiple inheritance in Java? A. public class Z extends A, B { } B. private void Z implements A, B { } C. public class Z implements A, B { } D. private class Z extends A, B, implements C { }

C. We cannot just extend (or inherit) from more than one class. Instead, by using interfaces we can have multiple implementations.

A _______ linked list is a list that is connected tail-to-head. It is useful for round-robin scheduling, where a process is given a certain amount of time at the tail of the list before being rotated out.

Circularly

Cubic and Polynomials or O(nn)

Cubic functions are of the form f(n) = n3. When there are 3 nested loops, the number of iterations performed is O3. When there are n nested loops, the number of iterations is On. A polynomial algorithm represents an operation that increases in size as the size of the iterations n increases.

The performance of a binary search in terms of Big O Notation is _____, where n is the number of elements in the array. A. O(1) B. n(log n) C. log n D. O(log n)

D. The performance of a binary search in terms of Big O Notation is O(log n).

Which of the following Java code blocks correctly performs an insertion sort on an array named arr? A.for(int i = 1; i < arr.length; i++) { int temp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = temp; } B. for(int j = i; (j > 0 && arr[j-1] > arr[j]); j--) { for(int i = 1; i < arr.length; i++) { int temp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = temp; } C. for(int j = i; (j > 0 && arr[j-1] > arr[j]); j--) { for(int i = 1; i < arr.length; i++) { int temp = arr[j]; arr[j-1] = temp; } D. for(int i = 1; i < arr.length; i++) { for(int j = i; (j > 0 && arr[j-1] > arr[j]); j--) { int temp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = temp; } }

D. Two loops should be made: one that starts looping through the array, the other loops again, but goes backward (decrements) down. Each nested loop ensures the next element is greater than the current.

______ queues can be used as either a queue or a stack

Double-ended

When is the Requirements Document finished?'' A. Not until after the requirements review B. Not until the surveys are analyzed and results incorporated C. Not until the customer gives it back to me after review D. Not until suggestions and requests have been incorporated into the document E. Not until the customer agrees that it accurately describes everything he wants the program to do.

E.

These are the lines connecting our vertices.

Edges

Document Review

I got a copy of the menu, which documents what pancakes need to be made and how they are served.

Application Programming Interface.

In Java-speak, the APIs are a collection of packages that programmers can import into their programs. In this lesson we'll discuss the core Java APIs, since they come packaged with an installation of the developer toolkit. However, there are three major types of Java APIs that are available: Core API: This comes when you download the developer kit (JDK), or a developer tool like NetBeans Optional Java-delivered APIs: You may have to download these Unofficial APIs: Available from external websites/sources (or write your own!)

Theta (θ)

Measures both upper and lower bound. or an algorithm represented by f(n) where n is the input size, θ(f(n)) = { g(n) if and only if g(n) = O(f(n)) and g(n) = θ(f(n)) for all n > n0. }, where g(n) is the upper bound calculated.

Omega (Ω)

Measures lower bound (best-case or minimum time). For an algorithm represented by f(n) where n is the input size, Ω(f(n)) = { g(n) : there exists c > 0 and n0 such that g(n) ≥ c.f(n) for all n > n0. }, where g(n) is the upper bound calculated.

Meetings

Meetings: I had meetings with Fred, the owner, to talk with him about what he wanted.

_____ are an abstract data type that allow for efficient manipulation of lists. These ______ use a first-in first-out schema with no exceptions.

Queues

Think of a _____ in Java as a stack of plates in a cafeteria. When you need a new plate, you pop one off the top. As new plates are cleaned, they are pushed back onto the top of the stack. A _____ is an implementation of LIFO or last-in-first-out.

Stack

N-log-N function or O(n log n)

The N-log-N function is of the form f(n) = n log n. This is a logarithmic running time function. This function can be used in two different scenarios: (1) from a random number of n choices, only one choice needs to be selected for the next task, and (2) there are any number of n choices to select from. The complexity increases as the number of choices, n, increases. This is the time complexity that describes the amount of time to run an algorithm and also represented by the big O notation, O (n log n).

Binary Search

The algorithm of a binary search is as follows: Identify the middle element of the sorted array. Compare the target element with the middle element. If the target matches with the middle element, the middle index is returned. If the middle element is greater than the target, search the lower sub-array. If the middle element is less than the target, search the upper sub-array. Identify the middle element of the sub-array. Repeat the steps 3 through 6 until the target is found. The average performance of a binary search is O(log n), where O is the Big O Notation and n is the number of elements in the array.

Exponential Function

The exponential function is of the form f(n) = bn. n is the exponent or the number of times b is multiplied by itself, where n is the size of the input. As the size of the input grows, the execution time of the algorithm also grows exponentially.

Quadratic Function or O(n2)

The quadratic function is of the form f(n) = n2. This function is used many times in nested loops where there are 2 loops - one inner and one outer. The inner loop performs n operations, and the outer loop performs n operations, and the algorithm now completes n * n or n2 operations. In the simplest of terms, the running time of an algorithm increases by the square of the number of inputs. This function finds uses in bubble sort, insertion sort and selection sort.

Requirements document:

Using these four tools, I was able to create a draft of a requirements document which, when finished, will be Fred's wish list, telling me what he wants Foober to do. I've given it to Fred for review, so the next step is to start making sure that I have everything Fred wants and that I understand each part. This is what we will talk about in the next lesson: requirements review. See you then!

dot product

We multiply each of the terms in the first row (3, 5, 7) by the corresponding terms in the first column (1, 7, 13) of the second matrix and then add those numbers together. It looks like this: ( 3 * 1 ) + (5 * 7) + (7 * 13) = 129

Constructor

______ are special methods invoked when an object is created and are used to initialize them.A constructor can be used to provide initial values for object attributes.- A constructor name must be same as its class name.- A constructor must have no explicit return type.Example of a constructor: public class Vehicle { private String color; Vehicle() { color = "Red"; } }

Inheritance

_______ is the process that enables one class to acquire the properties (methods and variables) of another. With inheritance, the information is placed in a more manageable, hierarchical order.The class inheriting the properties of another is the subclass (also called derived class, or child class); the class whose properties are inherited is the superclass (base class, or parent class).To inherit from a class, use the extends keyword.This example shows how to have the class Dog to inherit from the class Animal. class Dog extends Animal { // some code } Here, Dog is the subclass, and Animal is the superclass.

Connector symbol

a flowchart symbol which contains a number and represents exit and re-entry points when the space or process does not allow a continuous flowchart to be presented>>> CIRCLE

Process symbol

a flowchart symbol which shows how the program is functioning... Rectangular

Display symbol

a flowchart symbol which signifies that information is displayed to the user ... weird oval on the bottom triangle on top thingy

algorithm

a recipe that describes the exact steps needed for the computer to solve a problem or reach a goal

O(N2)

bool hasDuplicate(ArrayList<string> str) { for (int out = 0; out < str.length; out++) { for (var in = 0; in < str.length; in++) { if (out == in) continue; if (str[out] == str[in]) return true; } } return false; } This block of code has two loops, one being an inner loop. Clearly, the function generated is quadratic. Hence, the time complexity will be O(N2). The space used is also N∗N so the space complexity is O(N2). When out is 0, the number of statements inside the loop will be executed 0 times, when out is 1 it will be executed 1 time, when it is 2 it will be executed 2 times, and so on. So, it is 0 + 1 + 2 + 3 + ... + N - 1 = N(N - 1)/2, which is a quadratic expression.

O(N)

bool hasValue(ArrayList<string> str, string value) { foreach (var element in str) { if (element == value) return true; } return false; } This has one foreach loop that deals with an ArrayList of size N. The function generated is a linear function. Hence the time complexity will be O(N). It also requires N units of space, so the space complexity is also O(N).

JLABEL

class in Java Swing applications is a simple yet powerful tool, because it lets you present un-editable content to the user. Whether for general instructions, or in front of text fields/buttons, it is important to present information to the user. Although the content of a label can be changed via the setText method, it is not editable by the end user.

Unlike an array, which is a single object of defined size, a ___ ______ is a structure of independently linked elements called nodes. Each node contains data, and a reference to another node; in a ___ ____ _____, each node points to the next node. The start of the list is the head and the end is the tail. Using a ____ ______ allows you to add, change, and remove elements within the list far easier than with an array.

linked list, singly linked list, linked list


Kaugnay na mga set ng pag-aaral

Chapter 36: Urinary Elimination Supplement

View Set

Exam 3 questions (multiple choice and t/f)

View Set

Creole Revolutions in Latin America

View Set

Chapter 16: Nursing Care of the Child With an Alteration in Intracranial Regulation/Neurologic Disorder

View Set

Module 13 Practice Questions: Genes and Proteins

View Set