Blank Final in Java Last Updated : 23 Aug, 2022 Comments Improve Suggest changes Like Article Like Report A final variable in Java can be assigned a value only once, we can assign a value either in declaration or later. final int i = 10; i = 30; // Error because i is final. A blank final variable in Java is a final variable that is not initialized during declaration. Below is a simple example of blank final. // A simple blank final example final int i; i = 30; How are values assigned to blank final members of objects? Values must be assigned in constructor. Java // A sample Java program to demonstrate use and // working of blank final class Test { // We can initialize here, but if we initialize here, // then all objects get the same value. So we use blank // final final int i; Test(int x) { // Since we have already declared i as final above, // we must initialize i in constructor. If we remove // this line, we get compiler error. i = x; } } // Driver Code class Main { public static void main(String args[]) { Test t1 = new Test(10); System.out.println(t1.i); Test t2 = new Test(20); System.out.println(t2.i); } } Output: 10 20If we have more than one constructors or overloaded constructor in class, then blank final variable must be initialized in all of them. However constructor chaining can be used to initialize the blank final variable. Java // A Java program to demonstrate that we can // use constructor chaining to initialize // final members class Test { final public int i; Test(int val) { this.i = val; } Test() { // Calling Test(int val) this(10); } public static void main(String[] args) { Test t1 = new Test(); System.out.println(t1.i); Test t2 = new Test(20); System.out.println(t2.i); } } Output: 10 20 Blank final variables are used to create immutable objects (objects whose members can't be changed once initialized). Comment More infoAdvertise with us Next Article Static and Non Static Blank Final Variables in Java K kartik Improve Article Tags : Java Practice Tags : Java Similar Reads Coding Guidelines in Java Java is one of the most popular and widely used programming languages and platforms. A platform is an environment that helps to develop and run programs written in any programming language. Java is fast, reliable, and secure. From desktop to web applications, scientific supercomputers to gaming cons 7 min read Static and Non Static Blank Final Variables in Java In Java, a variable provides us with named storage that our programs can manipulate. In Java, a blank final variable is a final variable that is declared but not immediately initialized. It must be assigned exactly once before use. When a variable is declared with static, it becomes a static blank f 6 min read Static and Non Static Blank Final Variables in Java In Java, a variable provides us with named storage that our programs can manipulate. In Java, a blank final variable is a final variable that is declared but not immediately initialized. It must be assigned exactly once before use. When a variable is declared with static, it becomes a static blank f 6 min read Interesting facts about null in Java Almost all the programming languages are bonded with null. There is hardly a programmer, who is not troubled by null. In Java, null is associated java.lang.NullPointerException. As it is a class in java.lang package, it is called when we try to perform some operations with or without null, and somet 6 min read Rules For Variable Declaration in Java Variable in Java is a data container that saves the data values during Java program execution. Every variable is assigned a data type that designates the type and quantity of value it can hold. Variable is a memory location name of the data. A variable is a name given to a memory location. For More 2 min read Introduction to Java Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android 4 min read Like