Mixed Technical FAQ's

##### What is the basic difference between DBMS and RDBMS?

$$$$$ DBMS stands for Database Management System, which is a general term for a set of software dedicated to controlling the storage of data.

RDMBS stand for Relational Database Management System. This is the most common form of DBMS. Invented by E.F. Codd, the only way to view the data is as a set of tables. Because there can be relationships between the tables, people often assume that is what the word "relational" means. Not so. Codd was a mathematician and the word "relational" is a mathematical term from the science of set theory. It means, roughly, "based on tables".

$$$$$ 1) rdbms is object based database management system while dbms
2) Rdbms can maintain at many users at same time while dbms in not
3) In rdbms is relation is more important than object itself while dbms entity is more important.

$$$$$ The main advantage of an RDBMS is that it checks for referential integrity (relationship between related records using Foreign Keys). You can set the constraints in an RDMBS such that when a particular record is changed, related records are updated/deleted automatically.

$$$$$ The difference is dbms has no tables while rdbms has and also it describes about the relationships among the tables.
DBMS for small organizations where rdbms for large amount of data.
In DBMS only one user can access the same database, at the same time. In RDBMS many users simultaneously access the same database
RDBMS is more secure than DBMS
In DBMS store and retrieve small amount of Data In RDBMS store and retrieve large amount of Data

$$$$$ 1. Dbms is a single user system rdbms is a multi-user system 2. Dbms stores do not store data in the form of tables while rdbms stores it in the form of tables. 3. Most of dbms are not supporting client/server architecture as it is supported by rdbms. 4. Most dbms do not support distributed databases.
------------------------------------------------------------------------------------------------------------
###### What is meant by Open Source?

$$$$$ Open Source Initiative (OSI) is a non-profit corporation dedicated to managing and promoting the Open Source Definition for the good of the community, specifically through the OSI Certified Open Source Software certification mark and program. You can read about successful software products that have these properties, and about our certification mark and program, which allow you to be confident that software really, is "Open Source." They also make copies of approved open source licenses here.
The basic idea behind open source is very simple: When programmers can read, redistribute, and modify the source code for a piece of software, the software evolves. People improve it, people adapt it, and people fix bugs. And this can happen at a speed that, if one is used to the slow pace of conventional software development, seems astonishing.
The open source community have learned that this rapid evolutionary process produces better software than the traditional closed model, in which only a very few programmers can see the source and everybody else must blindly use an opaque block of bits.

Open source doesn't just mean access to the source code. The distribution terms of open-source software must comply with the following criteria:
Free Distribution.
Source Code.
Derived Works.
Integrity of Author’s Source Code.
No Discrimination against Persons or Groups.
No Discrimination against fields of Endeavor.
Distribution of license.
License Must Not Be Specific to a Product.
License Must Not Restrict Other Software.
License Must Be Technology-Neutral.

------------------------------------------------------------------------------------------------------------
##### What is the difference between a Webserver and an Application Server?

$$$$$ A Web server serves pages for viewing in a Web browser, while an application server provides methods that client applications can call.
A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.

$$$$$ 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. E.g. 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.
------------------------------------------------------------------------------------------------------------
##### Difference between a Servlet and an Applet?

$$$$$ Applet is a part of Core JAVA and Servlet of Advance Java. Applet is client side program and Servlet is Server side. When Applet runs it take the resources of client whereas Servlet is processed at server.
An Applet's class, jar files can be accessed and downloadable by client but not so in case of servlet.
Applets can run under any web browser their execution is dependent on Client as they require JRE Whereas Servlets do not require any thing specific at client side, as they require java enabled web/application Server.

$$$$$ Servlet is the server side component and the applet is the client side component. Applet makes the request to the servlet and servlet is the server, which respond that request.

$$$$$ Servlet doesn't have GUI, while applet have GUI. Applets are very heavy to handle as compared to servlet. Servlets are for server side and applet are for client view

##### What is a Co-related Query?
$$$$$

##### Difference between arraylist and vector?
$$$$$ 1. Array list is not synchronized while Vector is.
2. Array list has no default size while Vector has a default size of 10.
3. Array list don’t define any increment size while vector does.
4. Both Arraylist and Vector require an Iterator to display it.
5. If we insert an element beyond the border of a vector it will increases the size
by double of its original size, but an ArrayList will increases its size by 50% of
the original list.

for( int i =0;i System.out.println( vector.elementAt( i ) );
}

If you are not sure of when to use Vector or ArrayList, write your code as
List list = new Vector();
List list = new ArrayList();
and use the methods overridden from the List. This makes the code easier to change whenever you change your mind.

Vector and ArrayList are very similar. Both of them represent a 'growable array', where you access to the elements in it through an index.ArrayList it's part of the Java Collection Framework, and has been added with version 1.2, while Vector it's an object that is present since the first version of the JDK. Vector, anyway, has been retrofitted to implement the List interface.While the iterators that are returned by both classes are fail-fast (they cleanly thrown a ConcurrentModificationException when the original object has been modified), the Enumeration returned by Vector are not.Unless you have strong reason to use a Vector, the suggestion is to use the ArrayList.
------------------------------------------------------------------------------------------------------------
##### Explain the difference between a procedure and a function?
$$$$$ The difference between functions and procedures is really quite simple: functions return a value, while procedures don't. However, any function can be treated as a procedure by simply discarding its value.

##### What are the different type of drivers in JDBC?
$$$$$ The different types of drivers are:
Type 1:
A JDBC-ODBC bridge provides JDBC API access via one or more ODBC drivers. Note that some ODBC native code and in many cases native database client code must be loaded on each client machine that uses this type of driver. Hence, this kind of driver is generally most appropriate when automatic installation and downloading of a Java technology application is not important. For information on the JDBC-ODBC bridge driver provided by Sun, see JDBC-ODBC Bridge Driver.

Type 2:
A native-API partly Java technology-enabled driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.

Type 3:
A net-protocol fully Java technology-enabled driver translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC API alternative. It is likely that all vendors of this solution will provide products suitable for Intranet use. In order for these products to also support Internet access they must handle the additional requirements for security, access through firewalls, etc., that the Web imposes. Several vendors are adding JDBC technology-based drivers to their existing database middleware products.

Type 4:
A native-protocol fully Java technology-enabled driver converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary the database vendors themselves will be the primary source for this style of driver. Several database vendors have these in progress.

##### What is the difference between Servlet Context and Config?
$$$$$ Context is for whole webapp (i.e. inclusive of all the servlets) and Config is for one servlet.

##### What is the difference between Servlet Context and Servlet Config?
$$$$$

##### What is the difference between upcasting and downcasting?
$$$$$ Upcasting is casting to a higher-level type, for example casting a String reference to an Object, and downcasting is the reverse, for example casting an Object reference to a String.
A Upcast is when you cast up the object hierarchy (towards java.lang.Object).A Downcast is when you cast down it (towards the most specific classes).Upcasting is always safe and implicit. e.g.
Object o = new Integer(44);
Downcasting is not always safe, and you have to explicitly cast the object.
void foo(Object o)
{
Integer i = (Integer)o; //might not work depending on what o is
}

##### Difference between finalize () and finally () method?
$$$$$ finalize:

protected void finalize()
throws Throwable
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.
The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.
The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.
The finalize method is never invoked more than once by a Java virtual machine for any given object.
Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.
Throws:
Throwable - the Exception raised by this method


##### Why is finalize method protected?
$$$$$ The finalize method is invoked by the JVM/GarbageCollector on Objects which are no longer referenced. So, if I were the guy who designed the finalize method, ideally I would want it to be private. Just like why the writeObject method of the Serializable interface is private. These methods are not meant to be called by other user objects, these methods are invoked only by the JVM runtime classes only. So it would make sense to make them private, and have special handling in the VM to invoke these methods. This is ok in case of the writeObject method, however, making finalize method private would have other implications.

Assume we had decided to go ahead and allow the finalize method to be private. Consider the following classes
public class SuperClass { private HeavyResource resource = new HeavyResource(); private void finalize() throws Throwable { resource.shutdown(); } } public class SubClass extends SuperClass { private AnotherResource another = new AnotherResource(); public SubClass(){ super(); //Added for clarity } private void finalize() throws Throwable { another.shutdown(); } }
Since SubClass extends the SuperClass, when we create an instance of SubClass, we would also have created an instance of HeavyResource and an instance of AnotherResource. However, when this instance of SubClass is being finalized, we shutdown only the instance of AnotherResource. The shutdown method of HeavyResource would not be called.
The recommended practice for finalize methods is that in the finally block of the finalize method one should call the finalize method of the super class. (That's right, in the constructor the first statement has to be the call to super so for destructor/finalize the sequence should be reversed and super should be called last). So our SubClass would look something like:
public class SubClass extends SuperClass { private AnotherResource another = new AnotherResource(); public SubClass(){ super(); //Added for clarity } private void finalize() throws Throwable { try{ another.shutdown(); }finally{ super.finalize();//Compilation error here } } }
This would have worked, but unfortunately this won't even compile. You can not call the private method of the super class. There are couple of ways I can think of to solve this problem.
One solution of-course would be to relax our requirements and make the access modifier of the finalize method protected and hope people are sensible enough not to call it!
Another solution could be to allow calls to super.finalize(), even if the finalize method of the super class has private access modifier, in the Java Language Specification (JLS).
My preferred solution would be to have compilers automatically add a try finally block and insert a call to super.finalize() method in the finally block. (Modifying byte code to add a try finally block is a nightmare (as compared to adding a call to super()), but that's a separate discussion!) This would be similar and consistent with the way compilers add the call to super() as the first statement of a constructor if it does not already exist.
The fact that class Object declares a finalize method means that the finalize method for any class can always invoke the finalize method for its superclass. This should always be done, unless it is the programmer's intent to nullify the actions of the finalizer in the superclass. (Unlike constructors, finalizers do not automatically invoke the finalizer for the superclass; such an invocation must be coded explicitly.)
It appears this was done ``So that the programmer can nullify the actions of the finalizer in the superclass.'' But thanks to this choice, developers today use tools like PMD which warn them about empty finalize methods and when the finalize does not call the same method of the super class.
The problems that can occour with finalizers(Finalizer Rules):

If the finalize() method is empty, then it does not need to exist.
If the finalize() is implemented, it should do something besides just calling super.finalize().
Methods named finalize() should not have parameters. It is confusing and probably a bug to overload finalize(). It will not be called by the VM.
If the finalize() is implemented, its last action should be to call super.finalize().
If you override finalize(), make it protected. If you make it public, other classes may call it.
Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object.(Avoid calling finalize()).


##### How does Java deal with Multiple Inheritance?
$$$$$ Java does not support multiple inheritance, allowing a class to extend more than one base class. It does however support implementing multiple "interfaces ", which is similar to multiple inheritance but simpler and safer. Inheritance describes an IS-A relationship. Dalmatian IS-A Dog. You can also have HAS-A relationships. A Body HAS-A Leg. HAS-A relationships are implemented with embedded references to other objects. HAS-A relationships are more flexible. An object can have multiple HAS-A relationships. It can even have a variable number of them, by having a reference to an array or ArrayList of references.

##### Difference between Extends and Implements
$$$$$ When you derive a class from a base class we say the derived subclass extends the base class. An interface can also extend another interface. In contrast, when a class provides the methods (possibly abstract) necessary to conform to some interface we say that class implements the interface. Extending a class is closely related to implementing an interface. A new class can extend at most one superclass, but it may implement several interfaces.
In interface may extend several other interfaces. You sometimes do this to give you a short same to stand for the requirement implementing half a dozen related interfaces.
Extending means adding new method definitions. Implementing means satisfying the existing interface contract by writing the proscribed method bodies. Logically, when you extend an abstract class and fill in the method bodies, that should be called implementing, but in the Java world that is called extending.

##### What is the difference between POP(Procedure Oriented Programming) and OOP?
$$$$$ 1. In POP, importance is given to the sequence of things to be done and in OOP, importance is given to the data.
2. In POP, larger programs are divided into functions and in OOP, larger programs are divided into objects.
3. In POP, most functions share global data. In OOP mostly the data is private and only functions inside the object can access the data.
4. POP follows a top down approach in problem solving while OOP follows a bottom up approach.

##### Why is multiple inheritance not allowed in java?
$$$$$ By not allowing the inheritance of multiple base classes by a single subclass, Java greatly simplifies the inheritance model. Multiple inheritance carries with it several special cases that must be handled. This adds overhead to both the compiler and the run-time system, while providing only marginal benefit for the programmer.

##### Is overriding compile time or runtime polymorphism? Is overloading compile time or runtime polymorphism?
$$$$$


##### What is the Difference between sendRedirect() and Forward?
$$$$$ sendRedirect() completely transfer the control of execution to new resource whereas forward() just forwards the requests. That’s why in the next page the request is unavailable in case of sendRedirect() whereas in forward() this request is still available in the next page.

$$$$$ When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container. When a sendRedirect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward. always sends a header back to the client/browser.

$$$$$ the difference between the two is that sendRedirect always sends a header back to the client/browser. This header then contains the resource (page/servlet) which u wanted to be redirected. The browser uses this header to make another fresh request. Thus sendRedirect has a overhead as to the extra remote trip being incurred it is like any other Http request being generated by your browser. The advantage is that u can point to any resource(whether on the same domain or some other domain) e.g. if sendRedirect was called at www.mydomain.com then it can also be used to redirect a call to a resource on www.theserverside.com. Where as in case of forward() call, the above is not true, resources from the server, where the fwd., call was made, can only be requested for, but the major diff between the two is that forward just routes the request to the new resources which u specify in your forward call. that means this route is made by the servlet engine at the server level only, no headers are sent to the browser which makes this very efficient, also the request and response objects remain the same both from where the forward call was made and the resource which was called.




No comments: