Java 101 Interview Questions

If you’re like me, you’re looking to get into Java development. But to leap across that hurdle, you need to be prepared for when your interviewer asks you any questions! Here’s 21 basic Java questions that any Java developer should be able to answer:

  1. What is Java?
  2. What do objects have in common?
  3. What are superclasses to subclasses?
  4. How would one create/define a subclass?
  5. How would one use a method on an object?
  6. Which elements are most common in any Java file?
  7. When would imports be used?
  8. Where would imports be placed?
  9. How many different String methods are already in the String class?
  10. What is String concatenation?
  11. Which import allows for user input?
  12. Are there any limitations to assignment statements?
  13. What is the difference between primitive and reference data types?
  14. What are the rules of precedence?
  15. What is type casting?
  16. When would a constant value be used?
  17. Which Scanner method can be used to input Strings?
  18. Writing your first Java method, what order of declaration is needed?
  19. What are constructors for and where can they not be used?
  20. What kind of access modifiers are there?
  21. Which kinds of if statements exist?

Here are the answers!

  1. Java is a general-purpose class-based object-oriented programming language that follows four fundamentals: Abstraction, Polymorphism, Inheritance, and Encapsulation.
  2. Objects hold data values, methods, and may have the same methods/values created as instances of a class.
  3. A superclass is a class that supports objects (subclasses) that instantiate it.
  4. object = new Class();
  5. int value = object.useMethod();
  6. Comments, import statements, and class declarations make up most common elements in any Java file.
  7. Imports are used to import Java’s main packages and methods, such as java.util.Scanner for scanning user terminal input.
  8. Imports are best placed atop the .java file to ensure their use by the very beginning. Asterisks may be placed on class name as wildcards to import all classes, such as java.util.*
  9. There are almost 50 methods defined in the String class, including an operation called concatenation.
  10. String concatenation is an operation used to combine strings. Whereas a String may be defined as a quoted constant, a concatenation String can be defined as a pair of existing Strings. After defining Str_1 and Str_2 I can define a new String. Example below.
  11. the java.util.Scanner class allows for Scanner user input.
  12. There are no limits to assignment statements. You can assign values to variables as long as the statement supports it. Example below.
  13. Primitive data types are individual values and numerical data. Reference data types represent objects and addresses where object data is stored.
  14. Precedence rules are essentially the order of operations: PEMDAS! Parenthesis, Exponent, Multiplication, Division, Addition, Subtraction.
  15. Type casting takes mixed expressions (such as a statement that multiplies a float value with an int value) and uses promotion rules to use the higher precision data type. Demotion of data type precision is unallowed.
  16. Keyword final is only used when a value must remain unchanged.
  17. The next() Scanner method can be used to input Strings.
  18. <modifier> <return type> <method name> ( <parameters> ) { <statements> }
  19. Constructors create subclasses, but cannot be used with interfaces.
  20. Default, Public, Private, and Protected. If you do not mention any access modifier for class, method or variable, then it is treated as default. The default access modifier is accessible only within same package and cannot be accessed from a different package. Public and private determine accessibility within the same class. Protected is unique as it becomes accessible within the same package as well as within a subclass of a different package. It cannot be applied to a class.
  21. An if statement is made up of control flow and relational operators and can be compound statements, else-if statements, or even nested-if statements.
10. /* The following String concatenation should print out "doghouse" */
String Str_1 = "dog";
String Str_2 = "house";
System.out.print(Str_1 + Str_2);

12. /* We assign value to a variable using an assignment statement. */
int three;
int one;
int two;
three = one + two;

18. /* We declare order on line 1 of the method. Access modifier, data returned, method name, parameters (which is commonly left as null) and inside the method we place all of our statements, loops, and variables. */
public static void main(String[] args) {
        System.out.println("This is a test.");
    }


Can’t get stumped as easily on interview questions with a comprehensive Java overview!

Leave a comment

Design a site like this with WordPress.com
Get started