- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2620 Articles for Java
11K+ Views
Yes, we can write a return statement of the method in catch and finally block. There is a situation where a method will have a return type and we can return some value at any part of the method based on the conditions. If we return a value in the catch block and we can return a value at the end of the method, the code will execute successfully. If we return a value in the catch block and we can write a statement at the end of the method after return a value, the code will not execute so it became unreachable ... Read More
24K+ Views
Yes, It is possible to have a try block without a catch block by using a final block. As we know, a final block will always execute even there is an exception occurred in a try block, except System.exit() it will execute always. Example 1 public class TryBlockWithoutCatch { public static void main(String[] args) { try { System.out.println("Try Block"); } finally { System.out.println("Finally Block"); } } } Output Try Block Finally Block A ... Read More
559 Views
Both an Exception class and an Error class are subclasses of java.lang.Throwable class, we can able to handle the exceptions at runtime but the errors we cannot handle.Exceptions are the objects representing the logical errors that occur at the run time and makes JVM enters into the state of "ambiguity".The objects which are automatically created by the JVM for representing these run time errors are known as an Exception. An Error is a subclass of Throwable class that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.If an exception occurs we ... Read More
406 Views
No, Java does not support multi-dimensional arrays.Java supports arrays of arrays.In Java, a two-dimensional array is nothing but, an array of one-dimensional arrays. int[][] arr = new int[2][4];The expression arr[i] selects the one-dimensional array and the expression arr[i][j] selects the element from that array.Array indices in each dimension range from zero to "length". Where length is the array length in the given dimension. There is no array assignment operator. The number of dimensions and the size of each dimension is fixed once the array has been allocated.
191 Views
The String class objects are immutable whereas the StringBuffer and the StringBuilder objects are mutable.A StringBuffer is synchronized while a StringBuilder is not synchronized.A Concatenation operator "+" is internally implemented using either StringBuffer or StringBuilder.If the Object value is not going to change use String Class because a String object is immutable.If the Object value can change and will only be accessed from a single thread, use a StringBuilder because StringBuilder is unsynchronized.If the Object value can change and will be modified by multiple threads, use a StringBuffer because StringBuffer is synchronized.
690 Views
A StringBuffer is a thread-safe, mutable sequence of characters.Unlike a String class (immutable), the StringBuffer class is mutable. That is, we can change the contents of a StringBuffer object.When we modify a string of StringBuffer class, we are not creating a new String object, but rather operating directly on the original string itself.For this reason, the StringBuffer class offers a different set of methods than the String class, all of which operate directly on the buffer that contains the string. A StringBuffer can be defined simply by the use of the new operator and bypassing the string value inside a ... Read More
4K+ Views
Heap MemoryThe heap memory is a run time data area from which the memory for all java class instances and arrays is allocated.The heap is created when the JVM starts up and may increase or decrease in size while the application runs.The size of the heap can be specified using –Xms VM option. The heap can be of fixed size or variable size depending on the garbage collection strategy. Maximum heap size can be set using –Xmx option.By default, the maximum heap size is set to 64 MB. String Constant PoolString uses a special memory location to reuse of String objects ... Read More
2K+ Views
There are two ways to create a String object in Java By using the new operator String str = new String("Tutorials Point"); By using String literal String str = "Tutorials Point"; Whenever we call new String() in Java, it will create an object in the heap memory and String literals will go into String Constant Pool (SCP). For objects, JVM used SCP which is for efficient memory management in Java. Unlike other Java objects, instead of managing String object on the heap area, they introduced the String constant pool. One of important characteristic of String constant pool is that it does not create the same String ... Read More
7K+ Views
The string is immutable means that we cannot change the object itself, but we can change the reference to the object. The string is made final to not allow others to extend it and destroy its immutability. Security Parameters are typically represented as String in network connections, database connection URLs, usernames/passwords, etc. If it was mutable, these parameters could be changed easily. Synchronization and Concurrency making String immutable automatically makes them thread safe thereby solving the synchronization issues. Caching when compiler optimizes our String objects, it seems that if two objects have the same value (a =" test", and b =" test") and ... Read More
17K+ Views
In order to call an interface method from a java program, the program must instantiate the interface implementation program. A method can then be called using the implementation object.Examplepublic interface InterfaceDemo{ default public void displayNameDefault(String name){ System.out.println("Your name is : " + name); } public void displayName(String name); public void displayNameAndDesignation(String name, String designation); }The above interface defines three methods for displaying a name and optionally a job title. One method is a default method that contains implementation logic. The remaining two methods do not include implementation logic.public class InterfaceDemoImpl ... Read More
To Continue Learning Please Login
Login with Google