Java Programming And Software Engineering Fundamentals

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By SPACECOMPUTER
S
SPACECOMPUTER
Community Contributor
Quizzes Created: 10 | Total Attempts: 49,136
Questions: 42 | Attempts: 1,270

SettingsSettingsSettings
Java Programming And Software Engineering Fundamentals - Quiz

If you are preparing for Java developer, then you should definitely take this Java fundamentals programming quiz.


Questions and Answers
  • 1. 

    What is the size of a Char?

    • A.

      4 bits

    • B.

      7 bits

    • C.

      8 bits

    • D.

      16 bits

    Correct Answer
    D. 16 bits
    Explanation
    A char data type in most programming languages is typically represented by 8 bits or 1 byte. However, in some languages like Java, a char is represented by 16 bits or 2 bytes. Therefore, the correct answer for the size of a char in this question is 16 bits.

    Rate this question:

  • 2. 

     A class cannot be declared

    • A.

      Static

    • B.

      Private

    Correct Answer
    B. Private
    Explanation
    A class cannot be declared as private because the private access modifier restricts access to members within the same class only, not to the class itself. Private is used to hide members (such as variables and methods) from being accessed by other classes or objects. However, a class needs to be accessible by other classes in order to be used and instantiated. Therefore, declaring a class as private would render it inaccessible and unusable, making it impossible to create objects of that class.

    Rate this question:

  • 3. 

    Following code will result in: int a = 3.5;

    • A.

      Compilation error

    • B.

      Runtime error

    Correct Answer
    A. Compilation error
    Explanation
    The code will result in a compilation error because it is trying to assign a floating-point value (3.5) to an integer variable (a). In Java, this type mismatch is not allowed and will cause a compilation error.

    Rate this question:

  • 4. 

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

    • A.

      Runtime error

    • B.

      No errors

    Correct Answer
    B. No errors
    Explanation
    The code will not result in any errors because it is a valid type casting operation. The variable a1 is an integer with a value of 5, and it is being explicitly casted to a float before assigning it to the double variable a2. Since the float can be safely converted to a double without any loss of precision, there will be no errors during compilation or runtime.

    Rate this question:

  • 5. 

     Following code will result in: int a = 9/0;

    • A.

      Compilation error: Divisions must be in a try block.

    • B.

      Runtime Exception

    Correct Answer
    B. Runtime Exception
    Explanation
    The code will result in a runtime exception because it tries to divide 9 by 0, which is not a valid operation in mathematics. This will cause a division by zero error at runtime, resulting in a runtime exception.

    Rate this question:

  • 6. 

    Following code will result in: float a = 9/0

    • A.

      Compilation error: DivideByZeroException

    • B.

      Runtime Exception

    Correct Answer
    B. Runtime Exception
    Explanation
    The code "float a = 9/0" will result in a runtime exception. This is because dividing a number by zero is not a valid mathematical operation and it throws a runtime exception called "DivideByZeroException".

    Rate this question:

  • 7. 

    A class can be transient

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    A class cannot be transient. Transient is a keyword in programming languages, typically used to indicate that a variable should not be serialized, or in other words, should not be saved and restored when the object is written to a file or transferred over a network. However, the transient keyword cannot be applied to a class itself. It can only be used with variables within a class to specify that they should not be serialized. Therefore, the statement "A class can be transient" is incorrect.

    Rate this question:

  • 8. 

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

    • A.

      Compilation error

    • B.

      Runtime Error

    Correct Answer
    A. Compilation error
    Explanation
    The given code will result in a compilation error because the variable "b" is an instance variable and cannot be accessed directly from a static method (main method). To access the instance variable, it needs to be accessed through an object of the class.

    Rate this question:

  • 9. 

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

    • A.

      Compile error

    • B.

      No error

    Correct Answer
    A. Compile error
    Explanation
    The given code will result in a compile error because class B extends class A, creating a cyclic inheritance relationship. In Java, cyclic inheritance is not allowed, and the compiler will throw an error. To resolve this issue, the inheritance relationship between class A and class B should be modified.

    Rate this question:

  • 10. 

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

    • A.

      Runtime Exception

    • B.

      No errors

    Correct Answer
    B. No errors
    Explanation
    The code will not result in any errors because class B extends class A, so it is valid to create an instance of B and assign it to a variable of type A. This is known as polymorphism in Java. However, it is important to note that at runtime, the actual object being referred to is of type B, so if any methods or fields specific to B are accessed using the variable 'a', it may result in a runtime exception.

    Rate this question:

  • 11. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Protected methods in a class can be accessed by any subclass of that class. This means that if a method is marked as protected in a parent class, it can be called and used in any child class that inherits from the parent class. This allows for the child classes to have access to and utilize the protected methods defined in the parent class, providing flexibility and extensibility in the design and implementation of the class hierarchy.

    Rate this question:

  • 12. 

    An abstract class can have non-abstract methods

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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 called directly. This allows the abstract class to provide some default behavior that can be inherited by its subclasses.

    Rate this question:

  • 13. 

    Java keywords are written in lowercase as well as uppercase

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Java keywords are written in lowercase as well as uppercase. This means that Java keywords can be written in either lowercase or uppercase letters. The Java language is case-sensitive, so both forms of writing keywords are considered valid. However, it is a common convention to write Java keywords in lowercase letters to distinguish them from class names and variables, which are typically written in camel case. Therefore, the statement "Java keywords are written in lowercase as well as uppercase" is true.

    Rate this question:

  • 14. 

    What is an instanceof

    • A.

      A methods in object

    • B.

      An operator and keyword

    Correct Answer
    B. An operator and keyword
    Explanation
    The correct answer is "An operator and keyword." The instanceof operator is used to check if an object is an instance of a particular class or interface. It returns true if the object is an instance of the specified class or interface, and false otherwise. It is a keyword in Java and is used in conjunction with the object and the class or interface being checked.

    Rate this question:

  • 15. 

    Primitive datatypes are allocated on a stack

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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, its value is directly stored on the stack. This allows for efficient memory allocation and deallocation, as the stack automatically manages the memory for these variables. Additionally, since primitive datatypes are not objects, they do not require dynamic memory allocation on the heap like objects do.

    Rate this question:

  • 16. 

    Can you compare a boolean to an integer?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
    Explanation
    A boolean represents a logical value, either true or false, while an integer represents a numeric value. Comparing a boolean to an integer would be comparing two different data types, which is not allowed in most programming languages. Therefore, it is not possible to directly compare a boolean to an integer.

    Rate this question:

  • 17. 

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

    • A.

      Yes, always

    • B.

      No, not when A is abstract

    Correct Answer
    B. No, not when A is abstract
    Explanation
    When class A is declared as abstract, it means that it cannot be instantiated on its own. Abstract classes can have abstract methods, which are methods without an implementation. Therefore, when class A implements an interface, it is not required to implement all methods of that interface because the responsibility of implementing those methods can be deferred to its concrete subclasses.

    Rate this question:

  • 18. 

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

    • A.

      True

    • B.

      FALSE

    Correct Answer
    B. FALSE
    Explanation
    When comparing the objects "a" and "b" using the "==" operator, it checks if the two objects refer to the exact same memory location. In this case, since "a" and "b" are both created using the "new" keyword, they are separate instances and occupy different memory locations. Therefore, the comparison will result in "FALSE" because "a" and "b" are not the same object.

    Rate this question:

  • 19. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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 coordination. When a thread calls the wait() method, it releases the lock on the object and waits until another thread calls notify() or notifyAll() to wake it up. These methods should only be called when the calling thread owns the lock on the object, which is ensured by using synchronized blocks or methods. Calling these methods from unsynchronized code can lead to unexpected behavior and runtime errors.

    Rate this question:

  • 20. 

    Inner classes can be defined within methods

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Inner classes can be defined within methods. This means that a class can be declared inside another class's method. This allows for a more organized and modular code structure, as the inner class can have access to the variables and methods of the outer class. It is useful in scenarios where the inner class is only relevant to the method it is defined in and does not need to be accessed outside of it.

    Rate this question:

  • 21. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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 particular block of code or method at a time. It provides a way to synchronize the execution of multiple threads and prevent potential conflicts or race conditions. By using the "synchronized" keyword, a thread must acquire the object lock before executing the synchronized block, ensuring that other threads cannot access the same block simultaneously. Therefore, the statement that "synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution" is true.

    Rate this question:

  • 22. 

    The default statement of a switch is always executed

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    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 value, the corresponding code block is executed and the switch statement terminates. If there is no default statement, then nothing is executed when none of the cases match.

    Rate this question:

  • 23. 

    How can you prevent a member variable from becoming serialized?

    • A.

      By marking it volatile

    • B.

      By marking it transient

    Correct Answer
    B. By marking it transient
    Explanation
    By marking a member variable as transient, you can prevent it from being serialized. When an object is serialized, all of its member variables are also serialized by default. However, by using the transient keyword, you can specify that a particular member variable should not be serialized. This is useful when the variable contains sensitive or unnecessary data that should not be included in the serialized object.

    Rate this question:

  • 24. 

    What is Java (in regard to Computer Science) ?

    • A.

       A type of coffee

    • B.

      AN OBJECT-ORIENTED PROGRAMMING LANGUAGE

    Correct Answer
    B. AN OBJECT-ORIENTED PROGRAMMING LANGUAGE
    Explanation
    Java is an object-oriented programming language. It is widely used in computer science for developing various applications and software. Java follows the principles of object-oriented programming, allowing developers to create modular and reusable code. It provides features like inheritance, encapsulation, and polymorphism, making it easier to manage and maintain large-scale projects. Java is platform-independent, meaning that it can run on different operating systems without the need for recompilation. It is known for its robustness, security, and scalability, making it a popular choice among developers.

    Rate this question:

  • 25. 

    WHAT IS AN APPLET?

    • A.

      A JAVA PROGRAM THAT IS RUN THROUGH A WEB BROWSER

    • B.

       A type of coffee

    Correct Answer
    A. A JAVA PROGRAM THAT IS RUN THROUGH A WEB BROWSER
    Explanation
    An applet is a small Java program that is designed to be run within a web browser. It is embedded within an HTML page and can be executed by the Java Virtual Machine (JVM) installed on the user's computer. Applets are commonly used to provide interactive features on websites, such as animations, games, or data visualization. They can be downloaded and executed by the web browser, allowing for dynamic and interactive content on web pages.

    Rate this question:

  • 26. 

    Java runs on _______.

    • A.

       Windows

    • B.

      All of the Above

    • C.

       Unix/Linux

    Correct Answer
    B. All of the Above
    Explanation
    Java is a programming language that is designed to be platform-independent, meaning it can run on multiple operating systems. It is not limited to a specific operating system like Windows or Unix/Linux. Therefore, the correct answer is "All of the Above" as Java can run on Windows, Unix/Linux, and other operating systems as well.

    Rate this question:

  • 27. 

    Why can't the whole program just consist of the one line that does the painting ?

    • A.

      In Java, to create an applet, you can't call on functions without defining a class to call them.

    • B.

      The drawString function is not defined without the "import" statements at the top.

    • C.

       All of the above.

    Correct Answer
    C.  All of the above.
    Explanation
    The correct answer is "All of the above." This is because all three statements provided are valid explanations for why the whole program cannot just consist of the one line that does the painting. In Java, to create an applet, a class must be defined to call functions. Additionally, the drawString function is not defined without the "import" statements at the top. Therefore, all three statements contribute to the explanation of why the whole program cannot be reduced to just one line.

    Rate this question:

  • 28. 

    What's the difference between an Applet and an application ?

    • A.

      Applets can paint words, applications cannot.

    • B.

       Applets are run over the web.

    Correct Answer
    B.  Applets are run over the web.
    Explanation
    Applets are small programs that are designed to be run within a web browser. They are typically used to provide interactive content on websites. On the other hand, applications are standalone programs that are installed on a computer and can be run independently of a web browser. Therefore, the correct answer is that applets are run over the web, while applications are not limited to running within a web browser.

    Rate this question:

  • 29. 

    What is the main function of any variable ?

    • A.

       To add numbers together

    • B.

       To keep track of data in the memory of the computer

    Correct Answer
    B.  To keep track of data in the memory of the computer
    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 during the execution of a program. They allow programmers to assign values to specific memory locations, which can then be accessed and modified as needed. By using variables, programmers can store and retrieve data, perform calculations, and make decisions based on the stored information. Variables play a crucial role in the functioning of computer programs by providing a way to store and manage data effectively.

    Rate this question:

  • 30. 

    What is the proper way to declare a variable ?

    • A.

      VariableName variableType;

    • B.

      VariableType variableName;

    Correct Answer
    B. VariableType variableName;
    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 based on its type.

    Rate this question:

  • 31. 

     Booleans are _______.

    • A.

       True or False

    • B.

       Single characters

    Correct Answer
    A.  True or False
    Explanation
    Booleans are a data type in programming that can have one of two values: true or false. They are used to represent logical values and are often used in conditional statements and comparisons. In this case, the correct answer is "True or False" because it accurately describes what booleans are - they can only have the values true or false.

    Rate this question:

  • 32. 

    The following statements make “length” be what number ?

    • A.

       5

    • B.

      6

    Correct Answer
    A.  5
    Explanation
    The question is asking for the number that makes "length" equal to it. The given statements are "5" and "6". Since the answer is "5", it means that when "length" is equal to 5, the statements are true.

    Rate this question:

  • 33. 

    What is an assignment statement ?

    • A.

      Assigning a name to a variable

    • B.

      Assigning a value to a variable

    Correct Answer
    B. Assigning a value to a variable
    Explanation
    An assignment statement refers to the action of assigning a value to a variable. It is a fundamental concept in programming where a specific value is assigned to a variable so that it can be stored and manipulated later in the program. This allows the program to remember and work with data throughout its execution.

    Rate this question:

  • 34. 

    What will be the value of “num” after the following statements?

    • A.

      1

    • B.

      12

    Correct Answer
    B. 12
    Explanation
    The value of "num" will be 12 because the first statement assigns the value 1 to "num" and the second statement assigns the value 12 to "num". Therefore, the final value of "num" will be 12.

    Rate this question:

  • 35. 

     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 ?

    • A.

      &&

    • B.

      !!

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

    Rate this question:

  • 36. 

    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 ?

    • A.

       if ((x < 3) || (y > = 4))

    • B.

       if ((x > 3) || (y < = 4))

    Correct Answer
    A.  if ((x < 3) || (y > = 4))
    Explanation
    The correct answer states 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. This means that if either of these conditions is true, the conditional statement will be executed. The use of the logical OR operator (||) indicates that only one of the conditions needs to be true for the overall condition to be true. Therefore, the correct answer is if ((x < 3) || (y > = 4)).

    Rate this question:

  • 37. 

     What is a loop ?

    • A.

       A new type of Applet

    • B.

       A segment of code to be run a specified amount of times

    Correct Answer
    B.  A segment of code to be run a specified amount of times
    Explanation
    A loop is a segment of code that is designed to be executed repeatedly for a specified number of times. It allows for efficient and repetitive execution of a block of code, eliminating the need to write the same code multiple times. By specifying the number of times the code should be executed, loops provide a way to automate repetitive tasks and make programs more efficient.

    Rate this question:

  • 38. 

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

    • A.

      That there is a Boolean statement somewhere in your code

    • B.

      That your Boolean statement will at some point be false

    Correct Answer
    B. That your Boolean statement will at some point be false
    Explanation
    To ensure that a loop is not infinite, it is essential to have a Boolean statement in the code that will eventually become false. This allows the loop to terminate when the condition specified by the Boolean statement is no longer true. Without this condition, the loop would continue indefinitely, resulting in an infinite loop. Therefore, having a Boolean statement that will eventually be false is crucial for preventing infinite loops.

    Rate this question:

  • 39. 

    Which is NOT a section of all types of loops ?

    • A.

       Test statement

    • B.

       The word "while"

    Correct Answer
    B.  The word "while"
    Explanation
    The word "while" is not a section of all types of loops. The "while" loop is a type of loop that executes a block of code repeatedly as long as a specified condition is true. However, there are other types of loops such as "for" and "do-while" loops that do not include the "while" keyword. Therefore, the word "while" is not a section of all types of loops.

    Rate this question:

  • 40. 

    In a ‘for’ loop, what section of the loop is not included in the parentheses after “for” ?

    • A.

       Loop Body

    • B.

       Initialization

    Correct Answer
    A.  Loop Body
    Explanation
    In a 'for' loop, the loop body is not included in the parentheses after 'for'. The loop body is the section of the code that is executed repeatedly until the loop condition becomes false. The initialization section, on the other hand, is included in the parentheses after 'for' and is used to initialize the loop counter or any other necessary variables before the loop starts executing.

    Rate this question:

  • 41. 

    What is a function in terms of Computer Science ?

    • A.

       A group of code lines that performs a specific task

    • B.

       Something that contains an ‘init’

    Correct Answer
    A.  A group of code lines that performs a specific task
    Explanation
    A function in computer science refers to a group of code lines that are written to perform a specific task. It is a way to organize and encapsulate a set of instructions that can be reused multiple times throughout a program. Functions help in making the code more modular, readable, and efficient by breaking it down into smaller, manageable tasks. They can take input parameters, perform computations, and return output values, allowing for better code organization and reusability.

    Rate this question:

  • 42. 

    What does AWT stands for ?

    • A.

       Abstract window Toolkit

    • B.

       Adjust Window Toolkit

    Correct Answer
    A.  Abstract window Toolkit
    Explanation
    AWT stands for Abstract Window Toolkit. It 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 components such as buttons, labels, text fields, etc., that can be used to build GUI applications. It also includes classes for handling events, layout managers for arranging components, and graphics classes for drawing on the screen. AWT is platform-independent and can be used to create GUIs that run on different operating systems.

    Rate this question:

Quiz Review Timeline +

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

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 31, 2012
    Quiz Created by
    SPACECOMPUTER
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.