Monday 20 July 2015

Adobe Java Subjective Questions

Q1 What is a transient variable?
A transient variable is one that is not serialized, it means if your class implements serializable interface and has a transient and some other variables then when you try to store the object in memory all the variables will be stored except the one which is declared as transient.
When you deserialize the object the value of transient is set to its default value.


Q2 Why would you design a J2EE application so that user data is entered by way of a JSP page and managed by an underlying JavaBean class?
This is because you want to have independence between the user view and the underlying application server. This is the major idea behind the Model-View-Controller architecture or the 3-tier architecture.


Q3 In a multi-tiered application, which tier is the browser in?
Tier - 1 (Client Side)


Q4 What advantage does an entity bean have over a session bean?
The advantage of entity bean is they are objects that can be designed using object oriented principles and can be persisted is a relational database. The the benefits of relational technologies can be leveraged using entity bean.


Q5 What is a thin client application?
A thin client application is something that does not have its own business login and uses severs for all the data processing.


Q6 What are synchronized methods and synchronized blocks?
Synchronized Methods are those which are declared with the keyword synchronized and are thread safe thus provide a lock when accessed in a multi-threaded environment. The basic disadvantage is that they provide a lock for the complete method.
Synchronized blocks contain a set of statements declared under a synchronized block and provides lock for the block run when accessed in a multi-threaded environment. They help to lock only the part of code that requires synchronization rather that the complete method.


Q7 What is the difference between Reader/Writer class hierarchy and InputStream/OutputStream class hierarchy?
The former basically works with stream of characters and the later works with bytes of data.


Q8 What is the difference between ">>" and ">>>" in Java?
>> is Signed Right Shift operator, this it shifts the bits to the right and appends 1 at the end if the number is negative
>>> is Unsigned Right Shift operator, this it shifts the bits to the right but appends 0 at the end regardless of the number being -ve or +ve

Example:
12>>3
-12>>3
12>>>3
12 in binary is 1100


Q9 What is the purpose of wait(), notify() and notifyAll() in Java?
wait( ) tells the calling thread to give up the monitor and go to sleep until some other
thread enters the same monitor and calls notify( ).
notify( ) wakes up the first thread that called wait( ) on the same object.
notifyAll( ) wakes up all the threads that called wait( ) on the same object. The
highest priority thread will run first.

Q10 Who invoke run() method on a thread in Java?
start() method invokes run() method on a thread in Java


Q11 What is a J2EE component? List out all other components?
J2EE component are functional units inside a J2EE application. Various J2EE components are-
Client app
Web app
EJB
Connectors


Q12 Find the output of the below program-
StringBuffer sb1 = new StringBuffer("display");
StringBuffer sb2 = new StringBuffer("display");
String s = "display";
System.out.println(sb1 == sb2); - false
System.out.println(sb1.equals(sb2)); - false
System.out.println(sb1.equals(s)); - false
System.out.println("TestABC".substring(3)); - tABC

Q13 What is finally in try-catch-finally blocks?


Q14 Which is illegal?
int i=0;
float f=45.0;
double d = 49.0;
-------------------
45.0 is double by default in java, in order to assign it to float use 45.0f

Q15 What is a package and how it is used in Java?
A package is used to organize classes in Java. It is used as
package p1;
import p1.ClassName;

Q16 Consider the program below

class Test {
static int total = 10;

public static void main(String args[]) {
    new Test();
}

Test() {
    System.out.println("in Test");
    System.out.println(this);
    int temp = this.total;
    if (temp > 5) {
       System.out.println(temp);
    }
}
Select the correct option
1. The program will not compile.
2. The program will compile but throw RunTimeException
3. The program will run and one of its output will be 10


Q17 Consider the program below
class Test {

int i[] = {0};

public static void main(String args[]) {
    int i[] = {1};
    change_i(i);
    System.out.println(i[0]);
}

public static void change_i(int i[]) {
        int j[] = {2};
        i=j;
    }
}

What will be the output of the program?
A. 0
B. 1
C. 2
D. Compile Time Error

No comments :

Post a Comment