Java Programming Fundamentals
Test your knowledge of Java programming fundamentals including classes, inheritance, data types, arrays, strings, conditional statements, and the Java platform architecture.
Questions
Suppose you want to define a class named Application1. This is the only class in the application. Which code completes the declaration of the class?
- class Application1
- public class Application1
- public static void Application1
- static Application1
Suppose you are using a Windows operating system and you wish to run an application. The application class is named App1 and is contained within the samples.java package. Choose the command that will run the application.
- java App1.samples.java
- java samples.java.App1
- javac samples.java.App1
- javac App1.samples.java
Suppose you want to declare an array of the first five letters of the alphabet. How do you declare and initialize the array?
- char[] alpha = {'A', 'B', 'C', 'D', 'E'};
- char[] alpha = {"A", "B", "C", "D", "E"};
- char[] alpha = new char('A', 'B', 'C', 'D', 'E');
- char[][] alpha = {{'A', 'B', 'C', 'D', 'E'}};
Which range of values is valid for all integral types, where n is the number of bits?
- 2^(n-1) to 2^(n+1)+1
- -2^(n-1) to 2^(n-1)-1
- -2^(n-1) to 2^(n-1)+1
- -2^(n-1) to 2^(n+1)-1
Which lexical elements do you use to start and end a comment that you wish to include as part of documentation? Choose more than one option.
- //
- /*
- /**
- */
Assume you have created a piece of Java source code and compiled it successfully. How does the Java platform execute the code?
- The compiler interprets the bytecode in the Java class file
- The Java Virtual Machine (JVM) interprets the bytecode in the Java class file
- The JVM interprets the native machine code
- The JVM translates compiled bytecode to machine code
You are required to represent the employees at a company in Java code. The employees are categorized according to their position and salary. You also need to be able to change the state of an employee due to a promotion. How could you represent this?
- Create a Salary object
- Declare an Employee class
- Declare an instance of the Employee class called Promotion
- Declare a promotion method that changes the value of the position variable
- Define variables for position and salary
Which Java keywords do you use in conditional statements to control program flow? Choose more than one option.
- catch
- else
- finally
- if
Identify the type of the following comment: /* this method prints out all *the employee's information */ Choose an option.
- Doc comment
- In-line comment
- Multi-line comment
- none
What is the correct way to declare and initialize a string object, "start", whose value - "Welcome to Java Programming" - can be shared?
- String start = new String("Welcome to Java Programming");
- String start[] = "Welcome to Java Programming";
- String start = "Welcome to Java Programming";
- none
When do you need to use an array?
- To create a mutable string
- To store a single character
- To store multiple items of the same type
- none
Assume you create a Student class with the variables name, ID, and course. You then create a method called gradeStudent. If you create a subclass of the Student class called GraduateStudent, what does it inherit?
- An instance of the Student class
- The course variable
- The gradeStudent method
- The ID variable
- The name variable