OOPs Java Basic Interview Questions and answers
1. What is a virtual function in C++?
Simply put, the virtual keyword enables a function to be ‘virtual’ which then gives possibility for that function to be overridden (redefined) in one or more descendant classes. It is a good feature since the specific function to call is determined at run-time. In other words, a virtual function allows derived classes to replace the implementation provided by the base class.
2. What is the difference between private, protected, and public?
These keywords are for allowing privilages to components such as functions and variables.
Public: accessible to all classes
Private: accessible only to the class to which they belong
Protected: accessible to the class to which they belong and any subclasses.
3. What is a cartesian product in PL/SQL?
When a Join condition is not specified by the programmer or is invalid(fails), PL/SQL forms a Cartesian product.
In a Cartesian product, all combinations of rows will be displayed.
For example, All rows in the first table are joined to all rows in the second table. It joins a bunch of rows and it’s result is rarely useful unless you have a need to combine all rows from all tables.
4. What is mutual exclusion? How can you take care of mutual exclusion using Java threads?
Mutual exclusion is where no two processes can access critical regions of memory at the same time.
Java provides many utilities to deal with mutual exclusion with the use of threaded programming.
For mutual exclusion, you can simply use the synchronized keyword and explicitly or implicitly provide an Object, any Object, to synchronize on.
The runtime system/Java compiler takes care of the gruesome details for you. The synchronized keyword can be applied to a class, to a method, or to a block of code. There are several methods in Java used for communicating mutually exclusive threads such as wait( ), notify( ), or notifyAll( ). For example, the notifyAll( ) method wakes up all threads that are in the wait list of an object.
5. What are some advantages and disadvantages of Java Sockets?
Some advantages of Java Sockets:
* Sockets are flexible and sufficient. Efficient socket based programming can be easily implemented for general communications.
* Sockets cause low network traffic. Unlike HTML forms and CGI scripts that generate and transfer whole web pages for each new request, Java applets can send only necessary updated information.
Some disadvantages of Java Sockets:
* Security restrictions are sometimes overbearing because a Java applet running in a Web browser is only able to establish connections to the machine where it came from, and to nowhere else on the network
* Despite all of the useful and helpful Java features, Socket based communications allows only to send packets of raw data between applications. Both the client-side and server-side have to provide mechanisms to make the data useful in any way.
* Since the data formats and protocols remain application specific, the re-use of socket based implementations is limited.