QnA | How do I get the default value of data type?

Frequently Asked Questions

There is a simple process to get the default value of data type. Declare data type without any value, try to access it and you will get your answer.

Step-1: Declare variables

Declare variables without any value and try to print the value of that variable.

public class Sample3 {
	public static void main(String[] args) {
		int intVar;
		String strVar;
		System.out.println(intVar);
		System.out.println(strVar);
	}
}

Step-2: Default value of data type

When we try to access or print the value for the variables which are not initialized, we got a compile-time error for these variables.

Observe that tiny red lines for the variables (intVar and strVar) under println() statements. Mouse hover over these variables and select the option “Initialize Variable” from the pop-up box.

Mouse hover over these variables and select the option "Initialize Variable" from the pop-up box.

As soon as you click on the “Initialize variable” link, all the respective variables get initialized with their default values as mentioned below. Observe that for int data type default value is 0 and for String data type default value is null.

int data type default value is 0 and for String data type default value is null.

Java Question And Answer:

TestNG:

Computer Basics:

Java Basics:

Java File Handling:

OOPs Concept:

Java Programs:

Selenium Tutorials:

JIRA:

Agile:


201total visits,5visits today

Leave a Reply

Your email address will not be published. Required fields are marked *