The document provides an overview of variables in Java, including their types (local, instance, and class/static), declaration, and differences between primitive and non-primitive data types. It explains concepts such as final variables, constant variables, autoboxing, unboxing, typecasting, and variable scope. Additionally, it covers the default values of uninitialized variables and variable shadowing.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views2 pages
JAVA Imp
The document provides an overview of variables in Java, including their types (local, instance, and class/static), declaration, and differences between primitive and non-primitive data types. It explains concepts such as final variables, constant variables, autoboxing, unboxing, typecasting, and variable scope. Additionally, it covers the default values of uninitialized variables and variable shadowing.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
1. What is a variable in Java?
A variable is a container that holds a value or reference to a
value. 2. What are the different types of variables in Java? There are three types of variables in Java: local variables, instance variables, and class/static variables. 3. How do you declare a variable in Java? To declare a variable in Java, you use the syntax: data_type variable_name; For example, int count; 4. What is the difference between int and Integer in Java? int is a primitive data type, while Integer is a wrapper class for the int data type. Integer provides additional methods and functionality that are not available with the int data type. 5. What is a constant variable in Java? A constant variable is a variable whose value cannot be changed once it has been initialized. In Java, constant variables are declared using the final keyword. 6. What is a final variable in Java? A final variable is a variable whose value cannot be changed once it has been initialized. In Java, final variables can be declared using the final keyword. 7. What is the difference between a final variable and a constant variable in Java? There is no difference between a final variable and a constant variable in Java. Both refer to a variable whose value cannot be changed once it has been initialized. 8. What are the primitive data types in Java? The primitive data types in Java are: byte, short, int, long, float, double, boolean, and char. 9. What are the non-primitive data types in Java? The non-primitive data types in Java are: String, Arrays, Classes, and Interfaces. 10. What is the difference between primitive and non-primitive data types in Java? Primitive data types are basic data types and are built into the Java language, while non-primitive data types are created by the programmer or are provided by Java in the form of classes and interfaces. 11. What is autoboxing and unboxing in Java? Autoboxing is the automatic conversion of a primitive data type to its corresponding wrapper class, while unboxing is the automatic conversion of a wrapper class to its corresponding primitive data type. 12. What is the difference between a float and a double in Java? float is a single-precision 32-bit floating point data type, while double is a double-precision 64-bit floating point data type. 13. What is the difference between a long and an int in Java? long is a 64-bit signed integer data type, while int is a 32-bit signed integer data type. 14. What is the difference between a char and a String in Java? char is a primitive data type that represents a single character, while String is a non-primitive data type that represents a sequence of characters. 15. What is typecasting in Java? Typecasting is the process of converting a variable of one data type to another data type. 16. What is type promotion in Java? Type promotion is the process of converting a variable of a smaller data type to a larger data type. 17. What is the default value of an uninitialized variable in Java? The default value of an uninitialized variable in Java depends on its data type. For example, the default value of an uninitialized int variable is 0. 18. What is the scope of a variable in Java? The scope of a variable in Java is the part of the program where the variable is visible and can be accessed. 19. What is variable shadowing in Java? Variable shadowing occurs when a variable declared within a certain scope has the same name as a variable declared in an outer scope. 20. How do you assign a value to a variable in Java? To assign a value to a variable in Java, you use the assignment operator (=), like this: variable_name = value; For example, int count = 10;