Sunday, February 26, 2012

Java Interview Questions & Answers


What's the difference between a queue and a stack?


Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule

You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces? 
Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.



What makes a plugin secure?

What makes a plugin secure?
Here are some characteristics of a secure plugin:

1. It is digitally signed by the publisher by a third party issued certificate. This way the user at least knows where the plugin in coming from.

2. Inform the user of any actions which can lead to any changes in the system before hand and allow user to reject the proposed actions.

3. Give user the option to save current system settings such that the user can go back to it after the plugin has finished execution if the user so desires.

Items 2 and 3 above are sometimes the responsiblity of the application installing and using the plugin and not the plugin itself. From the end user perspective they are the same. So the the word plugin here can mean either just the plugin or the plugin together with web application driving it.

Both java applets and activex components are plugins. Both are written to the disk and saved for future use. ActiveX components can be used by applications other than the web browser while for most practical purposes, java applets can only be used from a web browser (there are stanalone java applet hosting programs out there but they are mostly used by developers and not by end users). The ActiveX component installation requires modification to system registery and hence the end user must have administrative privilege in order to install it while Java applets don't need any adminitrative privilege for installation. One can argue that this makes a signed Java Applet a bigger security threat than an ActiveX component since even a user with minimum previlege can download and run it without the knowledge of the system adminstrator. The only way to avoid this situation is to set the browser to not allow Java Applets all together. 


What is the difference between Web Server and Application server?

·         Webserver serves pages for viewing in web browser, application server provides exposes business logic for client applications through various protocols
·         Webserver exclusively handles http requests. application server serves business logic to application programs through any number of protocols.
·         Webserver delegation model is fairly simple, when the request comes into the webserver, it simply passes the request to the program best able to handle it (Server side program). It may not support transactions and database connection pooling.
·         Application server is more capable of dynamic behavior than webserver. We can also configure application server to work as a webserver.Simply application server is a superset of webserver.
·         Web Server serves static HTML pages or gifs, jpegs, etc., and can also run code written in CGI, JSP etc. A Web server handles the HTTP protocol. Eg of some web server are IIS or apache.
·         An Application Server is used to run business logic or dynamically generated presentation code. It can either be .NET based or J2EE based (BEA WebLogic Server, IBM WebSphere, JBoss).
·         A J2EE application server runs servlets and JSPs (infact a part of the app server called web container is responsible for running servlets and JSPs) that are used to create HTML pages dynamically. In addition, J2EE application server can run EJBs - which are used to execute business logic.
·         An Application server has a 'built-in' web server, in addition to that it supports other modules or features like e-business integration, independent management and security module etc.

FAQ on Java Security Part 1

     Is Java secure?

Nothing in life is completely secure; Java is no exception. Several specific security problems have been discovered and fixed since Java was first released. If you're using an up-to-date Web browser, you are usually safe against the known attacks. However, nobody is safe against attacks that haven't been discovered yet.
If somebody says Java is safe because ``hackers aren't smart enough to exploit the problems,'' don't believe them. We're disappointed that some people who should know better are still spouting this nonsense. We've discovered several security problems, and we're pretty sure we're not the smartest people in the world. If one group of hackers creates a Java-based attack and shares it with their friends, we're all in trouble.

Other Web ``scripting'' tools such as JavaScript, Visual Basic Script, or ActiveX face the same sorts of problems as Java. ``Plug-in'' mechanisms provide no security protection. If you install a plug-in, you're trusting that plug-in to be harmless.

What are the risks?

There are two classes of security problems: nuisances and security breaches. A nuisance attack merely prevents you from getting your work done - for example it may cause your computer to crash. Security breaches are more serious: your files could be deleted, your private data could be read, or a virus could infect your machine.
If you are the victim of a security breach, any data stored on your machine may be read or corrupted by a bad guy. If you've got important company secrets on your computer, maybe you should surf the net on another machine.

In the not-too-distant future, your computer may be able to digitally sign documents that are legally binding, just like your paper signature. Your computer may also be able to spend your money. In a world like that, security becomes even more important than it is right now.

How common are security breaches?

So far, there have been no publicly reported, confirmed cases of security breaches involving Java, though there have been some suspicious events that might possibly have involved Java security problems. Of course, the lack of reported cases is no guarantee that there haven't been breaches that either weren't discovered or weren't reported. But it does indicate that breaches are rare.

Who is at risk?

You're at risk if you're running a Java-enabled browser and you visit a Web page written by a person you don't know or don't trust. Since the two most common browsers, Netscape Navigator and Microsoft Internet Explorer, are Java-enabled, most people surfing the Web are at risk.

How can I protect myself?

If you maintain sensitive data on your computer that you think an unscrupulous adversary might want, you should disable Java and JavaScript, as well as not installing plug-ins, except from well-known vendors.

If you don't disable Java or JavaScript, think twice before visiting a Web site belonging to a person you don't know or don't trust. Of course, some people will be perfectly happy just living with the risk.

You can reduce the damage caused by a potential security breach by taking common-sense precautions like backing up your data frequently and keeping sensitive data off your Web-surfing machine.

What about products that claim to detect malicious applets?

We are skeptical about these products. They probably can't hurt, but don't let yourself get a false sense of security from using them.

What about products that claim to block Java applets at a firewall?

Recent research by David Martin, S. Rajagopalan, and Avi Rubin suggests that it is extremely difficult, if not impossible, to do this, so we suspect that these products can be bypassed by sophisticated attackers.

If you want to block Java, the best way to do it is by setting your browser preferences to disable Java.

How can I restrict which sites my browser will accept applets from?

We are about to release a prototype tool that lets you do this.

Won't digital signatures solve all of the problems?

No, they'll only help a little. Digital signatures let you know who wrote an applet, but they don't help you decide whether you can trust the author.

Is this problem ever going to go away?

No. Security will always be an issue with any network software. As long as vendors are racing their products out the door and adding new functionality with each and every release, you can expect security bugs will always exist. Writing crash-proof software is hard. Writing secure software is even harder.

Which is more secure: Netscape Navigator or Microsoft Internet Explorer?

In our judgement, the latest versions of the two browsers offer roughly comparable levels of security.

Which version of my browser should I use?

Generally, the latest version is the safest. Be sure to regularly check your browser vendor's Web pages for announcements of new versions. Look carefully - the announcements are not always prominent.

What about ``hostile applets?''

This is a general term for Java applets (programs) that exploit security bugs. There are some pages on the Web that demonstrate, with appropriate warning messages, some hostile applets. The applets we've seen are nuisance attacks rather than damaging attacks.

I run a Web server. Am I at risk?

Not directly. But watch out for some newer servers that support "servlets". Servlets are fine if they are all written by the people running the server site; using servlets in this way is probably better than using CGI scripts. Going beyond this to let clients upload Java servlets into your server is very risky.
Of course, you should be careful about which Java applets appear on your server. Unless you wrote the applet yourself, you don't necessarily know what it's doing. If you copy somebody else's applet, it could possibly be a trojan horse - doing something useful as well as being malicious.

What about JavaScript?

Java and JavaScript, despite the similarity of their names, are not related. (Isn't marketing wonderful?) JavaScript has its own security problems, so you may also want to disable JavaScript.

Can an Interface have an inner class? - Yes.public interface abc
{
static int i=0; void dd();
class a1
{
a1()
{
int j;
System.out.println("inside");
};
public static void main(String a1[])
{
System.out.println("in interfia");
}
}
}
------------------------------------------------------------------------------------

Can we define private and protected modifiers for variables in interfaces?No
-----------------------------------------------------------------------------------

What is Externalizable?Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)
-------------------------------------------------------------------------------------

What modifiers are allowed for methods in an Interface?Only public and abstract modifiers are allowed for methods in interfaces.
--------------------------------------------------------------------------------------

What is a local, member and a class variable?Variables declared within a method are “local” variables. Variables declared within the class i.e not within any methods are “member” variables (global variables). Variables declared within the class i.e not within any methods and are defined as “static” are class variables
----------------------------------------------------------------------------------------
        What are the different identifier states of a Thread?The different identifiers of a Thread are: R - Running or runnable thread, S - Suspended thread, CW - Thread waiting on a condition variable, MW - Thread waiting on a monitor lock, MS - Thread suspended waiting on a monitor lock
------------------------------------------------------------------------------------------------------------------------

What are some alternatives to inheritance?Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).
---------------------------------------------------------------------------------------------------------------------------

Why isn’t there operator overloading?Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn’t even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte().
---------------------------------------------------------------------------------------------------------------------------


What does it mean that a method or field is “static"? Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That’s how library methods like System.out.println() work. out is a static field in the java.lang.System class.
-----------------------------------------------------------------------------------------------------------------------------

How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?String hostname = InetAddress.getByName("192.18.97.39").getHostName();
-------------------------------------------------------------------------------------------------------------------
       Difference between JRE/JVM/JDK?
Why do threads block on I/O? - Threads block on i/o (that is enters the waiting state) so that other threads may execute while the I/O operation is performed.

------------------------------------------------------------------------------------------------------------------------

What is synchronization and why is it important?With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object’s value. This often leads to significant errors.
--------------------------------------------------------------------------------------------------------------------------

Is null a keyword?The null value is not a keyword.
--------------------------------------------------------------------------------------------------------------------------

Can there be an abstract class with no abstract methods in it?Yes
--------------------------------------------------------------------------------------------------------------------------

Can an Interface be final?No
--------------------------------------------------------------------------------------------------------------------------

Can an Interface have an inner class?Yes.
--------------------------------------------------------------------------------------------------------------------------

Which characters may be used as the second character of an identifier,but not as the first character of an identifier?The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.

What modifiers may be used with an inner class that is a member of an outer class? - A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
-----------------------------------------------------------------------------------------------------------------------------

How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.
------------------------------------------------------------------------------------------------------------------------------

What are wrapped classes?Wrapped classes are classes that allow primitive types to be accessed as objects.
-------------------------------------------------------------------------------------------------------------------------------

What restrictions are placed on the location of a package statement within a source code file?A package statement must appear as the first line in a source code file (excluding blank lines and comments).
-------------------------------------------------------------------------------------------------------------------------------

What is the difference between preemptive scheduling and time slicing?Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
-------------------------------------------------------------------------------------------------------------------

What is a native method?A native method is a method that is implemented in a language other than Java.
---------------------------------------------------------------------------------------------------------------------

What are order of precedence and associativity, and how are they used?Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left
---------------------------------------------------------------------------------------------------------------------

What is the catch or declare rule for method declarations?If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.
---------------------------------------------------------------------------------------------------------------------

Can an anonymous class be declared as implementing an interface and extending a class?An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
---------------------------------------------------------------------------------------------------------------------

What is the range of the char type?The range of the char type is 0 to 2^16 - 1.
----------------------------------------------------------------------------------------------------------------------

What is the purpose of finalization?The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
---------------------------------------------------------------------------------------------------------------------

What is the difference between the Boolean & operator and the && operator?If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
---------------------------------------------------------------------------------------------------------------------


Struts
What is Jakarta Struts Framework?Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.
---------------------------------------------------------------------------------------------------------------------

What is ActionServlet?The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the
---------------------------------------------------------------------------------------------------------------------

Can we use the constructor, instead of init(), to initialize servlet?Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
---------------------------------------------------------------------------------------------------------------------

How can a servlet refresh automatically if some new data has entered the database?You can use a client-side Refresh or Server Push.
---------------------------------------------------------------------------------------------------------------------

EJB interview questions
Are enterprise beans allowed to use Thread.sleep()?Enterprise beans make use of the services provided by the EJB container, such as life-cycle management. To avoid conflicts with these services, enterprise beans are restricted from performing certain operations: Managing or synchronizing threads
---------------------------------------------------------------------------------------------------------------------

Is is possible for an EJB client to marshal an object of class java.lang.Class to an EJB?Technically yes, spec. compliant NO! - The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the Java language.
---------------------------------------------------------------------------------------------------------------------

Is it legal to have static initializer blocks in EJB?Although technically it is legal, static initializer blocks are used to execute some piece of code before executing any constructor or method while instantiating a class. Static initializer blocks are also typically used to initialize static fields - which may be illegal in EJB if they are read/write - In EJB this can be achieved by including the code in either the ejbCreate(), setSessionContext() or setEntityContext() methods.
-------------------------------------------------------------------------------------------------------------------
Is “abc” a primitive value?The String literal “abc” is not a primitive value. It is a String object.
---------------------------------------------------------------------------------------------------------------------

What restrictions are placed on the values of each case of a switch statement? 

During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.
---------------------------------------------------------------------------------------------------------------------

What is the query used to display all tables names in SQL Server (Query analyzer)?select * from information_schema.tables
---------------------------------------------------------------------------------------------------------------------

Is it possible to write two EJB’s that share the same Remote and Home interfaces, and have different bean classes? if so, what are the advantages/disadvantages?It’s certainly possible. In fact, there’s an example that ships with the Inprise Application Server of an Account interface with separate implementations for CheckingAccount and SavingsAccount, one of which was CMP and one of which was BMP.
---------------------------------------------------------------------------------------------------------------------

What is garbage collection?What is the process that is responsible for doing that in java? - Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process
---------------------------------------------------------------------------------------------------------------------

What kind of thread is the Garbage collector thread?It is a daemon thread.
---------------------------------------------------------------------------------------------------------------------

What is a Marker Interface?An interface with no methods. Example: Serializable, Remote, Cloneable
---------------------------------------------------------------------------------------------------------------------

What interface do you implement to do the sorting?Comparable
---------------------------------------------------------------------------------------------------------------------

What is the eligibility for a object to get cloned?It must implement the Cloneable interface
---------------------------------------------------------------------------------------------------------------------

J2EE EJB interview questions
What is the relationship between local interfaces and container-managed relationships?Entity beans that have container-managed relationships with other entity beans, must be accessed in the same local scope as those related beans, and therefore typically provide a local client view. In order to be the target of a container-managed relationship, an entity bean with container-managed persistence must provide a local interface.
---------------------------------------------------------------------------------------------------------------------

What does a remove method do for different cases of beans?Stateless Session : Does not do anything to the bean as moving the bean from free pool to cache are managed by the container depending on load. Stateful Session: Removes the bean from the cache. Entity Bean: Deletes the bean (data) from persistent storage
---------------------------------------------------------------------------------------------------------------------

How does a container-managed relationship work?An entity bean accesses related entity beans by means of the accessor methods for its container-managed relationship fields, which are specified by the cmr-field elements of its abstract persistence schema defined in the deployment descriptor. Entity bean relationships are defined in terms of the local interfaces of the related beans, and the view an entity bean presents to its related beans is defined by its local home and local interfaces. Thus, an entity bean can be the target of a relationship from another entity bean only if it has a local interface.
---------------------------------------------------------------------------------------------------------------------

What is an Applet? Should applets have constructors?Applets are small programs transferred through Internet, automatically installed and run as part of web-browser. Applets implements functionality of a client. Applet is a dynamic and interactive program that runs inside a Web page displayed by a Java-capable browser. We don’t have the concept of Constructors in Applets. Applets can be invoked either through browser or through Appletviewer utility provided by JDK.
---------------------------------------------------------------------------------------------------------------------

What are the Applet’s Life Cycle methods? Explain them?Following are methods in the life cycle of an Applet:
init() method - called when an applet is first loaded. This method is called only once in the entire cycle of an applet. This method usually intialize the variables to be used in the applet.
start( ) method - called each time an applet is started.
paint() method - called when the applet is minimized or refreshed. This method is used for drawing different strings, figures, and images on the applet window.
stop( ) method - called when the browser moves off the applet’s page.
destroy( ) method - called when the browser is finished with the applet.
---------------------------------------------------------------------------------------------------------------------

What is the sequence for calling the methods by AWT for applets?When an applet begins, the AWT calls the following methods, in this sequence:
init()
start()
paint()
When an applet is terminated, the following sequence of method calls takes place :

stop()
destroy()
-------------------------------------------------------------------------------------------------------------------
How do Applets differ from Applications?Following are the main differences: Application: Stand Alone, doesn’t need
web-browser. Applet: Needs no explicit installation on local machine. Can be transferred through Internet on to the local machine and may run as part of web-browser. Application: Execution starts with main() method. Doesn’t work if main is not there. Applet: Execution starts with init() method. Application: May or may not be a GUI. Applet: Must run within a GUI (Using AWT). This is essential feature of applets.
---------------------------------------------------------------------------------------------------------------


Can we pass parameters to an applet from HTML page to an applet? How? 
We can pass parameters to an applet using tag in the following way:


Access those parameters inside the applet is done by calling getParameter() method inside the applet. Note that getParameter() method returns String value corresponding to the parameter name.
----------------------------------------------------------------------------------------------------------------

How do we read number information from my applet’s parameters, given that Applet’s getParameter() method returns a string?Use the parseInt() method in the Integer Class, the Float(String) constructor or parseFloat() method in the Class Float, or the
Double(String) constructor or parseDoulbl() method in the class Double.
----------------------------------------------------------------------------------------------------------------

How can I arrange for different applets on a web page to communicate with each other?Name your applets inside the Applet tag and invoke AppletContext’s getApplet() method in your applet code to obtain references to the other applets on the page.
----------------------------------------------------------------------------------------------------------------

How do I select a URL from my Applet and send the browser to that page?Ask the applet for its applet context and invoke showDocument() on that context object.

URL targetURL;
String URLString
AppletContext context = getAppletContext();
try
{
targetURL = new URL(URLString);
}
catch (MalformedURLException e)
{
// Code for recover from the exception
}
context. showDocument (targetURL);
Can applets on different pages communicate with each other?
- No, Not Directly. The applets will exchange the information at one meeting place either on the local file system or at remote system.

----------------------------------------------------------------------------------------------------------------

How do I determine the width and height of my application?Use the getSize() method, which the Applet class inherits from the Component class in the Java.awt package. The getSize() method returns the size of the applet as a Dimension object, from which you extract separate width, height fields. The following code snippet explains this:

Dimension dim = getSize();
int appletwidth = dim.width();
int appletheight = dim.height();
----------------------------------------------------------------------------------------------------------------

Which classes and interfaces does Applet class consist?Applet class consists of a single class, the Applet class and three interfaces: AppletContext, AppletStub, and AudioClip.
----------------------------------------------------------------------------------------------------------------

What is AppletStub Interface?The applet stub interface provides the means by which an applet and the browser communicate. Your code will not typically implement this interface.
----------------------------------------------------------------------------------------------------------------

What tags are mandatory when creating HTML to display an applet?name, height, width
code, name
codebase, height, width
code, height, width
Correct answer is d.
----------------------------------------------------------------------------------------------------------------

What are the Applet’s information methods?The following are the Applet’s information methods: getAppletInfo() method: Returns a string describing the applet, its author, copyright information, etc. getParameterInfo( ) method: Returns an array of string describing the applet’s parameters.
----------------------------------------------------------------------------------------------------------------
What are the steps involved in Applet development?Following are the steps involved in Applet development:
Create/Edit a Java source file. This file must contain a class which extends Applet class.
Compile your program using javac
Execute the appletviewer, specifying the name of your applet’s source file or html file. In case the applet information is stored in html file then Applet can be invoked using java enabled web browser.
----------------------------------------------------------------------------------------------------------------

Which method is used to output a string to an applet?Which function is this method included in?
drawString( ) method is used to output a string to an applet. This method is included in the paint method of the Applet.
----------------------------------------------------------------------------------------------------------------

Why we can not extends two classes in Java?Trying to extend 2 classes, or multiple inheritence, would result in a few problems. One of it is when you use the super() method. If you use that while extending more then 1 class, which superclass are you referring to then? Java solves this problem by thus using implementations for its multiple inheritence purposes.
----------------------------------------------------------------------------------------------------------------

What gives Java its “write once and run anywhere” nature?Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platorm specific and hence can be fed to any platform. After being fed to the JVM, which is specific to a particular operating system, the code platform specific machine code is generated thus making java platform independent.
----------------------------------------------------------------------------------------------------------------

What are the four corner stones of OOP?Abstraction, Encapsulation, Polymorphism and Inheritance.
----------------------------------------------------------------------------------------------------------------

Difference between a Class and an Object?A class is a definition or prototype whereas an object is an instance or living representation of the prototype.
----------------------------------------------------------------------------------------------------------------

What is the difference between method overriding and overloading?Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments.
----------------------------------------------------------------------------------------------------------------

What is a “stateless” protocol?Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a single request response combination.
----------------------------------------------------------------------------------------------------------------

What is constructor chaining and how is it achieved in Java?A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.
----------------------------------------------------------------------------------------------------------------

What is passed by ref and what by value?All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references
----------------------------------------------------------------------------------------------------------------

Can RMI and Corba based applications interact?Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.
You can create a String object as String str = “abc"; Why cant a button object be created as Button bt = “abc";? Explain - The main reason you cannot create a button by Button bt1= “abc"; is because “abc” is a literal string (something slightly different than a String object, by the way) and bt1 is a Button object. The only object in Java that can be assigned a literal String is java.lang.String. Important to note that you are NOT calling a java.lang.String constuctor when you type String s = “abc";
----------------------------------------------------------------------------------------------------------------

What does the “abstract” keyword mean in front of a method? A class?Abstract keyword declares either a method or a class. If a method has a abstract keyword in front of it,it is called abstract method.Abstract method hs no body.It has only arguments and return type.Abstract methods act as placeholder methods that are implemented in the subclasses. Abstract classes can’t be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract.
----------------------------------------------------------------------------------------------------------------

How many methods do u implement if implement the Serializable Interface?The Serializable interface is just a “marker” interface, with no methods of its own to implement. Other ‘marker’ interfaces are
java.rmi.Remote
java.util.EventListener
----------------------------------------------------------------------------------------------------------------

What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)? 
It makes no difference in the generated class files since only the classes that are actually used are referenced by the generated class file. There is another practical benefit to importing single classes, and this arises when two (or more) packages have classes with the same name. Take java.util.Timer and javax.swing.Timer, for example. If I import java.util.* and javax.swing.* and then try to use “Timer", I get an error while compiling (the class name is ambiguous between both packages). Let’s say what you really wanted was the javax.swing.Timer class, and the only classes you plan on using in java.util are Collection and HashMap. In this case, some people will prefer to import java.util.Collection and import java.util.HashMap instead of importing java.util.*. This will now allow them to use Timer, Collection, HashMap, and other javax.swing classes without using fully qualified class names in.
----------------------------------------------------------------------------------------------------------------

What is the difference between logical data independence and physical data independence?Logical Data Independence - meaning immunity of external schemas to changeds in conceptual schema. Physical Data Independence - meaning immunity of conceptual schema to changes in the internal schema.
----------------------------------------------------------------------------------------------------------------

What is a user-defined exception?Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.
----------------------------------------------------------------------------------------------------------------

Describe the visitor design pattern?Represents an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. The root of a class hierarchy defines an abstract method to accept a visitor. Subclasses implement this method with visitor.visit(this). The Visitor interface has visit methods for all subclasses of the baseclass in the hierarchy.
----------------------------------------------------------------------------------------------------------------

What methods can be overridden in Java?In C++ terminology, all public methods in Java are virtual. Therefore, all Java methods can be overwritten in subclasses except those that are declared final, static, and private.
---------------------------------------------------------------------------------------------------------------

Can there be an abstract class with no abstract methods in it? 

Yes
----------------------------------------------------------------------------------------------------------------

Can an Interface be final? 
No
----------------------------------------------------------------------------------------------------------------



No comments:

Post a Comment

ShareThis

Related Posts Plugin for WordPress, Blogger...