Saturday 16 March 2013

What is an Object and how do you allocate memory to it?


What is an Object and how do you allocate memory to it?
Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. An object is created using new operator, memory is allocated to it.

Blog Author: Vijay Kumar



What is the difference between constructor and method?


What is the difference between constructor and method?
Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

Blog Author: Vijay Kumar



What are methods and how are they defined?


What are methods and how are they defined?
 -  Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.

Blog Author: Vijay Kumar



What is the use of bin and lib in JDK?


What is the use of bin and lib in JDK?
 -  Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

Blog Author: Vijay Kumar



What is casting?


What is casting?
 -  Casting is used to convert the value of one type to another.

Blog Author: Vijay Kumar



How many ways can an argument be passed to a subroutine and explain them?


How many ways can an argument be passed to a subroutine and explain them?
 -  An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.

Blog Author: Vijay Kumar



What are different types of access modifiers?


What are different types of access modifiers?
 -  public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and sub classes in the other packages. default modifier : Can be accessed only to classes in the same package.

Blog Author: Vijay Kumar



What are Class, Constructor and Primitive data types?


What are Class, Constructor and Primitive data types?
 -  Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, Boolean, char.

Blog Author: Vijay Kumar



What is the difference between Assignment and Initialization?


What is the difference between Assignment and Initialization? 
Assignment can be done as many times as desired whereas initialization can be done only once.

Blog Author: Vijay Kumar



What is the difference between procedural and object-oriented programs?


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 within the object and which in turn assures the security of the code.

Blog Author: Vijay Kumar



What are the various ways of creating a thread. What is difference between them?

What are the various ways of creating a thread. What is difference between them? 
1> Implementing Runnable interface.
2>Extending
 Thread class.

First case we have to override run method of the interface. Also if we want to inherit any other class in our thread then first case is appropriate and useful option, because with the second case we can’t inherit any other class.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What are the various access modifiers in Java. Difference between them?

What are the various access modifiers in Java. Differences between them? 
transient, final, static

transient for variable:-- variable's state can't be serialized.

final :-- can be
 declared for class, METHODS as well as variables, who's definition can't be changed.

static :-- variable & methods can be
 declared as static means it has only one copy for all the objects & it's exist only in class level



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between static and non-static variables?

What is the difference between static and non-static variables? 
Static variable is a variable ,which is not repeated to each and every object .It is shared by all objects .It is also known as Class variable.Static methods only access the static variable.By default static variables are initialized to zero.

Non-static variable ,which is repeated to each and every object.
 



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between yielding and sleeping?

What is the difference between yielding and sleeping? 
In yielding the thread permits another thread which is waiting in queue to use CPU time ( i.e execute ) while the current thread goes to the back of the queue ( i.e in a round robin fashion ).

In sleeping the thread suspends its activity itself by calling the sleep method. This thread can be made active again by using notify() or notifyAll() methods.

The major problem with the sleep() approach is that it completely depends on external threads to "Awaken" it. Such an arrangement is dead-lock prone and kind of very tough to debug and so it is generally avoided.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between InputStream/Outputstream classes?


What is the difference between InputStream/Outputstream classes? 
InputStream and its sub classes are used for reading data inthe form of streams.

Ex : FileInputStream, DataInputStream

OutputStream and its sub classes are used for writing data inthe form
 of streams.

Ex: FileOutputStream, DataOutputStream


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between Reader/Writer classes?

What is the difference between Reader/Writer classes? 
The Reader/Writer class is character-oriented. 
READER: reads and returns
 the next char from the stream.
WRITER: writes a character / string to the stream.

Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between HashMap and TreeMap?


What is the difference between HashMap and TreeMap? 
Both Hashmap and Treemap are data structures, which holds the values of in the form of key -value pairs. But difference is, hashmap is a unordered data structure, treemap is ordered data structure. Both does not allow duplicate values.


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between applet and application?

What is the difference between applet and application? 
Difference b/w Applet and Application:

Applet
 :
1.Applet
 is a small java program,which is executed in the special browser.
2.Applet
 should not contain main () method.
3.Applet
 travel in the internet.

Application:

1.
 Application is executed in the JVM.
2.It contains main () method.

Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between Iterator and Enumeration?

What is the difference between Iterator and Enumeration? 
Enumeration and Iterator both are interfaces present in util package. Enumeration is a legacy interface which does not come under the collection framework, wheras Iterator is an interface present in the collection framework. All the legacy classes like Stack, Vector , Hashtable, Properties can use Enumeration for enumerating the elements from the collection. The classes under the collection framework like ArrayList, LinkedList, HashSet ,Tree Set etc can use the Iterator interface.

Iterator actually adds one method that Enumeration doesn't has: remove().



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between Classpath and Import?

What is the difference between Classpath and Import? 
Classpath: Class path is a system variable. It is a collection of files in the directories.Normally classpath will be used by Java interpreter to exucute the class files(.class).

Import :Import is a keyword. It is used to getting the required files into the program without writing the hard code.
eg. import java.io.*;


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions