Java Basics Interview Prep Questions with Answers
1.What is a variable?: A data container that can be named and assigned
a data type. Each variable name is given a memory location that can
be called within the variables scope.
2.What is a variable's scope?: The segments in a program in which a
variable can be used.
3.What is a literal? Give examples.: A literal is a source code
representation of a fixed value. They are represented directly in the
code without any computation.
int count = 0;
A literal '0' represents the value zero.
4.What are variable naming conventions? (Reference/Primitive types;
Meth- ods; Enums; Imports): Reference and primitive types: use lower
camel case for names with no spaces. Variables cannot have the same
name unless you are reassigning the value of a previously declared
variable.
Method names: camelCase, can overload method
names Enums use all caps snake case:
LETTERS_LETTERS Imports: java.util.package
5.What happens if you define a variable without assigning a value, and then
use the variable?: You will have the ability to assign it later, but a value is
necessary if the variable's value is being evaluated before the
assignment. If you try to use it, then it will give you an error.
6.What is a type?: A data type determines what kind of value an object
or variable is allowed to hold.
Example: an int holds a number with a limited length, and a String holds
multiple character values such as words or number combinations.
7.Distinguish between value types and reference types.: Value Type holds
the data within its own memory allocation: Predefined datatypes,
structures, enums
Reference Type contains a pointer to another memory location that
holds the real data: Objects, Classes, Arrays, Interfaces