Skip to main content

Posts

Showing posts from November, 2020

Inner Class in Java

Inner class in Java In this article, we are going to learn a special type of class which is known as the Inner class in Java. Let's start this tutorial with the definition of the inner class, then we'll look at the types of the inner class, and how to create and use them. What is Inner class in Java? An inner class is a class that is defined within another class. An inner class can be considered as a member of the outer class and like the other members, it can have any access specifier and can be declared as abstract or final. There are generally two types of inner class in java: Static inner class or Static class Non-Static Inner class Whenever the inner class is marked with the static keyword, it will be called a Static class in java. Otherwise non-static inner class. In this tutorial, we are going to discuss the non-static inner class in java, so whenever we refer to the inner class it means we are talking about the non-static inner c

Static Class in Java

Static class in Java In this article, we are going to study what is a Static class in java, how we can create it and the benefits of making a static class. Before starting our tutorial on the static class, we first want to briefly remind you that "What is static?" , static is a keyword in java which is used to define a static member. A static member-created only once for a class and referred directly by the class name itself, objects created by the class can also refer the static member but all the objects share the same reference as static member-created only once for a class. A static member can be: static variables, static methods, static block or static initialization block, and, static class In this article, we will learn all about the static class in java, and we will discuss the other static members in another article. So, let's start this tutorial with the de

Immutable Class in Java

Immutable Class in Java In this article, we are going to learn how to create an immutable class in java. Immutable class is a class which constructs immutable objects. The state or property of an immutable object can only be initialized once (only in the constructor), and after that, all the properties of an immutable object remains constant throughout the life of the object. Before implementing immutable class in java, we must read the rules/guidelines provided for creating immutable class in java. Rules to create Immutable class in Java All the rules to create an Immutable class in java is defined to make sure that the state or property of the object do not get modified anyhow. Look at the below-mentioned rules to create an Immutable class in java. Class should be final : by making a class as final, we can ensure that the class will not to be extend by any other class and the methods will not allow to get overridden by the s