November 9, 2018

Sreekanth B

Hexacta Most Frequently Asked Core Java Interview Questions Answers

Why Are There No Global Variables In Java?

Global variables are considered bad form for a variety of reasons: Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables), State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state, When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, Java decided to ban global variables.

Whats The Difference Between Notify() And Notifyall()?

notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a “writer” lock on a file might permit all “readers” to resume).

How Can My Application Get To Know When A Httpsession Is Removed?

Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method. Create an instance of that class and put that instance in HttpSession.

What Interface Must An Object Implement Before It Can Be Written To A Stream As An Object?

An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

What Is Your Platform's Default Character Encoding?

If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1.
Hexacta Most Frequently Asked Core Java Interview Questions Answers
Hexacta Most Frequently Asked Core Java Interview Questions Answers

What 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 is passed from one stream to another.

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.

Which Class Should You Use To Obtain Design Information About An Object?

The Class class is used to obtain information about an object’s design.

What Is The Purpose Of The System Class?

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

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 Servlet Context.

How Can A Servlet Refresh Automatically If Some New Data Has Entered The Database?

You can use a client-side Refresh or Server Push.

The Code In A Finally Clause Will Never Fail To Execute, Right?

Using System.exit(1); in try block will not allow finally code to execute.

How Many Messaging Models Do Jms Provide For And What Are They?

JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing.

What Information Is Needed To Create A Tcp Socket?

The Local System?s IP Address and Port Number. And the Remote System’s IPAddress and Port Number.

What Class.forname Will Do While Loading Drivers?

It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.

How Many Jsp Scripting Elements Are There And What Are They?

There are three scripting language elements: declarations, scriptlets, expressions.

What Are Stored Procedures? How Is It Useful?

A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements everytime a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases.

How Do I Include Static Files Within A Jsp Page?

Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.

Why Does Jcomponent Have Add() And Remove() Methods But Component Does Not?

Because JComponent is a subclass of Container, and can contain other components and jcomponents.

How Can I Implement A Thread-safe Jsp Page?

You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

What Is The Difference Between Procedural And Object-oriented Programs?

a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code.
b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.

What Are Encapsulation, Inheritance And Polymorphism?

Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse.

Inheritance is the process by which one object acquires the properties of another object.

Polymorphism is the feature that allows one interface to be used for general class actions.

Subscribe to get more Posts :