Misc Flashcards

1
Q

what are 4 fundamental data types in java

A

int, float, character, boolean;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

size and range of byte in java

A

1 byte and +127 to -128

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

size and range of short in java

A

2 byte and +32767 to -32768

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

size and range of int in java

A

4 byte and +x to -(x+1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

size and range of long in java

A

8 byte and +y to -(y+1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

size of float in java

A

4 bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

size of double in java

A

8 bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The letter ‘f’ must follow these type of constants

A

float type(float and double)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

default initial value of int

A

zero(0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

default initial value of float

A

zero(0.0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

default initial value of character

A

NA

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

default initial value of boolean

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Two types of programming languages are:

___ oriented and ___ oriented

A

Procedural and Object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Difference between class and objects

A
Class exists logically; it has no space allocated in memory to it; is loaded only once in memory while execution; resides in disk as 
object is allocated space when it is created; based on its parent class definition; reside in main memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Data members of a class are also known as

A

properties/fields/attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

methods of a class are also known as

A

behaviors/accessories

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

File name should be the same as the ___ name

A

Class name; although this is convention and not a rule

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Command to execute a java program

A

java ClassName; make sure that ClassName.class exists so that ClassLoader can put it into main memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

4 ways to input data to Java program

A

Keyboard; command prompt; file reading; xml file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Autoboxing/Unboxing is done by ____

A

Java Compiler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are default packages and they are imported by whom?

A

packages that need not be explicitly imported in java programs;
put internally by java compiler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

System class belongs to this package

A

java.lang

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Use of this keyword

A

differentiate between members of class and formal parameters of same name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

obj1.method_name(obj2);

obj1 and obj2 are

A

source/invoking object, and destination/target object respectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

5 types of inheritance are

A

single/multilevel/multiple/hierarchical/hybrid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

If we don’t want our class to be inherited, we must define it as ___ class

A

final class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

If we don’t want to give some methods/members of base class to derived class

A

the must be declared private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Java does not allow ___ classes however ___ ___ classes are allowed

A

private, and Inner Private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

scope of base class object is ___

A

can access base class objects but not derived class objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

types of relationships between classes in java

A

is_a, has_a, and uses_a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

is_a relationship uses ___ keyword

A

extends

32
Q

is_a relationship follows ___ memory management

A

logical

33
Q

define has_a relationship

A

an object of one class is used as data member of another class

34
Q

define uses_a relationship

A

a method in the class uses an object of another class.

35
Q

All java classes have a default ___ relationship because ___ class is base of all classes

A

is_a, Java.Lang.Object

36
Q

example of has_a relationship

A

System.out which contains out, out is an object of the PrintStream class.

37
Q

super keyword is used for

A

accessing same name methods/members of the base class in the derived class.

38
Q

When derived class constructor is called the constructors of base class are called ____ but are executed ___

A

bottom-to-top; top-to-bottom

39
Q

use of this() constructor

A

calls current class default constructor from current class parameterized constructor

40
Q

use of this(….) constructor

A

used to call current class constructor from other constructors

41
Q

when using this() and this(….) we must avoid having ___

A

cyclic calling of constructors.

42
Q

two ways to implement polymorphism with methods in java

A

method overloading; method overriding

43
Q

two types/principles of polymorphism

A

static/compile time polymorphism;

dynamic/run time polymorphism

44
Q

we can’t create an object of an abstract class directly, but we can do so by ___

A

creating an implementation/derived class.

45
Q

abstract method cannot be ___, ___ & ___

A

private, final, static

46
Q

what are the two types of packages in java

A

1) pre-defined/built-in 2) user-defined

47
Q

This package is also called the default package in java

A

java.lang.*; it is imported by default in all classes.

48
Q

java.lang.* has these following five basic facilities

A

1) command line arguments
2) data conversions
3) garbage collection
4) developing thread based apps
5) developing exception based apps

49
Q

private modifier is also known as ___

A

native access modifier

50
Q

default modifier is also known as ___

A

package access modifier

51
Q

protected access modifier is also known as ___

A

inherited access modifier

52
Q

public access modifier is also known as ___

A

universal access modifier

53
Q

is default a keyword in java?

A

no

54
Q

what are the three types of errors we get in all programming languages?

A

1) compile time errors
2) logical errors
3) run time errors

55
Q

what is a logical error?

A

logical errors are errors that produce wrong result according to business logic,

56
Q

how is a logical error different from a runtime error?

A

runtime errors don’t produce any wrong output, they simply terminate the program. they are a result of invalid operation/input.

57
Q

what are the two types of exceptions?

A

1) pre-defined/built-in exceptions

2) user/programmer/custom-defined exceptions

58
Q

pre-defined exceptions are of two types. what are they?

A

synchronous and asynchronous types

59
Q

synchronous exceptions are of two types. what are they?

A

checked and un-checked

60
Q

5 keywords often used when handling exceptions

A
  1. try
  2. catch
  3. finally
  4. throw
  5. throws
61
Q

nested try blocks are permitted in java. true/false

A

true

62
Q

one can write try catch blocks in finally. true/false

A

true

63
Q

out and err are objects of which class?

A

PrintStreamClass, which are used in System class

64
Q

3 ways to print error messages in exceptions

A
  1. print object of Exception/Throwable class.
  2. use printStackTrace()
  3. use getMessage() in Exception object
65
Q

2 ways of creating a thread class

A

using:

  1. java.lang.Thread class
  2. java.lang.Runnable interface
66
Q

use, and prototype of setName, and getName in Thread class

A

used to set user-friendly names for threads
public final void setName(String);
public final String getName();

67
Q

use, and prototype of setPriority, and getPriority in Thread class

A

public final void setPriority(int);

public final int getPriority();

68
Q

use, and prototype of isAlive()

A

true if thread is in execution; false otherwise(halted state, or new state)

public boolean isAlive()

69
Q

use of public void run()

A

in this method we write the java code that has to be executed by the thread. it is a null body method that we override from the Thread class.

70
Q

use of public final void start()

A
  1. moves thread from READY to NEW state
  2. provides multithreading services(concurrency, synchronization, and ITC)
  3. automatically calls run() which contains the logic of thread
71
Q

use of suspend()

A

puts a thread into WAITING state.
suspends its execution.
it can be resumed from here.

72
Q

use of resume()

A

move a thread from WAITING state to READY state

thread continues execution from where it had started.

73
Q

use of stop()

A

move a thread into the HALTED state

thread stops execution completely, and cannot be resumed from there.

74
Q

use of public final ThreadGroup getThreadGroup()

A

get the thread group name of foreground thread

75
Q

use of ‘public static final Thread currentThread()’

A

it is a factory method

returns all the thread that are currently running

76
Q

use of ‘public static final void sleep(long)’

A

makes a thread pause for certain number of milliseconds

77
Q

ThreadGroupName always resides in this method

A

main()