Friday 15 March 2013

What is the difference between scrollbar and scrollpane?


What is the difference between scrollbar and scrollpane? -  A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is a layout manager?


What is a layout manager and what are different types of layout managers available in java AWT? -  A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

How are the elements of different layouts organized?


How are the elements of different layouts organized? -  FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards. GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

Which containers use a Border layout as their default layout?

Which containers use a Border layout as their default layout? -  Window, Frame and Dialog classes use a BorderLayout as their layout.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

Which containers use a Flow layout as their default layout?

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


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What are Vector, Hashtable, LinkedList and Enumeration?

What are Vector, Hashtable, LinkedList and Enumeration? -  Vector : The Vector class provides the capability to implement a growable array of objects. Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects. LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations. Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this enumeration has more elements and nextElement method returns successive elements of the series.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between TCP/IP and UDP?

What is the difference between TCP/IP and UDP? -  TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call. UDP is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is Inet address?

What is Inet address? -  Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is Domain Naming Service(DNS)?

What is Domain Naming Service(DNS)?
It is very difficult to remember a set of numbers(IP address) to connect to the Internet. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, www. mascom. com implies com is the domain name reserved for US commercial sites, moscom is the name of the company and www is the name of the specific computer, which is mascom’s server.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions


What is URL?

What is URL?  
URL stands for Uniform Resource Locator and it points to resource files on the Internet. URL has four components: http://www. address. com:80/index.html, where http - protocol name, address - IP address or host name, 80 - port number and index.html - file path.
Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What do you mean by platform independence?


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



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between String and StringBuffer?

What is the difference between String and StringBuffer? 
String: String is a immutable class. You can't modify it.
StringBuffer: StringBuffer is a
 mutable class .You can modify it.


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

controversy on java final keyword:


controversy on java final keyword:

‘final’ should not be called as constants. Because when an array is declared as final, the state of the object stored in the array can be modified. You need to make it immutable in order not to allow modifications.  In general context constants will not allow to modify. In C++, an array declared as const will not allow the above scenario but java allows. So java’s final is not the general constant used across in computer languages.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

Java Final Keyword

  • A java variable can be declared using the keyword final. Then the final variable can be assigned only once.
  • A variable that is declared as final and not initialized is called a blank final variable. A blank final variable forces the constructors to initialize it.
  • Java classes declared as final cannot be extended. Restricting inheritance!
  • Methods declared as final cannot be overridden. In methods private is equal to final, but in variables it is not.
  • final parameters – values of the parameters cannot be changed after initialization. Do a small java exercise to find out the implications of final parameters in method overriding.
  • Java local classes can only reference local variables and parameters that are declared as final.
  • A visible advantage of declaring a java variable as static final is, the compiled java class results in faster performance.

Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between final, finally and finalized?

What is the difference between final, finally and finalized? 
"final" is a modifier in java. You can use "final" key word for classes, methods and variables. final variable can be assigned only once.
"finally" ,it is a block in exception handling, whatever u write in that block that would be executed 100% irrespective of the exception.
"finalize()" This is a method called by the garbage collector before reclaims the memory of an object.

Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between Vector, Array and Arraylist?

What is the difference between Vector, Array and Arraylist? 
1. ArrayList is not synchronized whereas the Vector is synchronized.

2. Arraylist is faster whereas Vector is slower in processing.

3. Elements in the arraylist can be traversed using iterator interface whereas in the case of Vector we can traverse using the Enumeration interface
1. Vector and Arraylist are grownable or shinkable where array is not. 
2. Vector and Arraylist are implemented from List interface where as array is a primitive data type
 
3. Vector is Synchronized where as arraylist is not
 
4. For best
 performance better to use arraylist than vector. 



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between Hashmap and Hashtable?

What is the difference between Hashmap and Hashtable? 
All the methods in HashTable are synchronized whereas HashMap is not thread-safe.

Another big
 difference is that HashMap allows null key and null values whereas HashTable does not permit null key and null values.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between overloading and overriding?

What is the difference between overloading and overriding? 
Overloading: Overloading is nothing but passing the different parameters to the method. Here method name is same but parameters are different.

Overriding: Overriding is nothing but giving the implementation to the method in the derived class. Here method signature is same.



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the difference between Abstract class and Interface?

What is the difference between Abstract class and Interface? 
Abstract class: Abstract class can contain abstract methods and concreat methods (implementation methods) (normal methods). 

Interface : An Interface contains only abstract methods(not concreat methods).



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is the functionality of try, catch and finally blocks?

What is the functionality of try, catch and finally blocks? 
In the context of "exception handling" "try", "catch", "finally", "throw" and" throws" plays an analogous role in the java programming language.

"try": This block will throw an exception.
"catch": This block will catch an exception that is raised in the "try" block.
"finally": This block will be execute irrespective of the exception.


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions


What is the purpose of finalisation?

What is the purpose of finalisation? 

Finalization was meant to clean up resources acquired by the object 
(not memory, but other resources, e.g. file handles, ports, DB connections etc.). 

Finalization is a facility provided by Java for classes who
use native resources to clean up before the objects are
garbage collected.

Since native resources or allocations are beyond the control
of Java's garbage collector, the responsibility of cleaning
up that native allocations falls on the object's
finalization code which should ideally initiate quick clean up
operations and free any native memory it has allocated.

If finalization is not done, then the native resources would
be left in the memory even after thier related Java
instances have been removed by the Java's GC. Hence it is an
invaluable feature. The garbage collector is working automatically in the 
background (although it can be explicitly invoked, but the need for this should be rare).

But it needs to be used with caution as finalization
consumes more processing by Java



Blog Author: Vijay Kumar

Go to: Coding Problem Solutions


What is the life cycle of an applet?

What is the life cycle of an applet? 
Applet life cycle:

An
 Applet is a small java program,which is executed in the special browser(like appletviewer). The life cycle of an applet is as follows:

1.init();
2.start();
3,stop();
4.destroy();

The init(),and destroy() methods called only once. but stop (),and start() methods called many times.


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is Serialization and Deserialization?

What is Serialization and Deserialization? 
Serialization : It is the process of storing the object state as permanently.

Deserialization: It is the process of retriving the object state (or) fetching the object state.
Serialization is also called Marshalling.
Deserialization is also called UnMarshalling.
Marshalling comes into picture when an object is being transferred from one location to other over wire. On the other end of wire, UnMarshalling takes place.


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is JavaMail?

What is JavaMail? 
The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications.


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is Synchronisation in threads?

What is Synchronisation in threads? 
Synchronisation in threads is the way of executing threads in an order. Threads , in general, execute in random order. On synchronisation, these threads execute in the order in which they are created.

Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is garbage collection?

What is garbage collection? 
Garbage collector: Whenever an object is no longer used in the program, Java reclaims the memory of that object. It is performed by the Java implicitly, no need to care of it. Finalize() will be called before sweeps the memory of an object by java. Java does not support destructor, so we will use Garbage collector in the place of destructor.
Garbage Collector :Whenever an object is no longer needed in the java program. Java provides the machenisam for free-up memory space taken by objects. This is known as garbage collection.


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is JAR file?

What is JAR file? 
JAR file stands for Java ARchive, a compressed file like zip, rar, lha files.
Using the jar
 command, a JAR file is commonly used for packaging Java classes (.class).
JAR is an acronym for Java Archive. It is nothing but a compressed form of a group of class files.

For Example if you have your packages and class files in C:javaprgs

Then from the windows
 command prompt one can jar the files in javaprgs using the following command

C:javaprgs> jar ?cvfM jar-file-name.jar *.*

We also hav WAR n EAR files. 

WAR is acronynm for Web
 Archive

EAR is acronynm for Enterprise Archive.


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is JNI?

What is JNI? 
The JNI is used to write native methods to handle situations when an application cannot be written entirely in the Java programming language such as when the standard Java class library does not support the platform - dependent features or program library. It is also used to modify an existing application, written in another programming language, to be accessible to Java applications.

The JNI is for programmers who must take advantage of platform - specific functionality outside of the Java Virtual Machine. Because of this, it is recommended that only experienced programmers should attempt to write native methods or use the Invocation API!


Blog Author: Vijay Kumar

Go to: Coding Problem Solutions

What is JVM?


What is JVM? 
JVM (Java Virtual Machine) is a platform - independent execution environment that converts Java bytecode into machine language and executes it.
JVM - Java Virtual Machine.

JVM consist of following components:-

1) Byte-code
 verifier: - It verify the byte-code ,it check's for unusual code.

2) Class Loader: - After verifying Class Loader will load the byte-code into the memory for execution.

3) Execution engine: -
It further consists of
 2 parts :-
a) Interpreter: - It interprets
 the code & run.
b) JIT (Just-in-Time Interpreter)
JVM Hotspot defines when to use Interpreter or JIT.

4) Garbage Collector: - It periodically check for the object on heap , whose link is broken
 
So it can collect the garbage from Heap.

5) Security Manager: - It constantly monitors
 the code. It is 2nd level of security.[1st level is Byte-code verifier ].
JVM stands for Java Virtual Machine. As the name indicates, it does not a real hardware machine but a software layer which resembles a hardware platform. JVM helps to run java programs on different Operating system platforms. The JVM will be different for different Operating Systems i.e. there will be separate JVM for Windows and Linux. Now I am going to explain how Java achieves platform independents with the help of JVM. We can write the java program on any platform. The source program is then converted to byte code using a Java compiler. The compiler will be different for different platforms. The byte code can be executed on any platform where there exist JVM.

Blog Author: Vijay Kumar

Go to: Coding Problem Solutions