Java Junior

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Cvbee
C
Cvbee
Community Contributor
Quizzes Created: 1 | Total Attempts: 10,134
| Attempts: 10,134 | Questions: 59
Please wait...
Question 1 / 59
0 %
0/100
Score 0/100
1. Java runs on _______.

Explanation

Java is a platform-independent programming language, which means it can run on multiple operating systems. It is designed to be compatible with Windows, Unix/Linux, and Mac operating systems. Therefore, the correct answer is "All of the Above" as Java can run on all of these platforms.

Submit
Please wait...
About This Quiz
Java Junior - Quiz

It is created for Beginners in Java. This is to test the knowledge of any Java Developer wannabe.

2. What is the difference between private and public functions ?

Explanation

Public functions can be accessed and used by anyone, regardless of where they are defined. On the other hand, private functions can only be accessed and used by other code within the same class they are defined in. This means that private functions are restricted to be used only within the context of the class they belong to, while public functions can be used by any code that has access to them.

Submit
3. What is the proper way to declare a variable ?

Explanation

The proper way to declare a variable is by specifying the variable type followed by the variable name. This allows the compiler to allocate the appropriate amount of memory for the variable and ensures that the variable can be used correctly in the program.

Submit
4. What will be the value of "num" after the following statements? int num; num = (5+4); num = num / 9; num = 9;

Explanation

The value of "num" will be 9 because the variable "num" is initially assigned the value of (5+4), which is 9. Then, the variable "num" is divided by 9, resulting in 1. However, the value of "num" is reassigned to 9 in the next statement. Therefore, the final value of "num" is 9.

Submit
5. What is the role of the constructor? 

Explanation

Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object.

Submit
6. If you want your conditional to depend on two conditions BOTH being true, what is the proper notation to put between the two Boolean statements ?

Explanation

The proper notation to put between two Boolean statements if you want your conditional to depend on both conditions being true is "&&". This is known as the logical AND operator in programming. It returns true if both conditions are true and false otherwise.

Submit
7. What is the main function of any variable ?

Explanation

The main function of any variable is to keep track of data in the memory of the computer. Variables are used to store and manipulate data in computer programs. They allow us to assign values to data and retrieve or modify those values as needed. By storing data in variables, we can access and manipulate it throughout the program, making it an essential component of computer programming.

Submit
8. Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4 ?

Explanation

The correct answer is "if ((x = 4))". This means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4. The "||" operator represents the logical OR, so if either of the conditions is true, the whole expression will evaluate to true.

Submit
9. What is a loop ?

Explanation

A loop is a segment of code that is designed to be executed repeatedly for a specified number of times. It allows the programmer to efficiently perform repetitive tasks without having to write the same code multiple times. By specifying the number of times the code should be executed, the loop ensures that the desired operations are carried out efficiently and accurately.

Submit
10. The last value in an array called ar can be found at index:

Explanation

The last value in an array can be found at the index ar.length - 1 because arrays in most programming languages are zero-based, meaning the first element is at index 0. Therefore, the last element will be at the index one less than the length of the array.

Submit
11. What loop will display each of the numbers in this array on a separate line: float [ ] nums= {1.1f, 2.2f, 3.3f};

Explanation

The correct answer is the first option, "for (int i =0; i

Submit
12. What is an assignment statement ?

Explanation

An assignment statement is a programming construct that assigns a value to a variable. It is used to store and update data in a program. In this context, assigning a value to a variable means giving a specific value to a variable so that it can be used later in the program. This is a fundamental concept in programming as it allows for the manipulation and storage of data.

Submit
13. Which one needs a web page to run

Explanation

A Java Applet needs a web page to run because it is a small application that is designed to be embedded within a web page. It is executed within a web browser's Java Virtual Machine (JVM) and requires the web page's HTML code to provide the necessary environment for its execution. Unlike Java Applications or Stand-Alone Applications, which can be run independently on a computer, a Java Applet relies on the web page infrastructure to function properly.

Submit
14. Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.

Explanation

The explanation for the given correct answer is that the "synchronized" keyword in Java is used to ensure that only one thread can access a block of code or a method at a time. It provides a way to synchronize the execution of multiple threads, preventing them from interfering with each other. When a thread encounters a synchronized block or method, it grabs the lock on the associated object and continues execution. This ensures that other threads have to wait until the lock is released before they can access the synchronized code. Therefore, the statement that "synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution" is true.

Submit
15. The following prototype shows that a Cylinder subclass is derived from a superclass called Circle

Explanation

The correct answer is "class Cylinder extends Circle". This is because the keyword "extends" is used to indicate that the class Cylinder is derived from the superclass Circle. In object-oriented programming, inheritance allows a subclass to inherit the properties and methods of its superclass, and in this case, the subclass Cylinder is inheriting from the superclass Circle.

Submit
16. How to define a JButton with the caption test?

Explanation

The correct answer is "JButton aButton=new JButton("test");". This is the correct way to define a JButton with the caption "test". In Java, when creating an object, the syntax is "new ClassName()", and in this case, the class name is JButton. The caption "test" is passed as a parameter within double quotes.

Submit
17. Methods that are marked protected can be called in any subclass of that class.

Explanation

Protected methods in a class can be accessed and called by any subclass of that class. This access modifier allows subclasses to inherit and use the protected methods from the parent class. It provides a level of accessibility that is more restricted than public, but less restricted than private. Therefore, the statement that protected methods can be called in any subclass of the class is true.

Submit
18. Primitive datatypes are allocated on a stack.

Explanation

Primitive datatypes are allocated on a stack because they are simple and small in size. The stack is a region of memory that is used for local variables and function calls. When a primitive datatype is declared, memory is allocated on the stack to store its value. The stack is a fast and efficient way to allocate and deallocate memory for these types of variables.

Submit
19. What is an Applet ?

Explanation

An applet is a Java program that is designed to run within a web browser. It is a small application that is embedded within a web page and can be executed by a Java Virtual Machine (JVM) installed on the client's machine. Applets are used to add interactive features to websites and provide dynamic content. They have access to certain resources on the client's machine, such as the file system, but are restricted from performing certain actions for security reasons.

Submit
20. Can you compare a boolean to an integer?

Explanation

A boolean is a data type that can only have two possible values: true or false. An integer, on the other hand, is a numeric data type that represents whole numbers. Since they are different data types, they cannot be directly compared.

Submit
21. What is the keyword used in java to create an object?

Explanation

In Java, the keyword "new" is used to create an object. It is followed by the name of the class and parentheses, which can optionally contain arguments to be passed to the constructor of the class. The "new" keyword dynamically allocates memory for the object and initializes its state.

Submit
22. What would display from the following statements? int [ ] nums = {1,2,3,4,5,6}; System.out.println((nums[1] + nums[3]));

Explanation

The code initializes an array called "nums" with the values {1,2,3,4,5,6}. It then prints the sum of the values at index 1 and index 3 of the array, which are 2 and 4 respectively. Therefore, the output will be 6.

Submit
23. With inheritance, a derived subclass object can directly access any

Explanation

Additionally, a subclass can access protected members of the superclass regardless of the package if it is derived from the superclass. However, private superclass members are not directly accessible to the subclass.

Submit
24. The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces of code.

Explanation

The methods wait(), notify(), and notifyAll() in the Object class need to be called from synchronized pieces of code because they are used for inter-thread communication and synchronization. When a thread calls the wait() method, it releases the lock on the object and waits for another thread to notify it. Similarly, when a thread calls the notify() or notifyAll() method, it notifies the waiting threads that they can resume execution. To ensure thread safety and prevent race conditions, these methods should only be called from synchronized blocks or methods.

Submit
25. If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:

Explanation

The size of the array "ar" is 6 because the given declaration "int[] ar = {1,2,3,4,5,6};" initializes an array named "ar" with 6 elements. Each element is assigned a value from 1 to 6. Therefore, the size of the array is equal to the number of elements in it, which is 6.

Submit
26. What's the difference between an Applet and an application ?

Explanation

An applet is a small program that is designed to be executed within a web browser. It is typically written in Java and runs on the client-side. On the other hand, an application is a standalone program that is designed to be executed on a computer's operating system. It is not limited to running within a web browser. Therefore, the difference between an applet and an application is that applets are specifically designed to be run over the web, while applications can be run on any operating system.

Submit
27. An abstract class can have non-abstract methods.

Explanation

An abstract class can have non-abstract methods because an abstract class is a class that cannot be instantiated and is meant to be inherited by other classes. It can contain both abstract and non-abstract methods. Non-abstract methods in an abstract class have a complete implementation and can be directly used by the subclasses that inherit from the abstract class. This allows the abstract class to provide common functionality to its subclasses while still allowing them to implement their own specific behavior.

Submit
28. Java keywords are written in lowercase as well as uppercase.

Explanation

Java keywords are written in lowercase only. In Java, keywords are predefined reserved words that have specific meanings and cannot be used as identifiers for variables, methods, or classes. These keywords are case-sensitive, meaning that they must be written in lowercase letters. Writing keywords in uppercase would result in a compilation error. Therefore, the statement that Java keywords are written in lowercase as well as uppercase is incorrect.

Submit
29. The default statement of a switch is always executed.

Explanation

The default statement of a switch is not always executed. The default statement is only executed when none of the cases match the value being evaluated. If a case matches, the corresponding block of code is executed and the switch statement terminates. If there is no default statement, and none of the cases match, the switch statement simply does nothing. Therefore, the correct answer is false.

Submit
30. Class B inherits from Class A, what cannot be said:

Explanation

Since Class B inherits from Class A, it can access the protected and public members of Class A. However, it cannot access the private members of Class A. Private members are only accessible within the same class and not by any derived classes. Therefore, it cannot be said that B has access to the private members of A.

Submit
31. Inner classes can be defined within methods.

Explanation

Inner classes can be defined within methods. This statement is true. In Java, it is possible to define a class inside another class, and this inner class can also be defined within a method. This allows for more flexibility in organizing and encapsulating code. Inner classes have access to the variables and methods of the outer class, and can be useful in implementing complex logic or creating specialized data structures within a specific method scope.

Submit
32. What is a member of a class

Explanation

A member of a class refers to any attribute or method that belongs to that class. It can be either an attribute, which represents the data or state of the object, or a method, which represents the behavior or actions that the object can perform. In object-oriented programming, classes are used to define the blueprint for creating objects, and the members of a class define the characteristics and capabilities of those objects. Therefore, a member of a class can be either an attribute or a method.

Submit
33. A class is...

Explanation

A class is an abstract definition of an object because it serves as a blueprint or template for creating specific instances of that object. It defines the properties and behaviors that the object will have, but it is not the actual object itself. The class provides a way to organize and structure the code, allowing for code reusability and modularity.

Submit
34. A null reference may be used to access a static variable or method.

Explanation

A null reference cannot be used to access a static variable or method because static members belong to the class itself and not to any specific instance of the class. They can be accessed using the class name directly, without needing an instance of the class. A null reference represents the absence of an object and cannot be used to access any members, including static members. Therefore, the statement is false.

Submit
35. Following code will result in: int num = 6.7;

Explanation

The given code will result in a compilation error. This is because the variable "num" is declared as an integer, but it is being assigned a floating-point value (6.7). In Java, you cannot assign a floating-point value to an integer variable without explicit type casting.

Submit
36. Following code will result in: float num = 5/0;

Explanation

The code will result in a runtime exception because dividing a number by zero is not a valid operation in mathematics. This will throw an exception at runtime and the program will terminate abruptly.

Submit
37. Following code will result in: int a1 = 5; double a2 = (float)a1;

Explanation

The given code will not result in any errors. It initializes an integer variable "a1" with the value 5 and then assigns the value of "a1" to a double variable "a2" after casting it to a float. Since both int and float can be implicitly converted to double without any loss of precision, there will be no compilation or runtime errors.

Submit
38. What displays from the following statements? String word = "abcde"; for (int i = 0; i <4; i+=2) System.out.print(word[i]);

Explanation

The given code initializes a string variable "word" with the value "abcde". Then, it enters a for loop that starts with i=0 and increments i by 2 in each iteration until i

Submit
39. In a 'for' loop, what section of the loop is not included in the parentheses after "for" ?

Explanation

In a 'for' loop, the section of the loop that is not included in the parentheses after 'for' is the Loop Body. The loop body contains the code that is executed repeatedly until the loop condition becomes false. The initialization, test statement, and update sections are all included within the parentheses after 'for' and are responsible for controlling the loop's execution. The loop body is the block of code that is executed during each iteration of the loop.

Submit
40. If none of the private/protected/public is specified for a member, that member ...

Explanation

If none of the access modifiers (private, protected, public) is specified for a member, that member is only accessible by other classes of the same package. This means that the member can be accessed by any other class within the same package, but not by classes in different packages.

Submit
41. Which is not a part of defining an object?

Explanation

An object in programming is typically defined by its name, methods, and associations with other objects. The description, on the other hand, is not a necessary component for defining an object. While a description can provide additional information about the object, it is not essential for its definition. The name is used to identify the object, methods define its behavior or actions, and associations establish relationships with other objects.

Submit
42. Which one is not correct?

Explanation

The statement "Class and object are just different names for the same thing" is not correct. In object-oriented programming, a class is a blueprint or template for creating objects, while an object is an instance of a class. A class defines the properties and behaviors that an object will have, and multiple objects can be created from the same class. Therefore, a class and an object are not the same thing, but rather, a class is used to create objects.

Submit
43. Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}

Explanation

The code will not result in any errors because class B extends class A, so it is valid to assign an instance of B to a variable of type A. The code will compile successfully and run without any issues.

Submit
44. A class can be transient

Explanation

A class cannot be transient. The "transient" keyword in programming is used to indicate that a variable should not be serialized when an object is being converted to a byte stream. However, it cannot be applied to a class itself. The "transient" keyword can only be used with variables within a class to specify that they should not be included in the serialization process. Therefore, the statement that a class can be transient is incorrect.

Submit
45. How can you prevent a member variable from becoming serialized?

Explanation

A transient variable is a variable that may not be serialized.

Submit
46. What is essential in making sure that your loop is not infinite ?

Explanation

To ensure that a loop is not infinite, it is essential that the Boolean statement used as the loop condition will eventually evaluate to false. This allows the loop to terminate and the program to move on to the next set of instructions. Without a false condition, the loop would continue indefinitely, causing the program to hang or crash. Therefore, it is crucial to have a Boolean statement that will eventually be false in order to prevent an infinite loop.

Submit
47. Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?

Explanation

When comparing the objects "a" and "b" using the "==" operator, it checks if the two objects refer to the same memory location. In this case, even though the values of "a" and "b" are both 2, they are different objects with different memory locations. Therefore, the condition "a==b" evaluates to false.

Submit
48. Following code will result in: class A { public static void main(String [] args) {B b = new A(); }} class B extends A {}

Explanation

The given code will result in a compile error because the object 'b' is being declared as type 'B' but it is being assigned a new instance of class 'A'. Since 'A' is not a subclass of 'B', this assignment is not valid and will cause a compile error.

Submit
49. Which is NOT a section of all types of loops ?

Explanation

The word "while" is not a section of all types of loops. It is specifically used in the syntax of the while loop, but not in other types of loops such as the for loop or the do-while loop. The other sections mentioned - Initialization, Loop Body, and Test statement - are common components found in all types of loops.

Submit
50. Native methods can be 'abstract'

Explanation

Native methods cannot be abstract. Native methods are methods that are implemented in a language other than Java, such as C or C++. These methods are declared with the "native" keyword and their implementation is provided outside of the Java code. Abstract methods, on the other hand, are methods that are declared without an implementation and must be implemented by the subclasses. Since native methods already have a specific implementation in a different language, they cannot be declared as abstract. Therefore, the correct answer is False.

Submit
51. A class cannot be declared:

Explanation

There is no access modifier called "static" for class declarations in Java. "Static" is used for static members and methods within a class. So, a class cannot be declared as "static," but it can have static members or methods.

Submit
52. If class A implements an interface does it need to implement all methods of that interface?

Explanation

When a class A is declared as abstract, it means that it cannot be instantiated directly and can only be used as a base class for other classes. In this case, if class A implements an interface, it is not required to implement all the methods of that interface. The responsibility of implementing those methods is passed on to the concrete subclasses of A. Therefore, the correct answer is "No, not when A is abstract."

Submit
53. Following code will result in: class A { int x = 1; public static void main(String [] args) { System.out.println("x is " + x); }}

Explanation

The code will result in a compilation error because the variable "x" is not declared as static, which means it can only be accessed through an instance of the class. However, in the main method, which is static, there is no instance of the class A created to access the variable "x". Therefore, a compilation error will occur when trying to access the non-static variable from a static context.

Submit
54. What is an instanceof?

Explanation

The correct answer is "An operator and keyword". The instanceof operator is used to check if an object belongs to a particular class or interface. It returns true if the object is an instance of the specified class or interface, or one of its subclasses or implementations. The instanceof keyword is used in Java programming language to perform this check. Therefore, the answer "An operator and keyword" accurately describes the instanceof operator.

Submit
55. Following code will result in: int num = 8/0;

Explanation

The code will result in a runtime exception because it is trying to divide a number by zero, which is not allowed in mathematics. This will cause a runtime error and the program will terminate abruptly.

Submit
56. What does AWT stands for ?

Explanation

AWT stands for Abstract Window Toolkit. This is a set of application programming interfaces (APIs) provided by Java for creating graphical user interfaces (GUIs) for Java programs. AWT provides a collection of classes and methods that allow developers to create windows, buttons, menus, and other GUI components. It is a part of the Java Foundation Classes (JFC) and is used for developing platform-independent GUI applications.

Submit
57. Which package do you need to use widgets such as JApplet, JFrame, JPanel and JButton?

Explanation

The correct answer is javax.swing. This is because javax.swing is the package that provides classes for creating and managing graphical user interface (GUI) components in Java. It includes classes such as JApplet, JFrame, JPanel, and JButton, which are commonly used for building GUI applications. The other options, javax.gui, java.awt, and java.swing, are not valid packages in Java.

Submit
58. What is the correct syntax for java main method?

Explanation

public static void main(String args[]) is the right format. String instead of string is the correct one.

Submit
59. Which of the following is not a Java keyword?

Explanation

"main" is a keyword used to denote the entry point of a Java program.

"try" is a keyword used to start a block of code that might cause exceptions.

"String" is a keyword used to declare string variables and objects.

"integer" is not a keyword in Java. The correct keyword for integer data types in Java is "int."

Submit
View My Results

Quiz Review Timeline (Updated): Jun 16, 2024 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Jun 16, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 11, 2013
    Quiz Created by
    Cvbee
Cancel
  • All
    All (59)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Java runs on _______.
What is the difference between private and public functions ?
What is the proper way to declare a variable ?
What will be the value of "num" after the following statements?...
What is the role of the constructor? 
If you want your conditional to depend on two conditions BOTH being...
What is the main function of any variable ?
Which of the following means that in order for the conditional to...
What is a loop ?
The last value in an array called ar can be found at index:
What loop will display each of the numbers in this array on a separate...
What is an assignment statement ?
Which one needs a web page to run
Synchronized is a keyword to tell a Thread to grab an Object lock...
The following prototype shows that a Cylinder subclass is derived from...
How to define a JButton with the caption test?
Methods that are marked protected can be called in any subclass of...
Primitive datatypes are allocated on a stack.
What is an Applet ?
Can you compare a boolean to an integer?
What is the keyword used in java to create an object?
What would display from the following statements? int [ ] nums =...
With inheritance, a derived subclass object can directly access any
The methods wait(), notify() and notifyAll() in Object need to be...
If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:
What's the difference between an Applet and an application ?
An abstract class can have non-abstract methods.
Java keywords are written in lowercase as well as uppercase.
The default statement of a switch is always executed.
Class B inherits from Class A, what cannot be said:
Inner classes can be defined within methods.
What is a member of a class
A class is...
A null reference may be used to access a static variable or method.
Following code will result in: int num = 6.7;
Following code will result in: float num = 5/0;
Following code will result in: int a1 = 5; double a2 = (float)a1;
What displays from the following statements? String word =...
In a 'for' loop, what section of the loop is not included in the...
If none of the private/protected/public is specified for a member,...
Which is not a part of defining an object?
Which one is not correct?
Following code will result in: class A { public static void...
A class can be transient
How can you prevent a member variable from becoming serialized?
What is essential in making sure that your loop is not infinite ?
Integer a = new Integer(2); Integer b = new Integer(2); What happens...
Following code will result in: class A { public static void...
Which is NOT a section of all types of loops ?
Native methods can be 'abstract'
A class cannot be declared:
If class A implements an interface does it need to implement all...
Following code will result in: class A { int x = 1; public static...
What is an instanceof?
Following code will result in: int num = 8/0;
What does AWT stands for ?
Which package do you need to use widgets such as JApplet, JFrame,...
What is the correct syntax for java main method?
Which of the following is not a Java keyword?
Alert!

Advertisement