Core Java Interview Questions-Set 5

What is generics in Java?

In Java, Arrays are type safe, meaning of that if we are declaring an array of int, only integers can be assigned to it, If it is a string array only strings are allowed. But for collections till Java 5 there was no type safe mechanism available. To make the collections type safe is known as making it generic type.

For example:

List someList= new ArrayList();

Above list will allow only Animal objects to be assigned to someList List.

What is a static class member?

Unlike C/C++ there is no concept of global variable in Java. But still a programmer may need a variable which will retain its value and state irrespective of the objects for a class. This can be achieved by the static class member. When a static class member is created, it can be accessed even before the object of the class is created. All the instances (objects) shares the same static variable and no more copy of the static variable is created even if a new object is created.
Methods declared static have the following properties/characteristics :
i. Static methods can only access static methods.
ii. They can only access static data
iii. Static methods can’t refer to this or super.

Posted in Core Java, Java | Leave a comment

HTML Interview Questions-Set 1

What is base tag in HTML?

When we write anchor tags we don’t use complete URL, rather we use a relative URL and never specify the domain name to decrease page size(page optimization) and coding time. But think about the scenario, where user downloaded the HTML file into his system and later tries to click the link. As there is no complete URL specified an error like “Internet Explorer cannot display the webpage ” if your browser is IE will come.

To counter such problem base tag is used. Let us take an example below.

<html>
<head>
<base href=”http://questionsforinterviews.com”></base>
</head>
<body>
<a href=”/what-is-base-tag-in-html”> What is base tag in HTML?</a>
</body>
</html>

In the above example although we have not specified domain name http://QuestionsForInterviews.com still the anchor tag will redirect to http://questionsforinterviews.com/what-is-base-tag-in-html.html

Why table should be avoided for layout of a page?

While creating a page, most of the time using table makes the creation of the page faster. But using table for the layout of a page is discouraged because of the following reasons.

1. For complex table, page will not be rendered unless all data inside the table is downloaded. For slower internet connection it might be a problem and might take considerable amount of time before even page start rendering. This makes the user feel the server to be slow.
2. Maintaining a complex page designed with table is very difficult. As to change a part of the page might need to alter the complete table or in other words complete page. Which results in poor maintainability index of the page.

What is streaming audio and video?

If a video or audio file needs to be played it was mandatory that the complete file is downloaded to the computer first. This was a big concern for the slower internet connection where downloading a small video file of few hundred MB can take hours and the user has to wait hours before even starting seeing what the video is about. To resolve this kind of situation streaming video and audio came into picture.

With streaming audio and video, user can see/listen to video/audio while data is being received. That means one might not wait for the complete download and start watching the movie or listen to a song.

In HTML when you add a media object using tag, automatically the media player installed with the browser take care of playing the streaming audio/video file.

In an website, I found a nice image. Can I use that image in my website?

There are two types of images available in the web world. First one is royalty free and another copyrighted. If the image found by you is a royalty free image and is explicitly specified by its author, you are free to use that image. But if the image is copyrighted you shouldn’t download the image and use it. In many countries the consequences are severe. Its author can drag you to the legal court.

Posted in HTML | Leave a comment

Operating System Interview Questions-Set 1

What are the advantages of multiprogramming?

Multi programming increases CPU utilization by organizing jobs so that CPU has always one task to execute. In multiuser environment if an use is using some I/O operation, if the system is non-multiprogram system CPU will sit idle where as in multiprogram system CPU will switch to a different user or a different task, there by utilizing the CPU time in the best possible way.

What are the basic purposes of an Operating System?

Operating system is the heart of any computing system. The basic purposes of any operating system are as follows.
1. Operating system makes sure to adopt a schedule algorithm so that the hardware will have the best performance possible.
2. It provides an environment for other programs to execute on the system without exposing the low level activities.

Posted in Operating System | Leave a comment

Core Java Interview Questions-Set 4

What is a final class?

Final class is a class which can’t be sub classed. Final keyword ensures, the class implementation is never overridden. Let us take one example. In java.lang the class String is a final class, It can’t be sub classed. The meaning of this the class implementation of String class shouldn’t be altered and this is achieved through final key word.

Example :
Package qfi;
Public final class QuestionsforInterviews{
.
.
.
}

What is an abstract class?

Abstract class is a java class which can’t be instantiated. The meaning of this is, an object can’t be created from an abstract class. The lone purpose to create an abstract class is to give an abstract skeleton for a class. Just imagine a class Car. It shouldn’t be instantiated as this is class with quite generic properties. But this can be sub classed to a model of a brand like BMW which will have concrete properties, like color, horse power, seating capacity and so on.

A class will be considered if the keyword abstract is used or any of the method inside the class is abstract.

Example:
Package qfi;
abstract class Car{
..
..
}

Or

Package qfi;
Class Car{
Public abstract void speed();
}

What are synchronized methods?

If a method is declared as synchronized, it can be accessed by only one thread at a time. Synchronized modifier can be used with any of the three modifiers. This type of methods are generally created to make sure that a transaction can only happen by a single thread for a single source. For example, if bank transaction like fund transfer, fund withdraw will happen by several threads at a time consistency can’t be maintained. To avoid such scenarios, the method can be declared as synchronized.

Example: public synchronized void questionForInterviews{
..
..
}

What are Transient variables?

Transient declaration of a variable restricts the variable to be serialized. It means you can’t save the state of a transient variable by serializing it.

What’s the difference between constructors and other methods?

The difference between a constructor and a method are as follows,
i. Constructors are not designed to perform any job other than initializing the object. Where as a method is created to perform a particular job or task.
ii. When we don’t create any constructor explicitly, JVM provide a default constructor to initialize the object. Where as we have to explicitly create methods of our own.
iii. Constructor has no return type, but a method has always a return type.
iv. The name of the constructor is always the name of the class, where as the name of the method depends on the programmer.

Posted in Core Java, Java | Leave a comment

Core Java Interview Questions-Set 3

What are final variables?

Final modifier restricts a variable to be reinitialized with an explicit value. For example if a final string is assigned with a value “check”, it will stay “check” forever.
The meaning of final reference variable is somewhat different. A final reference variable can’t be reinitialized with a different object, but the object to which it is referenced can be modified. There is no final object concept in Java, only the reference can be made final.

What are native methods?

Native modifier is used to implement some legacy languages like C in Java. It says the code specified inside the method with native modifier is platform dependent. Native modifier can only be applied to a method and not to a class or variable or anything else.

What are strictfp methods?

Strictfp is a modifier which forces the JVM to follow IEEE 754 standards for floating point precision. In normal floating point calculations JVM basically relies on the underlying hardware facility to decide on precision. But If a method is declared wit strictft modifier, it doesn’t rely on the underlying hardware. So it will be easy to predict the exact output of a floating point operation.

What are Instance variables?

The variables which are defined inside a class and outside of a method or block is known as instance variables. These are the fields which belong to each of the objects created out of that particular class. Whenever a class is instantiated automatically the instance variables are assigned with the default values. For example, integers are assigned with 0 and strings are assigned with null and so on. That’s the reason the instance variables need not be initialized explicitly.

What are local variables?

The variables declared inside a method are known as local variables. These are sometimes known as automatic variables or stack variables or method variables. The local variable has a life span of the method only. Outside of the method it has no existence. And it is automatically destroyed and become eligible for garbage collection once the method is destroyed.
Unlike instance variables, local variables need to be initialized before use.
For Local variables public or transient or volatile or abstract or static can’t be applied. But it can be declared as final.

Posted in Core Java, Java | Leave a comment

Core Java Interview Questions-Set 2

What is finalize() method in Java?

Before an object is destroyed, it may has to perform some necessary actions like resource release. To handle such requirements, finalize() method is used. By using this method programmer directs the JVM that it has to perform a set of operations before garbage collector destroys the object.
Finalize() method is called by garbage collector, because of this reason one can’t guarantee when exactly the resource release steps defined in the methods will run, as starting garbage collector is the responsibility of JVM and programmer can’t force it. That is the reason, it is always advisable to follow some other mechanisms too for releasing resources or doing other necessary operation immediately after the use of the same.

What is method overloading?

In java language, this is always possible to create multiple methods with the same name, which is known as method overloading. Here the methods are called overloaded methods. This is one of the example how Java implements polymorphism.

Over loaded methods may have same return type or different return type, but they must differ in parameter type or number of parameters.

What are constructors and how are they different from methods?

Initializing all the instance variable manually in a class during instancing process is a tedious process. But unless we initialize the variables, it is not possible to use it for any operation. As initialization process is mandatory, JVM provides a mechanism to initialize all the variables in a class. that automatic initialization is performed through the use of constructors.

Though constructors and methods looks same the following points makes them distinguishable.
i. Constructors have no return type.
ii. Constructors, always have the name exactly same as that of the class.
iii. Unlike methods, constructors are not designed to perform any particular task other than initialization.
iv. Constructors are called only once during the instantiation process.

What is a class and how is it different from object?

Class is the back bone of Java language. Everything in Java is based on class. Class provides logical construct on which entire Java language is based. Class is a template, and it has no role in application under process. In other words, class just declares a new data type.
Whereas object is the instance of a class and this is the one, on which all the operations happens during application execution. From a single class unlimited number of objects can be created based on the programmer’s requirement. Object is the physical reality of a class.

What are the usages of Java packages? Why is this advisable to use java packages, while developing Java applications?

i. Packages help in organizing the classes into logically similar group.
ii. Same class names can be used as far as both are in different packages, thereby decreasing the possibility of name conflict.
iii. Package access level provides a mechanism to protect data from being accessed from outside the package.

Posted in Core Java, Java | Leave a comment

Search Engine Optimization Interview Questions

Why my url doesnot appear in search engines even after days of submission?

In web world, millions s of new pages are created every day and millions of pages are changed every day. Even thousands of new domains created every day and are submitted to the search engines to start indexing. From this you can imagine how much data processing search engines do every day.

When a page is submitted through the URL submission services provided by the search engines, it usually takes few days to process the request.

Search for your direct domain name like mynewdomainname.com in the search engines and check if your site if coming. If its not, wait for few days and try to resubmit the page.

Do I need to submit all my pages to the search engines?

Answer is strict no. Search Engine optimization is not a one day process. Just submit your home page. You may create a site map for your site which is usually an XML file or an HTML file which gives information like page creation date, update frequency, priority etc to the search engine. Create an account in an webmaster service of major search engines and submit the page. You will see, search engines will automatically index all your pages in few days.

Ranking better doesn’t depend only on the pages of your website. Rather it depends on many factors, like page uniqueness, domain age, inbound links, keywords, competition etc. Doing an search engine optimization of your website will definitely help in long run.

Never follow any black hat trick. If you do, you will regret for sure.

 

Posted in SEO | Leave a comment

Core Java Interview Questions-Set 1

What is constructor chaining?

Constructor chaining is nothing but invoking the super class constructors when the current class is initialized. For example let us assume Parrot extends Bird class which interns extend Object.

When we instantiate the class Parrot as below

Parrot p = new Parrot();

below sequences of events occurs.

1. Parrot() calls Bird()
2. Bird() calls Object().

This is called constructor chaining.

What are the uses of final keyword?

In Java final keyword is used for three purposes as follows
• This used to create named constant which is not going to changed throughout its life.
• To prevent overriding. In big applications it may happen accidentally that a method is overridden accidentally. To avoid such issue, final keyword can be used to make a method to restrict overriding.
• Programmer may require to prevent the class from getting inherited. In such cases final keyword can be used. For example, if the class String is inherited and all the methods of it are overridden then the mess that will be created can be easily imagined. In such scenarios it is essential to make such classes final.

What is dynamic method dispatch?

Dynamic method dispatch comes into picture, when JVM finds a method is overridden. The call to an overridden method is resolved by a mechanism known as dynamic method dispatch.

What is method overriding?

If a subclass has a class with exact signature of that of the super class, the method is known as overriding class. If the signature of the method is not identical, the methods will be called overloaded.

What is a nested class? What are the difference between nested classes and inner classes?

Class defined inside a class is known as nested class. A nested class has access to the members of the class in which it is nested. It can even access the private members of the class in which it is nested. But the enclosing class doesn’t have access to the members of nested class.
There are two types of nested classes. One is static and the other is non-static. The non-static classes are known a sinner classes. These types of classes have access to the all the members of the enclosing class. But the inner class is never known to the out side world of the enclosing class. Nested classes are seldom used in normal Java programming. But especially they are useful in building applets.

Posted in Core Java, Java | Leave a comment

What are entities, attributes and relationship in databases?

Posted in Database | 1 Comment

What is a Data Model?

Posted in Database | 1 Comment