OBJECT-ORIENTED PROGRAMMING Flashcards
A string is enclosed with single quotation marks.
False
One of the tools for Object oriented design includes class hierarchy diagram
True
Netbeans started as a student project called Selfie
False
All methods and variables in Java language are kept inside a method?
False
James Gosling works for ____________ when they developed java?
Sun Microsystems
Scanner class is found on java.io package.
false
byte has a maximum value of 127
True
int has a width of _ bytes
4
float has a width of _ bytes
8
println does not belong to the System class.
False
A Netbeans feature that provides information about the runtime behavior of applications
NetBeans Profiler
The main method is declared public so that it is accessible as part of the public interface of the program.
True
The goal in developing netbeans was to write a Delphi- like Java IDE in Java for the first time.
True
Most IDEs today doesn’t have GUI modeling utilities that simplify the development of UIs.
false
A valid Identifier or name in Java language can start with which character?
option1: a-z, A-Z
option2: $, _
The System keyword defines a template for an object of derived type HelloWorld
False
It is a derived data type
String
Scanner class is found on what java package?
java.util
In standalone Java applications, which method is mandatory?
main method
A java edition that provides a robust, flexible environment for applications running on embedded and mobile devices in the Internet of Things
Micro Edition
API stands for
Application Programming Interface
All methods and variables in Java language are kept inside a?
Class or Interface
A feature of Netbeans that makes it easy to create, deploy and import java beans.
Enterprise Java Beans (EJB) Development
boolean data type has only two values
true
IDE stands for ______
Integrated Development Environment
The __________ creates a software simulation of a CPU and memory and handles all communication between the Java program and the underlying operating system and hardware.
JVM
A documentation or javadoc comment is enclosed between /* and **/
False
double data type has a width of _ in bytes.
8
What is the need to mention “static” before main method?
Option1 : To call main method without creating an object of class
short has a width of _ bytes
4
It returns the long value of the number that the next token represents.
NextLng()
It is a computer software to help computer programmers develop software.
Integrated Development Environment (IDE)
print() prints string inside the quotes then the cursor moves to the beginning of the next line
False
Sun Microsystems is now a subsidiary of Cisco Corporation?
False. Oracle
A feature of Netbeans that enables support for multiple source roots, easy management of libraries, easily ported to other environments, all based on Apache Ant.
project system
It reads a float value from the user.
nextFloat()
main method is void because the Java interpreter does not expect to receive or process any output from the class.
A feature of Netbeans for renaming, changing and moving of various objects, field encapsulation and usage finding.
Refactoring
An operator that copies a bit to the result if it exists in both operands.
& (bitwise AND)
They return the result of shifting the bits of the left operand by the number of positions specified by the right operand.
Supposed: double x = 13.1614; int y = (int)x; what is the value of y?
Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.
>
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
0, 1, 2, 3
What is the output of the following code fragments?
int [ ] fun = new int [5];
fun[0] = 1;
fun[1] = 2;
fun[2] = 3;
fun[3] = 4;
fun[4] = 5;
int j = 3;
System.out.println(fun[ j-1]) ;
3
What is the output of the following code fragment?
for ( int j = 10; j > 5; j– )
{
System.out.print( j + “ “ );
}
System.out.println( );
10 9 8 7 6
What will be the output of the following program?
public class AllDimensionArrays {
public static void main(String[] args) {
int[] a1d = {};
int[] b1d = {1, 3};
int[][] a2d = {};
int[][] b2d = {{}};
int[][] c2d = {{1, 2}, {5}};
System.out.print(a1d.length + “ “ + b1d.length + “ “);
System.out.print(a2d.length + “ “ + a2d[0].length + “ “ + b2d.length + “ “ + b2d[0].length + “ “);
System.out.print(c2d.length + “ “ + c2d[0].length + “ “ + c2d[1].length);
}
}
ArrayIndexOutOfBoundsException
Consider the following codes:
int x=4;
System.out.println(–x);
What will be the EXACT output?
3
Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.
!=
The break statement causes the program flow to exit prematurely from the body of the loop statement.
true
What is the result of 7%2
1
decrease the value of the variable by a particular number by which it was decreased
decrement operators
An operator that divides left-hand operand by right-hand operand and returns remainder.
%
What will be the output of the following program?
boolean lampX = false, result; boolean lampY = true; result = lampY || lampX; System.out.println("Lamp switch-on " + result); result = lampY | lampX; System.out.println("Lamp switch-on " + result);
Lamp switch-on true
Lamp switch-on true
What will be the output of the following program?
class ArrayOutput
{
public static void main(String args[])
{
int[] input = {3, 5, 6, 7};
int output = multiplyEveryElement(input);
System.out.print(“Result of multiplying every element = “ + output + “.”);
}
public static int multiplyEveryElement(int[] input) { int args = 1; for(int i = 0; i <= input.length - 1; i++) { args *= input[i]; } return args; } }
Result of multiplying every element = 630.
Consider the following codes:
int x=2;
System.out.println(–x);
What will be the EXACT output?
1
Dividing integer by zero results in the throwing of ____________
The do-while loop facilitates evaluation of condition or expression at the end of the loop to ensure that the statements are executed at least once
True
bitwise operator is an operator used to perform bitwise operations on bit patterns or binary numerals that involve the manipulation of individual bits
True
Method overriding is combination of inheritance and polymorphism?
True
Which of the following is a type of polymorphism in Java?
Compile time polymorphism
The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines
true
Procedural Programming is a technique of solving a problem and breaking it down into smaller parts and solving each of the smaller problems.
true
When Overloading does not occur?
More than one method with same name but different method signature and different number or type of parameters
final Class: a class that can never be sub-classed
true
this keyword can be passed as argument in the constructor call.
false
It represents an instance of the class in which it appears
this
final Variable: constant variable
true
variables used in a method
method variables
In Encapsulation, Class variables can be made read-only or write-only
True
Encapsulation is also called as?
Data Hiding
Which among the following best describes encapsulation?
It is a way of combining various data members and member functions that operate on those data members into a single unit
In Encapsulation, the programmer can change one part of the code without affecting other parts
true
If data members are private, what can we do to access them from the class object?
Create public member functions to access those data members
Which among the following is false for single level inheritance?
There can be more than 2 independent classes involved in single inheritance
The private member’s are made public to all the classes in inheritance.
False
How many classes can be inherited by a single class in java?
Only 1
Which is the correct syntax of inheritance?
class derived_classname : access base_classname{ /define class body/ };
All languages support single level inheritance
True
An abstract class declares a common interface for the various members of a class hierarchy. The abstract class contains methods that will be declared in the subclasses. All classes in the hierarchy can use this same set of methods through polymorphism.
true
Which among the following best describes polymorphism?
It is the ability for a message/data to be processed in more than one form
In case of using abstract class or function overloading, which function is supposed to be called first?
Function with highest priority in compiler
Which type of function among the following shows polymorphism?
Virtual function
All methods in a final class must be explicitly declared final.
false
Which of the following is FALSE about abstract classes in Java
A class can inherit from multiple abstract classes.
Abstraction principle includes
Use abstraction whenever possible to avoid duplication
Can an abstract class define both abstract methods and non-abstract methods?
Yes–the child classes inherit both.
In order for the following code to be correct, what must be the type of the reference variable card?
_________ card;
card = new Valentine( “Joe”, 14 ) ;
card.greeting();
card = new Holiday( “Bob” ) ;
card.greeting();
card = new Birthday( “Emily”, 12 ) ;
card.greeting();
Card
Which class is used to handle the input and output exceptions?
IOExceptions
Say that methodA calls methodB, and methodB calls methodC. MethodC might throw a NumberFormatException. Can the program be written so that methodA handles the exception?
Yes, if the headers for methodC and methodB say …throws NumberFormatException
Say that a method catches an IOException in a catch{} block. Is it possible for that block to do some processing and then throw the same exception to the caller?
Yes—as long as the method also has a throws clause for that exception.
class Base extends Exception {}
class Derived extends Base {}
public class Main {
public static void main(String args[]) {
// some other stuff
try {
// Some monitored code throw new Derived(); } catch(Base b) { System.out.println("Caught base class exception"); } catch(Derived d) { System.out.println("Caught derived class exception"); }
}
}
Compiler Error because base class exception is caught before derived class
You are writing a program to check people into a hotel. People over 65 get a 10% discount. How would you write the program?
Normal if-else programming logic will be used.
If the Java program is using assertions, it must be run with -ea or -enableassertions switches.
False
public class Test
{
public void foo() { assert false; /* Line 5 */ assert false; /* Line 6 */ } public void bar() { while(true) { assert false; /* Line 12 */ } assert false; /* Line 14 */ }
}
What causes compilation to fail?
Line 14
What will happen when you compile and run the following code with assertion enabled?
public class Test{
public static void main(String[] args){ displayAge(20); } private static void displayAge(int age){ assert age >= 21 : getAgeMessage(); System.out.println(age); } private static String getAgeMessage() { return "Your age must be greater than 21"; }
}
The code will compile but will throw AssertionError when executed
Here is a method definition: int compute( a int, y double ){ . . . .} Which of the following has a different signature?
int compute( a int, y int ){ . . . .}
In case of using abstract class or function overloading, which function is supposed to be called first?
Function with highest priority in compiler
It is the ability for a message/data to be processed in more than one form
polymorphism
A method that is declared final cannot be overridden in a subclass.
true
An interface is typically used in place of an abstract class when there is no default implementation to inherit.
true
Higher the level of abstraction, higher are the details.
False
Is one without a body that is declared with the reserved word abstract.
abstract method
Which of the following classes fail to compile?
abstract class X { abstract void method(); }
abstract class Y extends X { }
class Z extends Y { void method() { System.out.println(“Class Z”); } }
All classes compile
Encapsulation and abstraction differ as ____________
Binding and Hiding respectively
MethodX might encounter an IOException or an AWTException, but handles neither. How should the header for methodX be written?
… methodX(…) throws IOException, AWTException
Which are the two blocks that are used to check error and handle the error?
Try and catch
What method of an Exception object returns a message string?
getMessage()
Which three statements are true?
Option1: Assertion checking is typically enabled when a program is deployed.
Option2:It is never appropriate to write code to handle failure of an assert statement.
Option3:Assertion checking is typically enabled during program development and testing.
Option4:Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.
Option5:Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
2,3,5
What handles interface handle sequences?
List
What package contain all the collection classes?
java.util
What List class is synchronized?
Vector
You can’t put null elements into Queues in the API?
true
Can we have a sorted and unordered set?
No
What type of collection does not extend the Collection interface?
Map
What is the difference between HashSet and TreeSet?
HashSet maintains no order while TreeSet maintains ascending order.
The erase() method of OutputStream Class flushes the current output stream.
false
This the standard output stream.
System.out
What is the difference between HashMap and Hashtable?
HashMap is not synchronized while the Hashtable is synchronized.
The standard error stream.
system.err
All are invalid codes in getting an input from the console, except one.
i=System.in.readln(123);
i=System.in.readf(“%i”,123);
i=System.in.read=123;
i=System.in.read();
i=System.in.read();
is the constructor of the FileReader class that creates a new file and get its file name in stringT
The FileReader (String file)
A method of the FileWriter class that flushes the data of FileWriter.
flush()
A constructor of the FileReader class that creates a new file and get its file name in string
FileReader (String file)
What class returns data in byte format like FileInputStream class?
Java FileReader
A method of the FileWriter class that is used to write the string into FileWriter.
write (String text)
A method of the FileReader class that is used to return a character in ASCII form. It returns -1 at the end of file.
read ()
the constructor of the FileReader class that creates a new file and get its file name in file objects.
FileReader (File file)
A method of the FileWriter class that is used to write char array into FileWriter.
write (char[] c)
a sequence of data.
Stream
It is the superclass of all classes representing an output stream of bytes. It accepts output bytes and sends them to some sink.
OutputStream
the standard input stream.
System.in
What is the design pattern followed by Iterator?
Iterator design pattern
What interface is not a part of Java’s collection framework?
SortedList
What is the correct difference between ArrayList and LinkedList?
ArrayList uses a dynamic array whereas the LinkedList uses doubly linked list.
Which List would you use if wanted fast access and were doing lots of insertions and deletions?
LinkedList
What is the method to convert the array of strings into a list?
Arrays class asList() method
What is returned from both the compare() and compareTo() methods?
int
Which List would you use if wanted fast access and were doing lots of insertions and deletions?
LinkedList
What type of Queue is a PriorityQueue?
What do maps care about
Uniqueness
What is the difference between the Iterator and Enumeration?
Iterator can traverse legacy and non-legacy containers whereas the Enumeration can traverse only legacy containers.
What type of collection would we use if we wanted no duplicates?
Set
is used to process the input and produce the output.
Java I/O (Input and Output)
Automatically created streams are attached with the console.
True
is used to read data from a source; it may be a file, an array, peripheral device
InputStream
In using __________, unlike FileOutputStream class, you don’t need to convert string into byte array because it provides method to write string directly.
FileWriter class
is used to read data from the file.
Java FileReader class
the constructor of the FileReader class that creates a new file and get its file name in string
ReaderFile (String file)
Java language is originally called ______
the ‘Oak’
a general-purpose, concurrent, class-based, object-
oriented language that is specifically designed to have as few
implementation dependencies as possible.
Java
They are compiled into a format called bytecode (files with .class
extension), which can be executed by a Java interpreter.
The Java source code files (files with .java extension)
It was intended for use in Sun’s project research to work on a
programming software to control electronic devices.
Java
This defines a class, a template for an object of derived type
HelloWorld
class HelloWorld
This access specifier/modifier, the main method is declared public so that it is accessible as part of the public interface of the program. Fundamentals of Java Language
public
This is the state of the method, it is static
because it must be called before the class
that hosts the method is instantiated
static
It returns _______ This is because the Java
interpreter does not expect to receive or
process any output from the class.
void
This is one of dozens of methods in the Systemclass. The System class is a part of the core Java language package of the Application
Programming Interface (API)
System.out.println( )
These names that are given by the
programmer as name of variables, methods
or functions, classes etc.
Rules:
Each character is either a digit, letter, underscore or currency symbol.
First character cannot be a digit.
The identifier name must not be a reserved word.
Identifiers
three (3) types of Java Comments
- A single-line comment starting with //
- A multi-line comment enclosed within /* */
- A documentation or javadoc comment is
enclosed between /** and */. These
comments can be used to generate HTML
documents using the javadoc utility, which is
part of Java language comment.