In Java, a final variable is a variable whose value cannot be changed after it is initialized. Final variables are declared using the “final” keyword and once a value is assigned to a final variable, it cannot be reassigned. There are several benefits to using final variables. For example, final variables can be used to ensure…
Category: Java Core
What is ‘this’ keyword in java? Explained with example.
The “this” keyword in Java is used to refer to the current object of a class. It is used to access the current object’s properties and methods, and it can also be used to invoke constructors of the same class. For example, consider the following class: class MyClass { int x; MyClass(int x) { this.x =…
What is ‘super’ keyword in java? Explained with example.
The “super” keyword in Java is used to refer to the immediate parent class of an object. It is typically used within the context of inheritance, where a subclass inherits properties and methods from its parent class. The “super” keyword can be used in several ways in Java, but its most common usage is to invoke…
Java’s ‘write once and run anywhere’ nature explained.
Java is a widely-used programming language that is known for its “write once, run anywhere” (WORA) nature. This means that Java code can be written once and then run on any platform without the need for any additional changes or modifications. The reason behind Java’s WORA nature is its use of the Java Virtual Machine (JVM).…
What is the difference between JVM, JDK and JRE in Java?
Java is a popular programming language that is widely used for developing a variety of applications. In order to run Java code, you need to have certain software components installed on your computer. These components include the Java Virtual Machine (JVM), the Java Development Kit (JDK), and the Java Runtime Environment (JRE). The JVM is the…
What are the features of Java Programming Language?
Java is a popular, versatile programming language that is widely used in a variety of applications, from enterprise software to mobile apps. Here are some of the key features that make Java a powerful and popular choice for developers: Object-Oriented: Java is a strictly object-oriented programming language, which means that all elements of the language are…
What is the difference between C++ and Java?
C++ and Java are both popular programming languages, but they have some key differences that make them better suited for different types of projects. C++ is a low-level programming language that is often used for system programming, game development, and other performance-critical applications. It is a compiled language, which means that the code is translated…
Constructor Overloading in Java
Constructor are used to create the objects . new keyword always calls the constructor of the class. Constructor name is always be the same as the name of the class .Generally in 99% code ,the name of the method is different from the name of the class . But the problem arises that method too can…
Fail Fast Vs Fail Safe Iterator In Java
Fail fast iterator while iterating through the collection , instantly throws Concurrent Modification Exception if there is structural modification of the collection. Fail Safe Iterator makes copy of the internal data structure (object array) and iterates over the copied data structure.Any structural modification done to the iterator affects the copied data structure. Fail Fast Iterator Fail Safe Iterator…
String vs StringBuilder vs StringBuffer in Java
String String is immutable ( once created can not be changed )object . The object created as a String is stored in the Constant String Pool. Every immutable object in Java is thread safe ,that implies String is also thread safe . String can not be used by two threads simultaneously. String once assigned can not be changed. StringBuffer…