Showing posts with label interview questions. Show all posts
Showing posts with label interview questions. Show all posts

April 30, 2013

Core Java Interview Questions And Answers


Question: What is a Session?
Answer: A Session refers to all the request that a single client makes to a server. A session is specific to the user and for each user a new session is created to track all the request from that user. Every user has a separate session and separate session variable is associated with that session. In case of web applications the default time-out value for session variable is 20 minutes, which can be changed as per the requirement.


Question: What is Session ID?
Answer: A session ID is an unique identification string usually a long, random and alpha-numeric string, that is transmitted between the client and the server. Session IDs are usually stored in the cookies, URLs (in case url rewriting) and hidden fields of Web pages. 


Question: What is Session Tracking?
Answer: HTTP is stateless protocol and it does not maintain the client state. But there exist a mechanism called "Session Tracking" which helps the servers to maintain the state to track the series of requests from the same user across some period of time. 


 Question: What  are different types of Session Tracking? 
 Answer: Mechanism for Session Tracking are:
               a) Cookies
               b) URL rewriting
               c) Hidden form fields
               d) SSL Sessions


 Question: What is HTTPSession Class? 
 Answer: HTTPSession Class provides a way to identify a user across across multiple request. The servlet container uses HttpSession interface to create a session between an HTTP client and an HTTP server. The session lives only for a specified time period, across more than one connection or page request from the user.

April 29, 2013

C, C++ Interview Questions And Answers

In C++, what is the difference between method overloading and method overriding?
Ans- Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.


What methods can be overridden in Java?  
Ans-  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.


In C, what is the difference between a static variable and global variable?
Ans- A static variable declared outside of any function is accessible only to all the functions defined in the same file (as the static variable). However, a global variable can be accessed by any function (including the ones from different files).


In C, why is the void pointer useful? When would you use it? 
Ans- The void pointer is useful becuase it is a generic pointer that any pointer can be cast into and back again without loss of information.


What are the defining traits of an object-oriented language? 
Ans- The defining traits of an object-oriented langauge are:
           encapsulation
            inheritance 
            polymorphism     

Core Java Interview Questions And Answers

What do you mean by platform independence?
ANS- Platform independence means that we can write and compile the java code in one platform (eg- Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).


What is a JVM?
ANS- JVM is Java Virtual Machine which is a run time environment for the compiled java class files.


Are JVM's platform independent? 
ANS- JVM's are not platform independent. JVM's are platform specific run time implementation
provided by the vendor.


What is the difference between a JDK and a JVM? 
ANS- JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM


What is a pointer and does Java support pointers?
ANS- Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.

C/C++ Programming interview questions and answers

What is the difference between a pointer and a reference? Ans- A reference must always refer to some object and, therefore, must always be initialized; pointers do not have such restrictions. A pointer can be reassigned to point to different objects while a reference always refers to an object with which it was initialized.


How are prefix and postfix versions of operator++() differentiated?
Ans- The postfix version of operator++() has a
dummy parameter of type int. The prefix version does not have dummy parameter.


What is name mangling in C++??
Ans- The process of encoding the parameter types with the function/method name into a unique name is called name mangling. The inverse process is called demangling.
For example Foo::bar(int, long) const is mangled as `bar__C3Fooil'.
For a constructor, the method name is left out. That is Foo::Foo(int, long) const is mangled as `__C3Fooil'.


What is the difference between const char *myPointer and char *const myPointer?
Ans- Const char *myPointer is a non constant pointer to constant data; while char *const myPointer is a constant pointer to non constant data.


How can I handle a constructor that fails?
Ans- throw an exception. Constructors don't have a return type, so it's not possible to use return codes. The best way to signal constructor failure is therefore to throw an exception.

C/C++ Programming interview questions and answers

Can you think of a situation where your program would crash without reaching the breakpoint which you set at the beginning of main()?
Ans- C++ allows for dynamic initialization of global variables before main() is invoked. It is possible that initialization of global will invoke some function. If this function crashes the crash will occur before main() is entered.



Name two cases where you MUST use initialization list as opposed to assignment in constructors.
Ans- Both non-static const data members and reference data members cannot be assigned values; instead, you should use initialization list to initialize them.



Can you overload a function based only on whether a parameter is a value or a reference?
Ans- No. Passing by value and by reference looks identical to the caller.



What are the differences between a C++ struct and C++ class?
Ans- The default member and base class access specifiers are different.
The C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base class inheritance, and a class defaults to the private access specifier and private base class inheritance.



What does extern "C" int func(int *, Foo) accomplish?
Ans- It will turn off "name mangling" for func so that one can link to code compiled by a C compiler.



How do you access the static member of a class?
Ans- <ClassName>::<StaticMemberName>

C/C++ Programming interview questions and answers

What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
Ans- Multiple Inheritance is the process whereby a child can be derived from more than one parent class. The advantage of multiple inheritance is that it allows a class to inherit the functionality of more than one base class thus allowing for modeling of complex relationships. The disadvantage of multiple inheritance is that it can lead to a lot of confusion(ambiguity) when two base classes implement a method with the same name.


What are the access privileges in C++? What is the default access level?
Ans- The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and it's sub-classes. Public members of a class can be accessed by anyone.



What is a nested class? Why can it be useful?
Ans- A nested class is a class enclosed within the scope of another class. For example:
  //  Example 1: Nested class
  //
  class OuterClass
  {
    class NestedClass
    {
      // ...
    };
    // ...
  };
Nested classes are useful for organizing code and controlling access and dependencies. Nested classes obey access rules just like other parts of a class do; so, in Example 1, if NestedClass is public then any code can name it as OuterClass::NestedClass. Often nested classes contain private implementation details, and are therefore made private; in Example 1, if NestedClass is private, then only OuterClass's members and friends can use NestedClass.
When you instantiate as outer class, it won't instantiate inside class.





What is a local class? Why can it be useful?
Ans- local class is a class defined within the scope of a function -- any function, whether a member function or a free function. For example:
  //  Example 2: Local class
  //
  int f()
  {
    class LocalClass
    {
      // ...
    };
    // ...
  };
Like nested classes, local classes can be a useful tool for managing code dependencies.



Can a copy constructor accept an object of the same class as parameter, instead of reference of the object? 
Ans- No. It is specified in the definition of the copy constructor itself. It should generate an error if a programmer specifies a copy constructor with a first argument that is an object and not a reference.

C/C++ Programming interview questions and answers

What is a container class? What are the types of container classes?
Ans- A container class is a class that is used to hold objects in memory or external storage. A container class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the
container is called a homogeneous container.


What is inline function?? 
Ans- The __inline keyword tells the compiler to substitute the code within the function definition for every instance of a function call. However, substitution occurs only at the compiler's discretion. For example, the compiler does not inline a function if its address is taken or if it is too large to inline. 


What is overloading??
Ans- With the C++ language, you can overload functions and operators. Overloading is the practice of supplying more than one definition for a given function name in the same scope.
- Any two functions in a set of overloaded functions must have different argument lists.
- Overloading functions with argument lists of the same types, based on return type alone, is an error.


What is Overriding?
Ans- To override a method, a subclass of the class that originally declared the method must declare a method with the same name, return type (or a subclass of that return type), and same parameter list.
The definition of the method overriding is:
· Must have same method name.
· Must have same data type.
· Must have same argument list.
Overriding a method means that replacing a method functionality in child class. To imply overriding functionality we need parent and child classes. In the child class you define the same method signature as one defined in the parent class.


What is "this" pointer?
Ans- The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.
When a nonstatic member function is called for an object, the address of the object is passed as a hidden argument to the function. For example, the following function call
myDate.setMonth( 3 );
can be interpreted this way:
setMonth( &myDate, 3 );
The object's address is available from within the member function as the this pointer. It is legal, though unnecessary, to use the this pointer when referring to members of the class.

C/C++ Programming interview questions and answers

What is Memory alignment??
Ans- The term alignment primarily means the tendency of an address pointer value to be a multiple of some power of two. So a pointer with two byte alignment has a zero in the least significant bit. And a pointer with four byte alignment has a zero in both the two least significant bits. And so on. More alignment means a longer sequence of zero bits in the lowest bits of a pointer.


What problem does the namespace feature solve?
Ans- Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library's external declarations with a unique namespace that eliminates the potential for those collisions.
namespace [identifier] { namespace-body }
A namespace declaration identifies and assigns a name to a declarative region.
The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.


What is the use of 'using' declaration?
Ans- A using declaration makes it possible to use a name from a namespace without the scope operator.


What is an Iterator class?
Ans- A class that is used to traverse through the objects maintained by a container class. There are five categories of iterators: input iterators, output iterators, forward iterators, bidirectional iterators, random access. An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class. Something like a pointer.


What is a dangling pointer?
Ans- A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed.

C/C++ Programming interview questions and answers

What is default constructor?
Ans- Constructor with no arguments or all the arguments has default values.


What is copy constructor?
Ans- Constructor which initializes the it's object member variables ( by shallow copying) with another object of the same class. If you don't implement one in your class then compiler implements one for you.
for example:
Boo Obj1(10); // calling Boo constructor
Boo Obj2(Obj1); // calling boo copy constructor
Boo Obj2 = Obj1;// calling boo copy constructor


When are copy constructors called?
Ans- Copy constructors are called in following cases:
a) when a function returns an object of that class by value
b) when the object of that class is passed by value as an argument to a function
c) when you construct an object based on another object of the same class
d) When compiler generates a temporary object



What is assignment operator?
Ans- Default assignment operator handles assigning one object to another of the same class. Member to member copy (shallow copy)



What are all the implicit member functions of the class? Or what are all the functions which compiler implements for us if we don't define one.??
Ans- default ctor
copy ctor
assignment operator
default destructor
address operator

C/C++ Programming interview questions and answers

What is encapsulation??

Ans- Containing and hiding information about an object, such as internal data structures and code. Encapsulation isolates the internal complexity of an object's operation from the rest of the application. For example, a client component asking for net revenue from a business object need not know the data's origin.




What is inheritance?
Ans- Inheritance allows one class to reuse the state and behavior of another class. The derived class inherits the properties and method implementations of the base class and extends it by overriding methods and adding additional properties and methods.



What is Polymorphism??
Ans- Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
You can use implementation inheritance to achieve polymorphism in languages such as C++ and Java.
Base class object's pointer can invoke methods in derived class objects.
You can also achieve polymorphism in C++ by function overloading and operator overloading.



What is constructor or ctor?
Ans- Constructor creates an object and initializes it. It also creates vtable for virtual functions. It is different from other methods in a class.




What is destructor?
Ans- Destructor usually deletes any extra resources allocated by the object.

April 28, 2013

Core Java Interview Questions And Answers

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

What is a local, member and a class variable?
Ans- 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.

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

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

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

Core Java Interview Questions And Answers

What state does a thread enter when it terminates its processing?
Ans- When a thread terminates its processing, it enters the dead state.


What is the Collections API?
Ans- The Collections API is a set of classes and interfaces that support operations on collections of objects.


Which characters may be used as the second character of an identifier, but not as the first character of an identifier?
Ans- 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 is the List interface?
Ans- The List interface provides support for ordered collections of objects.


How does Java handle integer overflows and underflows?
Ans- It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

Core Java Interview Questions And Answers

What is synchronization and why is it important?
Ans- 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? 
Ans- The null value is not a keyword.


What is the preferred size of a component? 
Ans- The preferred size of a component is the minimum component size that will allow the component to display normally.


What method is used to specify a container's layout? 
Ans- The setLayout() method is used to specify a container's layout.


Which containers use a FlowLayout as their default layout? 
Ans- The Panel and Applet classes use the FlowLayout as their default layout.

Core Java Interview Questions And Answers

Que- What is a transient variable?
Ans- A transient variable is a variable that may not be serialized.


Que- Which containers use a border Layout as their default layout?
Ans- The window, Frame and Dialog classes use a border layout as their default layout.


Que- Why do threads block on I/O?
                                                                                       Ans- Threads block on i/o (that is enters the
waiting state) so that other threads may execute while the i/o Operation is performed.


Que- How are Observer and Observable used?
Ans- Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.


Que- Can a lock be acquired on a class?
Ans- Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.

CORE JAVA INTERVIEW QUESTIONS AND ANSWERS

QUE- What is difference between Path and Classpath?
ANS- Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.


QUE- What is the base class of all classes?
ANS- Java.lang.Object


QUE- Does Java support multiple inheritance?
ANS- Java doesn't support multiple inheritance.

QUE- Is Java a pure object oriented language?
ANS- Java uses primitive data types and hence is not a pure object oriented language.


QUE- Are arrays primitive data types?
ANS- In Java, Arrays are objects. 


QUE- What are local variables? 
ANS- Local variables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.
  • Blogger news

    This Blog Contains All Topics Related To Internet, Website Help, Interview Questions, News, Results From Various Resources, Visit Daily For More Interesting And Famous Topics.
  • Random Post

  • About

    We Provide All Information Which you Needed. We Maintain This Blog Very Carefully, If You Find Any Mistake or Any Suggestions Then Please Let Us Know, You Can Contact Us By Comments, On FB Page Or On Google+ Page. ~ Thank You