
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 7442 Articles for Java

3K+ Views
A super keyword is a reference of the superclass object in Java. Using this, you can invoke the instance methods constructors and, variables, of a superclass.Calling the constructor of a superclassYou can call the constructor of a superclass from the subclass’s constructor.ExampleConsider the following example, it has two classes SuperClass class and SubClass where the SubClass extends the SuperClass. The superclass has a parameterized constructor, we are invoking it from the subclass using the "super" keyword. Live Democlass SuperClass{ SuperClass(int data){ System.out.println("Superclass's constructor: "+data); } } public class SubClass extends SuperClass{ SubClass(int data) { ... Read More

1K+ Views
The "this" keyword in Java is used as a reference to the current object, within an instance method or a constructor. Using it, you can refer the members of a class such as constructors, variables, and methods.Assigning reference to "this"According to the definition "this" is a keyword which acts as a reference to the current object (the object from whose constructor/method you are using it), its value id is fixed. Therefore, you cannot assign a new reference value to it. Moreover, it is just a keyword, not a variable.Still, if you try to it assign a reference value to "this" it ... Read More

6K+ Views
In this article, we will learn about the basic structure of a program in Java. Java is widely used for developing large-scale applications, including Android apps, web applications, and enterprise software. To write a Java program, it's essential to understand its basic structure, which consists of several key components. Components A typical structure of a Java program contains the following elements: Package declaration Import statements Comments Class definition Class variables, Local variables Methods/Behaviors ... Read More

3K+ Views
In Java, non-static blocks run before the constructor whenever an object is created. If multiple non-static blocks exist, they execute in the order they appear in the class, followed by the constructor. In this article, we will understand this order of execution with the help of examples. What Are Non-Static Blocks in Java? The Non-static blocks are class-level blocks which don't contain a prototype. A non-static block must perform any logic whenever an object is instantiated, regardless of the constructor. The Non-static blocks are automatically called by the JVM for every object creation in the Java stack area. We can ... Read More

236 Views
The substring() method returns a String datatype which corresponds to the original String starting from the begin index until the end Index. If the end index is not specified, it is imperative that the endIndex is the String length. Since we are dealing with the String, the index starts at '0' position.Syntaxpublic String substring(int beginIndex) public String substring(int beginIndex, int endIndex)beginIndex: the starting index or position where we want to start to cut or substring our String.endIndex: the end index or position where we want to end our cutting or substring our String.This method returns a String datatype which corresponds to the ... Read More

1K+ Views
The UncaughtExceptionHandler is an interface inside a Thread class. When the main thread is about to terminate due to an uncaught exception the java virtual machine will invoke the thread’s UncaughtExceptionHandler for a chance to perform some error handling like logging the exception to a file or uploading the log to the server before it gets killed. We can set a Default Exception Handler which will be called for the all unhandled exceptions. It is introduced in Java 5 Version.This Handler can be set by using the below static method of java.lang.Thread class.public static void setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler ueh)We have to provide an implementation of the interface ... Read More

1K+ Views
A Java program can execute in the Java Virtual Machine (JVM) and uses the heap memory to manage the data. If our Java program requires more memory, there is a possibility that the Java Virtual Machine(JVM) will begin to throw OutOfMemoryError instances when attempting to instantiate an object in Java. How to change/increase the JVM Heap Size? In Java, it is possible to increase the heap size allocated by the JVM: -Xms: Set an initial Java heap size JVM automatically manages the heap memory but we can ... Read More

5K+ Views
No, we cannot define a static constructor in Java, If we are trying to define a constructor with the static keyword a compile-time error will occur.In general, static means class level. A constructor will be used to assign initial values for the instance variables. Both static and constructor are different and opposite to each other. We need to assign initial values for an instance variable we can use a constructor. We need to assign static variables we can use Static Blocks.ExampleLive Demopublic class StaticConstructorTest { int x = 10; // Declaratiopn of Static Constructor static StaticConstructorTest() { ... Read More

473 Views
The intern() method of String class can be used to deal with the string duplication problems in Java. Using intern() we can save a lot of memory consumed by duplicate string instances. A string is duplicate if it contains the same content as another string but it can be occupied different memory locations.We know that JVM maintains a separate heap memory for string literals for the performance. Once we declare a string literal it will go to this pool and if another variable is assigned with the same literal value, it will be picked from the pool instead of creating a new ... Read More

4K+ Views
Yes, we can change the order of public static void main() to static public void main() in Java, the compiler doesn't throw any compile-time error or runtime error. In Java, we can declare access modifiers in any order, the method name comes last, the return type comes second to last and then after it's our choice. But it's recommended to put access modifier (public, private and protected) at the forefront as per Java coding standards. Java Method Modifiers and Their Order Java allows you to place method modifiers (the keyword "public, " "static, " "final, " etc.) in various orders. The Java ... Read More