What object oriented programming characteristic allows you to create a class that is a specialized version of another class?

What is the difference between an iterative algorithm and a recursive algorithm?

An iterative algorithm will use looping statements to repeat the same steps until a certain condition is met, while a recursive algorithm will make a call to itself until the base condition is satisfied. Iterative algorithms are usually more efficient, but recursive algorithms may be easier to implement in some cases.

When multiple exceptions are caught in the same try statement and some of them are related through inheritance, does the order in which they are listed matter?

Yes, the more specialized exception classes should be handled before the more generalized exception classes.

Where does execution resume after an exception has been thrown and successfully caught?

The program resumes at the statement that immediately follows the try-catch statement.

What is the purpose of the finally clause?

The finally clause defines one or more statements that are always executed after the try block and any pertinent catch blocks have executed.

What happens when an exception is thrown but the try statement does not have a catch clause that is capable of catching it?

It is passed up the call chain until it is handled by a method in the program or by the default exception handler, which prints an error message and crashes the program.

What types of objects can be thrown?

Only objects that inherit from the class Throwable may be thrown.

When are you required to have a throws clause in a method header?

A method header is required to have a throws clause if it might throw a checked exception and does not handle the exception.

Explain why a misplaced semicolon can cause an if-statement to operate incorrectly.

Depending on the exact location of the semicolon, a prematurely terminated if-statement will compile and execute a null statement - which does nothing (but most likely causes a logical error).

What do you call a constructor that accepts no arguments?

Under what circumstances does Java automatically provide a default constructor for a class?

Java provides a default constructor ONLY when one is not explicitly written for the class.

What is the difference between an argument and a parameter variable?

An argument is a variable or literal that is listed inside the parentheses of a call to a method. Parameter variables are variables that are local to particular methods. They are initialized by the arguments with which the method is invoked.

What is the difference between a field and an attribute?

"Attribute" is a generic OOP term that refers to an item of data held by an object. "Field" is a Java-specific term that refers to a member of a class that holds data.

Which approach is less efficient: a loop or a recursive method? Why?

Recursive algorithms are usually less efficient because each method call requires several actions to be performed by the JVM - including allocating memory for parameters, and other local variables, and storing the address of the program location where control returns after the method terminates - which are not necessary with an iterative solution.

What type of recursive method do you think would be more difficult to debug: one that uses direct recursion or one that uses indirect recursion? Why?

An algorithm that uses indirect recursion would be more difficult to debug because the recursion may not be obvious from the code.

What is a recursive algorithm's base case? What is the recursive case?

The base case is the smallest version of the problem that can be solved with one step. In the recursive case, the problem must be incrementally reduced and passed to the algorithm again and again until the base case is reached.

What is the difference between the throw statement and the throws clause?

The throw statement causes an exception to be thrown, whereas the throws clause merely informs the compiler that a method throws one or more exceptions.

What is the difference between a checked exception and an unchecked exception?

Unchecked exceptions inherit from the Error or RuntimeException classes. They should not be handled because the conditions that cause them can rarely be dealt with in the program. All other exceptions are checked exceptions. If a method has the potential to throw a checked exception, it must handle the exception or have a throws clause in the header.

What does it mean to catch an exception?

An exception is caught when it is detected and remediated using a try-catch statement.

What is meant when it is said that an exception is thrown?

An exception is an object that is generated in memory (thrown) as the result of an error or unexpected event. When the code in a method throws an exception, the normal execution of that method stops and the JVM searches for a compatible exception handler inside the method. If it can't be handled locally, it is passed up the call chain until it is handled in the program or by the default exception handler.

When does dynamic binding take place?

Dynamic binding happens at runtime.

A program uses two classes: Animal and Dog. Which class is the superclass and which is the subclass?

Animal is the superclass and dog is the subclass.

What is an abstract method?

An abstract method has a header and no body. It must be overridden in a subclass of the class to which it belongs.

Each of the numeric wrapper classes has a "parse" method. What do these methods do?

They convert strings of digits into numeric values.

Each of the numeric classes has a static "toString" method. What do these methods do?

They convert numeric values to Strings.

What are the differences between an abstract class and an interface?

An interface is similar to an abstract class that has exclusively abstract methods. In its header, it uses the keyword interface instead of class. Classes extend abstract classes but they implement interfaces.

What is the difference between overriding a superclass method and overloading a superclass method?

A superclass method is overriden when the subclass contains a method with an identical signature. When the method is called partially qualified it will default to the functionality of the subclass method. Overloading a superclass method is just creating a method with the same name that has different parameter variables.

Reference variables can be polymorphic. What does this mean?

A variable can reference objects of types different from its own, as long as those types inherit from its type.

Describe the difference in the way primitive variables and class variables are passed as arguments to a method.

When variables are declared as instances of a class, they hold a memory address where an object is stored. Thus, they are called reference variables. When a reference variable is passed as an argument to a method, the method has access to the object that the variable references. By contrast, primitive variables hold literal values that are copied into the method parameters.

What is the difference between a protected class member and a private class member?

A protected class member can be accessed from within the entire package that a class belongs to. A private class member can only be accessed from within that class. Both may be accessed by subclasses using the "super" keyword.

What is an abstract class?

An abstract class has one or more abstract methods. Abstract classes cannot be instantiated, but serve as superclasses. They represent the generic form of any classes that inherit from them.

A program reads a String as input from the user for the purpose of tokenizing it. Why is it a good idea to trim the String before tokenizing it?

If you are not using white space as a delimiter, leading white space characters will become part of the first token and trailing white space characters will become part of the last token.

Why should you use StringBuilder objects instead of String objects in a program that makes lots of changes to Strings?

String objects are immutable whereas StringBuilder objects are not.

Which constructor is called first: that of the subclass, or that of the superclass?

The superclass constructor is always called first.

Can a subclass ever directly access the private members of its superclass?

Yes, using the superclass' public methods.

Why doesn't the assignment operator work for assigning the values in one array to another array?

When one array is assigned to another array, it becomes an alias of the first array. Both variables will hold the memory address where the first array begins. As a result, the array object created when the second array was declared will be garbage collected by the JVM because it is unreferenced. Instead, each individual value in an array must be copied into the corresponding subscript of the second array.

How do you define an array without providing a size declarator?

By initializing the array variable with a set of comma separated values inside a pair of curly braces.

What is the "this" keyword?

It is the name of a reference variable that an object can use to refer to itself.

Explain the selection sort algorithm.

In selection sort, the smallest value in the array is located and switched with the value in element 0. The next smallest element is found and switched with the value in element 1. This process continues until all elements are in increasing order.

What happens if you attempt to call a method using a reference variable that is set to "null"?

The program will terminate.

A "has a" relationship can exist between classes. What does this mean?

A "has a" relationship exists when an instance of one class is a member of another class.

Explain the binary search algorithm.

Binary search requires the collection to be sorted. It starts by comparing the center element with the search value. If SV=E, it returns the subscript of E. if SVE, it discards the lower half of the collection. It then repeats this process on the remaining subset of the array.

What is an enumerated data type and how is it used?

An enumerated data type consists of a set of predefined values. You can use one to create variables that may hold only the values that belong to the enumerated data type.

Explain the sequential search algorithm.

It uses a loop to sequentially step through an array, starting with the first element. If compares each element with the value being searched for and stops when the value is found or the end of the collection is reached.

Explain the advanced for-loop.

The advanced for-loop works ONLY on arrays. It always iterates sequentially through each element. On each iteration, it copies the current element into a local variable and executes its code block. It is handy, but limited.

Explain the finalize keyword.

If a class has a method named finalize, it is called automatically just before an unreferenced object is garbage collected. It accepts no arguments and has a void return type.

How do you write a method with a variable length argument list?

Append an ellipsis to the data type in the parameter list.

Aggregation occurs when an instance of a class is a field in another class.

What effect does the continue statement have on a loop?

The continue statement causes the current iteration of a loop to immediately end. When it is encountered, all statements in the body of the loop that appear after it are ignored and the loop begins the next iteration.

What effect does the break statement have on a loop?

When the break statement is encountered, the loop stops and the program jumps to the statement immediately following the loop.

Briefly describe the switch decision structure.

The switch statement is a multiple alternative decision structure in which a value is compared to each of a series of values stored in the structure which are preceded by the case keyword and followed by a colon. If the argument matches a case, then that code block executes. If no case matches, a default code block executes. All code blocks must end in a break statement, which causes the program to exit the decision structure.

Which loop is best for validating user entered data?

A variable's scope is the part of the program that has access to the variable.

How are primitive data types different from reference data types?

With PDTs, you can only create literals. With RDTs, you create pointers to objects.

A procedure is a set of programming statements that, together, perform a specific task.

An object is a software entity that encapsulates data and procedures.

Name and describe the process that the CPU is constantly engaged in.

Fetch/decode/execute cycle. Fetch: the control unit fetches the next instruction in the program from main memory. Decode: the control unit converts the binary instruction to an electrical signal. Execute: the signal is routed to the appropriate component of the computer to perform an operation.

What are the two parts of the CPU?

The control unit, which coordinates all of the computer's operations, and the Arithmetic and Logic Unit (ALU), which performs mathematical operations.

What is a cast operator and how are they used?

Cast operators let you convert a value from one PDT to another, even if that entails a narrowing conversion. Cast operators are unary operators that appear as a PDT name enclosed in a set of parentheses. The operator precedes the value being converted.

What is the effect of the final keyword on variables?

When a variable is declared final it becomes a named constant. By convention, the names should be all uppercase. Named constants must be assigned a value at declaration.

Explain the conditional operator.

The conditional operator is a short expression that acts like an if-else statement. It is comprised of a Boolean expression, a question mark, a value that is returned if the expression is true, a colon, and a value that is returned if the expression is false.

A literal is a value that is written into the code of a program.

A named storage location in memory.

When an OS multitasks, it runs multiple programs at once by using time-sharing to divide the allocation of hardware resources among all executing programs.

Why should an object hide its data?

Data hiding prevents accidental corruption and simplifies interactions between objects by limiting inter-object access to public methods and static fields.

Why must programs written in a high-level language be translated into machine language before they can be run?

A computer's CPU can only process instructions written in its particular machine language, which consists of binary strings that represent series of electrical impulses.

Why does byte code make Java a portable language?

Java byte code can be run on any computer that has a JVM without any modification.

What is the difference between operating system software and application software?

Operating system software manages the computer's hardware devices and creates a set of abstractions for software engineers to more easily create application software that is useful to the user.

What is the difference between machine language and byte code?

Byte code is machine language for the JVM. The JVM for a particular machine translates byte code into machine language for the host machine.

A set of well-defined steps for performing a task.

A collection of programming statements that specify the attributes and methods for a particular type of object.

What is the difference between a syntax error and a logical error?

Syntax errors are violations of the rules of a programming language. Logical errors are mistakes that will cause a compiled program to produce erroneous results.

What type of memory is volatile?

Random Access Memory (RAM), because its contents are erased when the computer is turned off.

What must a computer have in order to execute Java programs?

A Java Virtual Machine (JVM).

What is the difference between main memory and secondary storage?

Main memory is temporary and holds the instructions and data that are currently in use. Secondary storage holds data indefinitely. Data and instructions are loaded into main memory from secondary storage to be used.

A program that translates source code into executable machine code.

What happens when you compare two String objects with the equality operator?

The equality operator compares the memory addresses of the two Strings because String is an RDT. The String class' equals or compareTo methods should be used instead.

Explain the purpose of a flag variable. What data type is best for a flag?

A flag is a Boolean variable that signals whether some condition exists in a program.

What is something you cannot do with a static method?

Static methods do not operate on the attributes of any instance of the class where they are defined.

What does the Scanner class' hasNext method return when the end of a file has been reached?

What does it mean to append data to a file?

Appending to a file means writing new data at the end of the data that is already written.

What is a file's read position? Where is the read position when the file is first opened for reading?

A file's read position marks the location of the next item that will be read from the file. When the file is first opened, the read position is at the first item in the file.

When writing data to a file, what is the difference between the print and println methods?

The only difference is that println prints a new line character after printing its arguments.

Describe the difference between the while and do-while loops.

The while loop is a pre-test loop and the do-while loop is a post-test loop

Why should a program close a file when it is done using it?

Closing the file causes any unsaved data in the file buffer to be written to the file.

How does method overloading improve the usefulness of a class?

It creates the illusion of loosely typed parameter variables.

Under what circumstances does an object become a candidate for garbage collection?

When the object is no longer referenced.

What is the difference between an array size-declarator and a subscript?

A size-declarator is include in square brackets when an array variable is declared and specifies the number of elements the array may hold. An array's subscript is the value included in square brackets, when the array variable is referenced, to denote which element of the array is desired.

What is the difference between variable assignment and initialization?

Initialization is assignment at the time of declaration.

What does a variable declaration tell the Java compiler about a variable?

The variable's name and the type of data it will hold or reference.

Why are variable names like "x" not recommended?

Because they are not likely to help a human understand what a variable represents or how it might be used.

An expression adds a byte and a short, what data type is the result?

The result is a short because the JVM performs widening conversions unless it is specifically otherwise.

Is it a good idea to make fields private?

It is usually helpful to make fields private to protect their data from accidental corruption. But, there are notable exceptions.

What are accessor and mutator methods?

Accessor methods get the values of fields but do not change them. Mutator methods modify fields.

If a class has a private field, what has access to the field?

Only code within the same class may access the field.

Explain what is meant by the phrase "pass by value".

A copy of an argument's value is passed into a parameter variable. A method's parameter variables are distinct from the arguments listed inside the parenthesis of a method call. If a parameter variable is changed inside a method, it has no effect on the original argument. PDTs are passed by value. RDTs are passed by reference.

What is the purpose of the new keyword?

It is used to create an object in memory.

Why is it easier to write a program in a high-level language than in machine language?

High-level languages are designed to be "human readable".

What part of an object forms an interface through which outside code may access an object's data?

What is the difference between a sequential access file and a random access file?

When a SAF is opened, its read position is at the beginning of the file and it progresses sequentially through the file contents. In order to read a specific byte, all bytes preceding it must be read first. With RAFs, a program can immediately jump to any location in the file.

What is a ResultSet when working with databases in Java?

A ResultSet object contains the results of a SQL statement.

What is metadata? What is ResultSet metadata? When is it useful?

Metadata describes other data. ResultSet metadata can be used to determine which columns where returned when a query that is not known in advance is executed.

What does the Java compiler translate Java source code into?

What does "self-documenting" mean?

A program is considered self-documenting when you can gain understanding of what it does just by reading its code.

What type of program do you use to write Java source code?

An Integrated Development Environment (IDE).

How is a class different from an object?

An object is an instance of a class. A class is to an object as a blueprint is to a house.

What object-oriented programming characteristic allows you to create a class that is a specialized version of another class?

Briefly explain how the print and println methods are related to the System class and out object.

System is a class in the Java API. Out is an object that is a member of the system class; it is an instance of an inner class of system, but not of system itself. The print and println methods are members of the out object.

A source file is a container for source code - the instructions written in a high-level language by a programmer.

How is problem usually reduced with a recursive method?

A problem is usually reduced by making the value of one or more parameters smaller with each recursive call.

What happens when you serialize an object? What happens when you deserialize an object?

When an object is serialized, it is converted into a series of bytes that contain the object's data. The resulting set of bytes can be saved to a file for later retrieval. Deserialization is the process of reading a serialized object's bytes and constructing an object from them.

What is the effect of the final keyword on methods?

When a method is declared final cut cannot be overridden in a subclass.

What is the effect of the final keyword on a class?

When a class is declared final, no classes may inherit from it. All of its members are implicitly final.

Describe the defects of polymorphic variable declaration.

A variable can be used to call only the public methods of its data type, no matter what type of object it references. At runtime, if the object assigned to a variable has overridden one of the methods inherited from the variable data type, the object's method is used.

Describe the difference between pre-test loops and post-test loops.

Pre-test loops only ever execute if a set of conditions is met first. Post-test loops always execute at least once because they execute their instructions and then check if they should do so again.

What is the advantage of using a sentinel?

It creates the ability to terminate a user-controlled loop by passing a value that cannot be mistaken for a standard argument.

What is the difference between prefix and postfix increment operators?

Prefix operators modify the value of a variable before it is used, whereas postfix operators modify the value of a variable only after it has been used.

How can you determine the minimum and maximum values that can be stored in a variable of a given data type?

By using the MIN_VALUE and MAX_VALUE constants of the wrapper classes.

What is an "is a" relationship?

When one object is a specialized version of another object.

How does a file buffer increase a program's performance?

A buffer is a small "holding section" in main memory. When a program writes data to a file, that data is written to the buffer. When the buffer is filled, all the information stored there is written to the file.

If you do not write an equals method for a class, Java provides one. Describe the behavior of the equals method that Java automatically provides.

It does the same thing as the equality operator.

Why are static methods useful for creating utility classes?

They perform operations on data without any need to collect and store data and can be called without creating an instance of he class to which they belong.

When the same name is used for two or more methods in the same class, how does Java tell them apart?

It checks the number and data types of the parameters.

What is component reusability?

Component reusability is when an object performs a specific, well-defined operation and can be used by programs that need the component's service.

Will the Java compiler translate a source file that contains syntax errors?

When recursion is used to solve a problem, why must the recursive method call itself to solve a smaller version of the original problem?

Because the recursion eventually has to stop for a solution to be reached.

Why are constructors useful for performing "start up" operations?

Because a class' constructor is automatically called when an object is created from it.

When one object is a specialized version of another object there is a N?

When one object is a specialized version of another object, there is an "is a" relationship between them. The specialized object " is a" version of the general object. What does a subclass inherit from its superclass? It inherits all the superclass's attributes.

What is the feature of object

In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object (prototype-based inheritance) or class (class-based inheritance), retaining similar implementation.

What are the 4 characteristics of object

Object-oriented programming has four basic concepts: encapsulation, abstraction, inheritance and polymorphism..
Encapsulation. ... .
Abstraction. ... .
Inheritance. ... .
Polymorphism..

What is the special method that is called when an object of a class is created?

Instantiation: The new keyword is a Java operator that creates the object. As discussed below, this is also known as instantiating a class.

Which features of OOPs derives the class from another?

Inheritance is a feature of OOPs which allows classes inherit common properties from other classes.

What are main characteristics of objects oriented programming explain its benefits?

4 Advantages of Object-Oriented Programming.
Modularity for easier troubleshooting. ... .
Reuse of code through inheritance. ... .
Flexibility through polymorphism. ... .
Effective problem solving. ... .
What to know about OOP developer jobs..