• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/172

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

172 Cards in this Set

  • Front
  • Back

What is the difference between JDK, JRE and JVM?

JVM - Java virtual machine - provides the runtime environment for java bytecode execution


JRE - Java Runtime Environment - implementation of the JVM


JDK - Java development kit. has JRE and development tools



How many types of memory areas are allocated by JVM?

1.Class


2. Heap


3. Stack


4. Program Counter Register


5. Native method stack

What is JIT Compiler

Just-in-time: used to improve performance. Compiles similar bytecode together so less time is needed for compilation

What is platform?

A platform is the hardware or software environment on which the program runs

What is the main difference between Java platform and other platforms?

Java platform is a software=based platform that runs on top of other hardware-based platforms.


made up of : runtime environment and API

What gives Java its write once and run anywhere nature?

The bytecode. It is not platform specific and can be fed to any platform

What is classloader?

The classloader is a subsystem of JVM that is used to load classes and interfaces.

Is Empty .java file a valid source file name?

Yes it would run by just writing the class. ex java A

Is delete, next, main, exit or null keywords in Java

no

If I don't provide any arguments on the command line, then the string array of Main method will be empty or null?

Empty but not null

What if I write static public void instead of public stativ void

Will run properly

What is the default value of the local variables?

local variables are not initialized to any default value, neither primitives nor object references

What is the difference between OOP and OBP

OBP follows all of the features of OOP except Inheritance (ex. JavaScript)

What will the initial value of an object reference which is defined as an instance variable?

null

What is a constructor?

Constructor is like a method that is used to initialize the state of an object

What is the purpose of default constructor?

to provide the default values to the objects

Does constructor return any value?

yes, the current instance

is the constructor inherited?

no

Can you make a constructor final?

no

What is a static variable

used to refer to the common property of all objects, that is not unique to each object

What is a static method

method that belongs to the class rather than the object of a class. can be invoked without the need for creating an instance of the class

Why is the main method static?

because the object is not required to class static methods.

What is a static block?

It is used to initialize the static data member. It is executed before main method at the time of classloading

Can we execute a program without a main method

yes, through the static block

What if the static modifier is removed from the signature of the main method

Program would compile, but at runtime throw an error nosuchmethod error

What is the difference between static (class) method and instance method

static - object is not required to call the method


instance - object is required to call the method

What is 'this'?

this refers to the current object

What is inheritance?

Inheritance is a mechanism in which one object acquires all the properties and behaviors of another object of another class. It represents an IS-A relationship

Which class is the superclass for every class?

Object

Why is multiple inheritance not supported in Java?

To reduce complexity and to simplify the language

What is composition?

Holding the reference of the other class within some other class

What is the difference between aggregation and composition

Aggregation represents a weak relationship, whereas composition represents a strong relationship

Why does Java not support pointers

Pointers refer to the memory address. These are not used in Java for security reasons and because of complexity

What is super in java?

Keyword which refers to the immediate parent

Can you use this and super both in a constructor?

no, it can only be this or super

What is object cloning

creating the exact copy of an object

What is method overloading

Having a class with multiple methods by the same name, but different parameters. Used to avoid unneeded nulls in methods

Why is method overloading not possibly by changing the return type in java?

It creates ambiguity

Can we overload the main method

yes

What is method overriding

When a subclass provides a specific implementation of a method of the parent class

Can we override static methods?

No

Why can we not override static methods?

Because the static method is the part of the class that is bound. whereas instance method is bought with the object.

Can we override overloaded methods?

Yes

Difference between Overloading and overriding

overloading - multiple methods which accept different parameters


overriding - when a subclass creates a new method with the same name of the parent method and same parameters

Can you have virtual functions in Java

all functions are virtual by default

What is the covariant return type?

It is a return type which returns the type of a subclass

What is the final variable?

It is a variable which cannot be changed and is constant

What is a final method

cannot be overriden

what is a final class

cannot be inherited

What is a blank final variable?

A final variable which is not initialized at the time of declaration

Can we initialize a blank final variable?

yes only in the constructor if it is non-static. if it is a static blank final it can be initialized only in the static block

Can you declare the main method final

yes, public static final void main

What is runtime polymorphism?

Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time

Can you achieve runtime polymorphism by data members?

no

What is the difference between static binding and dynamic binding

static binding type of object is determined at compile time. dynamic binding is determined at runtime

What is abstraction?

Process of hiding the implementation details and showing only the functionality to the user

What is the difference between abstraction and encapsulation?

Abstraction hides the implementation details whereas encapsulation wraps code and data into a single unit

What is an abstract class?

A class that is declared as abstract. it needs to be extended and for its methods to be implemented. Contains all the common attributes

Can there be any abstract method without abstract class?

If a method is abstract, the class must be abstract

Can you use abstract and final both with a method?

no, because an abstract method must be overridden. And a final cannot be

Is it possible to instantiate the abstract class?

No

What is interface?

Interface is a blueprint of a class that has static constants and abstract methods.

Can you declare an interface method static

no, because methods of an interface are abstract by default. static and abstract cannot be used together

Can an interface be final

no because it needs to be implemented by another class

What is market interface

An interface that has no data member and methods

Difference between abstract class and interface

abstract - can have method body, instance variables, constructor, static methods, and be extended once


interface - only abstract methods, cannot have instance variables, no constructor, no static methods, can be implemented multiple times

Can we define private and protected in an interface

no, because interfaces are implicitly public

When can an object reference be cast to an interface reference?

An object reference can be cast to an interface reference when the object implements the referenced interface

What is a package?

A package is a group of similar type of classes, interfaces, and sub-packages

Do I need to import java.lang package

no. it is default

Can i import the same package/class twice? Will the JVM load the package twice at runtime?

You can import the same twice. The JVM will interanally load the class only once no matter how many times it is imported

What is a static import

We can access the static members of a class directly

What is exception handling?

Exception handling is a mechanism to handle runtime errors. it is used to handle checked exceptions

What is the difference between checked exception and unchecked exception?

checked - classes that extend throwable (SQLException, IOExceptions) - they are checked in compile-time


unchecked - classes that exend runtimeexception - exceptions that cannot be stopped, such as nullpointer

What is the base class for Error and Exception?

Throwable

Is it necessary that each try block must be followed by a catch?

It is not necessary. it should be followed by a catch or finally

What is a finally block?

Finally block is a block that is always executed

Can finally block be used without catch?

Yes, by try block

Is there any case when finally will not be executed?

finally will not be executed if the program exists (system.exit or fatal error)

difference between throw and throws

throw - used to explicitly throw an exception, checked exceptions can not be propagated with throw only, throw is followed by an instance


throws - used to declare an exception, checked exceptions can be propagated with throws, throws is followed by class

Can an exception be rethrown

yes

Can subclass overriding method declare an exception if the parent class method doesnt thrown an exception?

yes, but only unchecked exceptions not checked

What is exception propagation?

Forwarding the exception object to the invoking method is known as exception propagation

What is the meaning of immutable in terms of String?

unmodifiable or unchangeable. Once string object has been created, its value cant be changed

Why string objects are immutable in java?

Because java uses the concept of string literal.

How many ways can we create the string object?

String literal or by the new keyword

How many objects will be created in the following code? String s1 = "one"; String s2="two", String s3="three"

One object

Why does java use the concept of string literal?

To make Java more memory efficient. Because no new objects are created if it exists already in a string constant pool

How many objects will be created int he following code? String s= new String("Two");

two objects, one in the string constant pool and one in non-pool(heap)

What is the basic difference between string and stringbuffer object?

String is an immutable object, StringBuffer is a mutable object

What is the difference between StringBuffer and StringBuilder?

StringBuffer is synchronized whereas StringBuilder is not synchronized

How can we create an immutable class in java?

We can create immutable classes as the String class by defining the class final

What is the purpose of toString() method in java?

it returns the string representation of any object. It is mostly used for error logging

What is a nested class?

A class which is declared inside another class. There are 4 types of nested class members: inner class, local inner class, anonymous inner class and static nested class

Is there any difference between nested and inner classes?

inner class - non-static nested class, they are part of nested classes

Can we access the non-final local variable inside the local inner class?

No, local variables must be constant if you want to access it in a local inner class

What is a nested interface

Any interface declared inside of an interface or class

Can a class have an interface?

yes, a nested interface

Can an interface have a class?

Yes, they are static

What is garbage collection?

process of reclaiming the runtime unused objects. It is performed for memory management

What is gc()

a daemon thread. gc() method is defined in system class that is used to send requests to JVM to perform garbage collection

What is the purpose of finalize() method?

invoked just before the object is garbage collected. Used to perform cleanup processing

Can an unreferenced object be referenced again?

yes

Waht kind of thread is the garbage collector thread?

daemon

What is the difference between final, finally, finalize

final - keyword, method var or class which cannot be changed


finally - used in exception handling. block which is always executed


finalize - used in garbage collection. It is invoked jsut before the object is garbage collected.

What is the purpose of the runtime class?

to provide access to the java runtime environment

How will you invoke any external process in java?

By runtime.getRuntime().exec(?) method

What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?

The reader/writer class hierarchy is character-oriented. the inputstream/outputstream class hierarchy is byte oriented

What is an I/O filter?

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it passe from one stream to another

What is serialization?

process of writing the state of an object into a byte stream. mainly used to travel object's state on the network

What is deserialization?

Deserialization is the process of reconstructing the object from the serialized state. it is the reverse of serialization

What is the transient keyword

If you define any data member as transient, it will not be serialized

What is externalizable?

Externalizable interface is used to write the state of an object into a byte stream in compressed format. it is not a marker interface

What is the difference between serializable and externalizable itnerface

Serializable is a marker interface but Externalizable is not a marker interface.

How do I conver a numeric IP address like 192.18.9.39 into a hostname like java.sun.com

By InetAddres.getByName("192.1.3.4").getHostName()

What is reflection?

Reflection is the process of examining or modifying the runtime behaviour of a class at runtime

Can you access the private method from outside the class?

Yes, by changing the runtime behavior of a class if the class is not secured

What are wrapper classes?

Wrapper classes are classes tha tallow primitive type sot be access as objects

What is a native method?

A native method is a method that is implemented in a language other than Java

What is the purpose of the System class?

The purpose of the System class is to provide access to system resources

What comes to mind when someone mentions a shallow copy in java?

Object cloning

What is a singleton class

means that at any given time only one instance of the class is present

What is Java Bean?

A reusable software component written in JAva programming

What is multithreading?

multi threading is a process of executing multiple threads simultaneously. Its main advantage is: threads share the same address space, thread is lightweight, cost of communication between process is low

What is a thread?

A thread is a lightweight sub process. It is a separate path of execution. It is called separate path of execution because each thread runs in a separate stack frame.

What is the difference between preemptive scheduling and time slicing?

preemptive scheduling - the highest priority task executed until it enters the waiting or dead states or a higher priority task comes into existence


time slicing - task executes for a predefined slice of time and then reenters the pool of ready tasks. then scheduler determines which task should execute next

What does join() method do?

join() method waits for a thread to die. in other words, it causes the currently running threads to stop executing until the thread it joins will comple its task

what is the difference between wait and sleep method?

wait() - defined in object class, releases the lock


sleep() - defined in thread class, doesn't release the lock

Is it possible to start a thread twice?

No, if it does it throws an exception

Can we call the run() method isntead of start()

yes, but it will not work as a thread rather it will work as a normal object so there will not be context-switching between threads

What about the daemon threads

daemon threads are the low priority threads that provide the background support to the user threads

Can we make the user thread as a daemon thread if thread is started

no, it will throw an illegal thread state exception

What is shutdownhook?

a thread invoked simply before JVM shuts down

When should we interrupt a thread?

If we want to break out the sleep or wait state of a thread

What is synchronization?

capability of controlling the access of multiple threads to any shared resource. used to: prevent thread interference, to prevent consistency problems

What is the purpose of synchronized block?

synchronized block is used to lock an object for any shared resource. Scope of synchronized block is smaller than the method

Can java objects be locked down for exlcusive use by a given thread?

Yes, you can lock an object by putting it in a synchronized block

What is static synchronizatiion

If you make any static method as synchronized, the lock will be on the class not on the object

What is the difference between notify and notifyAll

notify() - used to unblock one waiting thread


notifyAll() - used to unblock all the threads in a waiting state

What is a deadlock?

a situation when two threads are waiting for each other to release a resource

What is the difference between an ArrayList and Vector

ArrayList - not synchronized, not a legacy class, increases its size by 50% of the array size


Vector - synchronized, legacy class, increases its size by double the array size

What is the difference between an ArrayList and a LinkedList

ArrayList - uses dynamic array, not efficient for manipulation before of shifting, better to store and fetch data


LinkedList - doubly linked lists, efficient for manipulation, better to manipulate data

Iterator vs ListIterator

Iterator - traverses the elements in forward direction only, can be used in List, Set and Queue


ListIterator - traverses the elements in backward and forward fashion, can be used in List only

Iterator vs Enumaration

Iterator - can traverse legacy and non-legacy elements, fail-fast, slower than enumeration


Enumeration - can traverse only legacy elements, not fail-fast, faster than iteration

List vs Set

List - contain duplicate elements


Set - only unique elements

HashSet vs Treeset

HashSet - no order


treeSet - ascending order

Set vs Map

Set - contains values only


Map - contains key and values both

HashSet vs HashMap

HashSet contains only values whereas HashMap contains entry(key,value). HashSet can be iterated by HashMap needs to convert into set to be iterated

HashMap vs HashTable

HashMap - not synchronized, contain one null key and multiple null values


Hashtable - synchronized, cannot contain any null key or value

Collection vs Collections

Collection - an interface - provides normal functionality of data structure to List, Set and Queue


Collections - class - is to sort and synchronize collection elements

Comparable vs Comparator

Comparable - provides only one sort sequence, provides one method name compareTo()


Comparator - provides multiple sort of sequences, method compare()

What is the advantage of Properties file?

If you change the value in the properties file, you don't need to recompile the java class

What does the hashCode() method do?

returns a hash code value.

Why do we override the equals() method?

It needs to be override if we want to check the objects based on property

What is the advantage of generic collection?

If we use generic class, we don't need typecasting. It is typesafe and checked at compile time

What is hash-collision in Hashtable and how is it handled

two different keys with the same has value. two different entries will be kept in a single hash bucket to avoid the collisison

What is the dictionary class?

provides the capability to store key-value pairs

What is the default size of load factor in hashing based collection?

.75

What is JDBC?

Java API that is used to connect and execute query to the database.

What is JDBC Driver?

JDBC driver is a software component that enables java application to interact with the database.

What are the steps to connect to the database in java?

1. Registering the driver class


2. Creating the connection


3. Creating the statement


4. Executing queries


5. Closing the connection

What are the JDBC API components?

Interfaces: connection, statement, preparedstatement, resultsset, resultssetmetadata, databasemetadata, callablestatement


Classes:DriverManager, Blob, Clob, Types, SQLException

What are the JDBC statements?

Statement, PreparedStatement, CallableStatement

Statement vs preparedstatement

Statement - query is compiled each time


PreparedStatement - query is compiled only once

How can we execute stored procedures and functions?

By using callable statement interface

What is the role of JDBC DriverManager class?

DriverManager class manages the registered drivers. it can be used to register and unregister drivers

What does the JDBC Connection interface do?

Connection interface maintains a session with the database

What does the JDBC ResultSet intrace do?

The ResultSet object represents a row of a table. It can be used to change the cursor pointer and get the information from the database

What does the JDBC DatabaseMetaData interface do?

Returns the information of the database such as username, driver name, driver version, ,number of tables, number of views

Which interface is responsible for transaction management in JDBC?

Connection interface provides methods for transaction management such as commit(), rollback() etc

What is batch processing and how do you perform batch processing in JDBC?

We can execute multiple queries

How can we store and retrieve images from the database?

By using PreparedStatement interface