




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
CSIS 1410 Final study.docx...CSIS 1410 Final study.docx.
Typology: Exams
1 / 28
This page cannot be seen from the preview
Don't miss anything!





















Strings are_____ - correct answer immutable immutable definition - correct answer The character contents can no longer be changed. == - correct answer compares instance(address of the object) equals - correct answer compares content of String Objects equalsignoreCase - correct answer compares content disregarding upper/lower case <0 - correct answer calling string smaller than parameter 0 - correct answer calling string equal to parameter >0 - correct answer calling string greater than parameter CompareTo - correct answer compares this object with the specified object for order StringBuilder - correct answer Used for creating and manipulating dynamic string information. ( when strings need to be changed ) capacity - correct answer specifies how many characters can be stored
If a StringBuilders capacity is exceeded: - correct answer the capacity expands to accommodate additional characters String vs StringBuilder - correct answer String should be used if the data does not change, if a program uses frequent concatenations or other String modifications StringBuilder is often more efficient. StringBuilder vs StringBuffer - correct answer StringBuilder is NOT thread safe, StringBuffer is thread safe. StringBuilder append(boolean b) - correct answer Appends the string representation of the boolean argument to the sequence. StringBuilder append(char c) - correct answer Appends the string representation of the char argument to this sequence. StringBuilder append(char[] str) - correct answer Appends the string representation of the char array argument to this sequence. StringBuilder append(char[] str, int offset, int len) - correct answer Appends the string representation of a sub-array of the char array argument to this sequence. StringBuilder append(CharSequence s) - correct answer Appends the specified character sequence to this appendable. StringBuilder
05 neither 07 unboxing each wrapper class has the exact same scope as the primitive type - correct answer A statement about wrapper classes that is not correct. to improve performance - correct answer Not a good reason to use a wrapper class instead of a primitive type. Code segment: int numberA = 3; Integer numberB = numberA; True or False: In the code segment above shows an example of unboxing - correct answer False Each of the enum constants has a corresponding numeric value - correct answer True Assume you have an enum Navigation. It is declared like this: public enum Navigation {LEFT, RIGHT, STRAIGHT} What is a valid java statement: - correct answer Navigation navRight = Navigation.RIGHT; An enum ( or enumeration) is - correct answer a class Rather than declaring an enum public enum Navigation {LEFT, RIGHT, STRAIGHT } I could also have an int variable navigation and assign it different values- lets say 0 for left, 1 for right, and 2 for straight.
In both cases I could keep track of my navigation, however, there are 2 major advantages of using an enum. Check the TWO main reasons why we should use an enum. - correct answer It allows the compiler to catch errors. It makes the code clear and easy to read. Which of the following demonstrates a constructor call of an enum. - correct answer BLACK(0,0,0) Assume you have an enum called TrafficLight and it is defined like this: public enum TrafficLight. { RED(3.5), GREEN(7.5), YELLOW(1.2); double duration; TrafficLight(double d) { duration =d; } public double duration() { return duration; } } Now you want to find out the duration of green. What would that be? - correct answer greenLight.duration() // greenLight is a variable of type TrafficLight representing the green light. Enums are reference types but you cannot override the toString method. - correct answer False Enums can contain constructors, fields, and methods- constructors can't be public. - correct answer True
Complete the sentence below based on the following stack trace: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100 at Erathrostenes.initialize(Erathostenes.java:33) at Erathrostenes.initialize(Erathostenes.java:12) at Erathrostenes.initialize(ErathostenesApp.jave:6) The exception was first thrown in method____ line___ - correct answer initialize, 33 It can happen that multiple catch blocks of a try statement are executed to handle a given exception. - correct answer False Complete this description of the termination model: If an exception occurs in a try block the remaining statements of the try block____executed. The execution continues in the _____block ( if there is one) If the exception was handled in the ____ block the execution resumes after the try statement. - correct answer are no longer, first matching catch, catch Complete the sentence below: A ____ is a collection of data or information that has a name and it is stored on a secondary storage. A____represents a sequence of bytes, which can be accessed in sequential order. - correct answer file, stream Which of the following is an analogy that can help understand streams? - correct answer conveyor belt What is the standard error stream in java? - correct answer System.err
Complete the following sentence with a single word: Class File represents a_______. - correct answer path Assume you have a variable demo that is declared like this: File demo = new File("C:\Demo"); You want to find out whether demo is a directory? Which of the following expressions should you use? - correct answer demo.isDirectory() Let's assume you need to print all the file names of a given directory, where the file is greater than 100K. Which method should you use to access the content of the given directory? - correct answer listFiles You can create an instance (object) of Formatter based on a File name. If the file does not exist______ If the file exists_______ - correct answer It will be created, it gets overwritten The formatting that is used in class Formatter is very analogous to the formatting that is used in String.format and in printf. - correct answer True Complete the sentence: The type parameter section is surrounded by____ - correct answer <> Which of the following is a valid method header? - correct answer public void swap (T[] array, int index1, int index2) a generic type is a class or an interface that has been declared with one or multiple type parameters. - correct answer True
a) List letters = Arrays.asList('a', 'r', 'o', 'u', 'n', 'd'); Collections.sort(letters, Collections.reverseOrder()); System.out.println(letters); b) List letters = Arrays.asList('a', 'r', 'o', 'u', 'n', 'd'); Collections.reverse(letters); System.out.println(letters); Does code segment a) produce the same results as code segment b)? - correct answer False The class Collections consists exclusively of static methods that operate on or return collections. One of these methods is sort. Which of the following statements is NOT correct - correct answer sort returns a sorted collection. Which of the following statements is true - correct answer List is an interface True or False? Declaring a variable of an interface type is a good practice because it keeps your code adaptable. - correct answer True Here is a collection called numbers: List numbers = Arrays.asList(1, 2, 3, 4, 5); You want to replace all elements of the list with the integer literal 7 Which of the following code statements provides this functionality? - correct answer Collections.fill(numbers, 7);
Here are two code segments: a) and b) Both are based on a list of characters that is modified and printed a) List letters = Arrays.asList('a', 'r', 'o', 'u', 'n', 'd'); Collections.sort(letters, Collections.reverseOrder()); System.out.println(letters); b) List letters = Arrays.asList('a', 'r', 'o', 'u', 'n', 'd'); Collections.reverse(letters); System.out.println(letters); Does code segment a) produce the same results as code segment b)? - correct answer False The class Collections consists exclusively of static methods that operate on or return collections. One of these methods is sort. Which of the following statements is NOT correct - correct answer sort returns a sorted collection Which of the following statements is true - correct answer List is an interface True or False? Declaring a variable of an interface type is a good practice because it keeps your code adaptable. - correct answer True _______components are heavyweight components that display differently on different platforms. - correct answer AWT
Complete the sentence: Labels can display _______________. - correct answer text and / or an image JComponents must be placed insdie a top-level container e.g. JFrame, JDialog, or JApplet. - correct answer True You need to write some code that responds to a text change in a JTextField. How can you do that? - correct answer Create a class that implements the interface ActionListener and override the method actionPerformed An inner-class object can directly access all the variables and methods of the outer class. - correct answer False Which of the following best describes how to respond to an event? - correct answer Create an event handler class Implement the appropriate event-listener interface Register the event handler object True or false - Event are special things that are happening e.g. a user clicking a button or a user moving a mouse - correct answer True Which LayoutManager is it? It lays out components row by row. If the window gets re-sized and there is no longer enough space in a row components get moved to the next row and the next.
.. - correct answer FlowLayout Complete the sentence: The _____________________ is similar to a table with rows and columns. It displays components in the requested 'cells'. - correct answer GridLayout
Layout managers provide the following functionality: - correct answer They calculate the sizes for a container and they lay out the container's childeren Assume you just drew a blue rectangle and now you want to draw a green oval. What do you need to do? - correct answer set the color of the Graphics object, then call the method fillOval The method_____can be called to draw a solid red circle. - correct answer fillOval The method_____can be used to draw the outline of a circle (an empty circle) - correct answer drawOval In order to include text in the drawing you can call the following method on the Graphics object: - correct answer drawString Which of the following methods can be used to draw a solid yellow rectangle? - correct answer fillRect In order to do some GUI drawing we need an object that knows how to set the color, how to draw a rectangle, etc. What class provides this functionality? - correct answer Graphics In the video all the code that did the actual drawing was placed in the following method: - correct answer paintComponent Complete the sentence:
Complete the sentence: When you redefine the implementation of an inherited method from the superclass you are - correct answer overriding Which of the following statements describes best the access modifier protected? - correct answer Protected members are accessible within its own class, its subclasses and other classes in the same package Interfaces are a part of the class hierarchy - correct answer False Interfaces_____a class interacts with other classes. - correct answer define the way Objects of a type that implements an interface have relationship with the implemented interface. - correct answer an is-a What is NOT a reason to use interfaces? - correct answer To allow unrelated classes to share common implementation What can NOT be included in an interface declaration? - correct answer implementation Which of the following is a doc comment? - correct answer /** comment */ Javadocs can provide useful information to programmers when they are about to access class members. - correct answer True
Java docs have to be placed immediately before the code they are documenting - correct answer True Javadoc uses tags to label what they are describing (e.g. the return type, the author, etc. ) Which of the following is a tag that indicates that a description / documentation pertains to a parameter? - correct answer @param What is NOT a good reason to use Javadoc? - correct answer It reduces the memory use during runtime With____Eclipse can create an HTML documentation of our own Java projects that has the same look and feel as the documentation of the Java API. - correct answer little effort Which of the following options describes the 2 main advantages of unit testing? - correct answer It makes it easy to run many tests repeatedly and no human judgement is required for the evaluation. Which of the following describes a key feature when creating unit tests? - correct answer Add tests incrementally jUnit provides an application to automatically run the tests - correct answer True Which of the following is NOT a key feature when running jUnit tests? - correct answer jUnit ensures that all the tests are run every time jUnit displays a bar in red and green colors. Depending on the amount of unit tests that passed / failed the bar is more red or more green. If the amount of tests passed equals the amount of tests failed then
two methods are these? - correct answer equals and hashCode What is a template for the implementation of the equals method? - correct answer public boolean equals (Object obj) { if (! (obj instanceof MyType)) return false; MyType other = (MyType) obj;
... } All 5 methods, that can be overriden, have an explicit general contract. Why is it so important to follow that contract? - correct answer Other classes rely on the proper implementation of these methods. 5 of the 11 method in class Object can be overriden. Which are they? - correct answer clone, equals, finalize, hashCode, toString Assume you have two Circle objects c1 and c2. You know that c1.equals(c2) returns false. Is the following statement true or false? Given that c1.equals(c2) returns false we can be certain that c1.hashCode() is different from c2.hashCode(). - correct answer False What are the three pillars of object oriented programming? - correct answer Encapsulation, Inheritance, Polymorphism One of the statements does not compile because it misses a cast. Which one is it? - correct answer Lion myLion = new Mammal(); Complete the sentence: All calls to overridden methods are resolved at ____time. - correct answer run, execution, run time, or runtime
The_______operator allows to check whether an object ( instance ) is of a given type.