Misc Flashcards
what are 4 fundamental data types in java
int, float, character, boolean;
size and range of byte in java
1 byte and +127 to -128
size and range of short in java
2 byte and +32767 to -32768
size and range of int in java
4 byte and +x to -(x+1)
size and range of long in java
8 byte and +y to -(y+1)
size of float in java
4 bytes
size of double in java
8 bytes
The letter ‘f’ must follow these type of constants
float type(float and double)
default initial value of int
zero(0)
default initial value of float
zero(0.0)
default initial value of character
NA
default initial value of boolean
false
Two types of programming languages are:
___ oriented and ___ oriented
Procedural and Object
Difference between class and objects
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
Data members of a class are also known as
properties/fields/attributes
methods of a class are also known as
behaviors/accessories
File name should be the same as the ___ name
Class name; although this is convention and not a rule
Command to execute a java program
java ClassName; make sure that ClassName.class exists so that ClassLoader can put it into main memory.
4 ways to input data to Java program
Keyboard; command prompt; file reading; xml file
Autoboxing/Unboxing is done by ____
Java Compiler
What are default packages and they are imported by whom?
packages that need not be explicitly imported in java programs;
put internally by java compiler
System class belongs to this package
java.lang
Use of this keyword
differentiate between members of class and formal parameters of same name.
obj1.method_name(obj2);
obj1 and obj2 are
source/invoking object, and destination/target object respectively.
5 types of inheritance are
single/multilevel/multiple/hierarchical/hybrid
If we don’t want our class to be inherited, we must define it as ___ class
final class
If we don’t want to give some methods/members of base class to derived class
the must be declared private
Java does not allow ___ classes however ___ ___ classes are allowed
private, and Inner Private
scope of base class object is ___
can access base class objects but not derived class objects.
types of relationships between classes in java
is_a, has_a, and uses_a
is_a relationship uses ___ keyword
extends
is_a relationship follows ___ memory management
logical
define has_a relationship
an object of one class is used as data member of another class
define uses_a relationship
a method in the class uses an object of another class.
All java classes have a default ___ relationship because ___ class is base of all classes
is_a, Java.Lang.Object
example of has_a relationship
System.out which contains out, out is an object of the PrintStream class.
super keyword is used for
accessing same name methods/members of the base class in the derived class.
When derived class constructor is called the constructors of base class are called ____ but are executed ___
bottom-to-top; top-to-bottom
use of this() constructor
calls current class default constructor from current class parameterized constructor
use of this(….) constructor
used to call current class constructor from other constructors
when using this() and this(….) we must avoid having ___
cyclic calling of constructors.
two ways to implement polymorphism with methods in java
method overloading; method overriding
two types/principles of polymorphism
static/compile time polymorphism;
dynamic/run time polymorphism
we can’t create an object of an abstract class directly, but we can do so by ___
creating an implementation/derived class.
abstract method cannot be ___, ___ & ___
private, final, static
what are the two types of packages in java
1) pre-defined/built-in 2) user-defined
This package is also called the default package in java
java.lang.*; it is imported by default in all classes.
java.lang.* has these following five basic facilities
1) command line arguments
2) data conversions
3) garbage collection
4) developing thread based apps
5) developing exception based apps
private modifier is also known as ___
native access modifier
default modifier is also known as ___
package access modifier
protected access modifier is also known as ___
inherited access modifier
public access modifier is also known as ___
universal access modifier
is default a keyword in java?
no
what are the three types of errors we get in all programming languages?
1) compile time errors
2) logical errors
3) run time errors
what is a logical error?
logical errors are errors that produce wrong result according to business logic,
how is a logical error different from a runtime error?
runtime errors don’t produce any wrong output, they simply terminate the program. they are a result of invalid operation/input.
what are the two types of exceptions?
1) pre-defined/built-in exceptions
2) user/programmer/custom-defined exceptions
pre-defined exceptions are of two types. what are they?
synchronous and asynchronous types
synchronous exceptions are of two types. what are they?
checked and un-checked
5 keywords often used when handling exceptions
- try
- catch
- finally
- throw
- throws
nested try blocks are permitted in java. true/false
true
one can write try catch blocks in finally. true/false
true
out and err are objects of which class?
PrintStreamClass, which are used in System class
3 ways to print error messages in exceptions
- print object of Exception/Throwable class.
- use printStackTrace()
- use getMessage() in Exception object
2 ways of creating a thread class
using:
- java.lang.Thread class
- java.lang.Runnable interface
use, and prototype of setName, and getName in Thread class
used to set user-friendly names for threads
public final void setName(String);
public final String getName();
use, and prototype of setPriority, and getPriority in Thread class
public final void setPriority(int);
public final int getPriority();
use, and prototype of isAlive()
true if thread is in execution; false otherwise(halted state, or new state)
public boolean isAlive()
use of public void run()
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.
use of public final void start()
- moves thread from READY to NEW state
- provides multithreading services(concurrency, synchronization, and ITC)
- automatically calls run() which contains the logic of thread
use of suspend()
puts a thread into WAITING state.
suspends its execution.
it can be resumed from here.
use of resume()
move a thread from WAITING state to READY state
thread continues execution from where it had started.
use of stop()
move a thread into the HALTED state
thread stops execution completely, and cannot be resumed from there.
use of public final ThreadGroup getThreadGroup()
get the thread group name of foreground thread
use of ‘public static final Thread currentThread()’
it is a factory method
returns all the thread that are currently running
use of ‘public static final void sleep(long)’
makes a thread pause for certain number of milliseconds
ThreadGroupName always resides in this method
main()