100000380
Points
Questions
185
Answers
186
-
Threads in Java can be created in two ways:
- By inheriting from Thread class (extends Thread)
- By implementing Runnable interface (implements Runnable)
Implementing Runnable interface is preferred over extending Thread class because implementing Runnable interface allows to extend from other class and also implement Runnable interface. The Thread class itself implements Runnable interface.
By extending Thread class, each of your threads has a unique object associated with it, whereas by implementing Runnable, many threads can share the same object instance.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1457 views
- 1 answers
- 0 votes
-
In Java, finalize() method is called by the garbage collector before reclaiming the memory allocated to the object. A class overrides the finalize() method to dispose of system resources or to perform other cleanup. However the usage of finalize() method is not recommended because the execution of finalize() method is not guaranteed and there is a severe impact on performance.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1232 views
- 1 answers
- 0 votes
-
The enhanced for-loop is a popular feature introduced with the Java SE platform in version 5.0. Its simple structure allows one to simplify code by presenting for-loops that visit each element of an array/collection without explicitly expressing how one goes from element to element.
For example, the standard for loop steps through an array as
for (int index = 0; index < myArray.length; index++) { System.out.println(myArray[index]); }
The so-called enhanced for loop is a simpler way to do this same thing hiding the index, also referred as for-each loop.
for (int myValue : myArray) { System.out.println(myValue); }
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1212 views
- 1 answers
- 0 votes
-
StringBuffer is a thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. String buffers are safe for use by multiple threads since the methods are synchronized.
StringBuilder is also a mutable sequence of characters introduced in Java 5, but not synchronized. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). It is recommended that StringBuilder be used in preference to StringBuffer as it will be faster under most implementations.
Note: Never manipulate Strings inside loops, as it would create as many objects as the loop goes on.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1292 views
- 1 answers
- 0 votes
-
In Java, two objects can be compared using the equals() method and == operator.
== operator is used to check if the references to two objects are same i.e. they point to the same location in memory.
The equals() method is used to check if the two objects have the same contents (same values in attributes).The default equals() implementation is provided in the Object class and its behavior is exactly the same as the == operator. A programmer is expected to override the equals() method and compare object contents to get the desired behavior. Another point to be noted is that hashCode() and equals() method should always be overridden together.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1256 views
- 1 answers
- 0 votes
-
UDDI stands for Universal Description, Discovery, and Integration. UDDI is an industry initiative which aims to enable businesses to quickly, easily, and dynamically find and carry out transactions with one another. A UDDI registry contains cataloged information about businesses; the services that they offer; and communication standards and interfaces they use to conduct transactions. A UDDI registry provides a standards-based foundation infrastructure for locating services, invoking services, and managing metadata about services (security, transport, or quality of service).
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1431 views
- 1 answers
- 1 votes