In Java, a variable declared within a method is referred to as a ________ variable.

  • Global
  • Instance
  • Local
  • Static
In Java, a variable declared within a method is referred to as a "Local" variable. Local variables are defined within a method and are only accessible within that method's scope. They are used for temporary storage and are typically used to store intermediate results or data specific to a method.

Which arithmetic operator is used to calculate the remainder in JavaScript?

  • % (Modulus)
  • / (Division)
  • * (Multiplication)
  • + (Addition)
In JavaScript, the % (Modulus) operator is used to calculate the remainder of a division operation. For example, 7 % 3 equals 1 because when 7 is divided by 3, the remainder is 1.

The main difference between a function expression and a function declaration is the function _________.

  • Hoisting
  • Scope
  • Expression
  • Name
The main difference between a function expression and a function declaration is the function name. Function declarations have a name, which is used to call the function, while function expressions may or may not have a name, depending on whether they are named or anonymous functions.

Which method is preferred to loop through an array in ES6 and onwards?

  • for loop
  • for...in loop
  • forEach method
  • while loop
In ES6 and onwards, the preferred method to loop through an array is the forEach method. It provides a concise way to iterate over array elements and execute a function for each element. The for loop and for...in loop are less commonly used for iterating arrays, and the while loop is a general-purpose loop that can be used but is not specifically designed for array iteration.

How does the Factory pattern differ from the Constructor pattern in object creation?

  • Factory Pattern allows object creation without using constructors, Factory Pattern can return different object types, Factory Pattern promotes loose coupling.
  • Constructor Pattern is limited to creating objects of a specific type, Constructor Pattern enforces the use of classes, Constructor Pattern promotes tight coupling.
  • Factory Pattern encourages object creation via constructors, Factory Pattern enforces the use of classes, Factory Pattern promotes tight coupling.
  • Constructor Pattern allows object creation without using constructors, Constructor Pattern can return different object types, Constructor Pattern promotes loose coupling.
The Factory pattern allows object creation without using constructors, making it more flexible as it can return different object types. It promotes loose coupling between the client and created objects. In contrast, the Constructor pattern is limited to creating objects of a specific type, enforces the use of classes, and can lead to tight coupling.

Which of the following accurately describes how a block-scoped variable behaves outside of its block?

  • It is accessible outside the block.
  • It is undefined outside the block.
  • It retains its value outside the block.
  • It causes a syntax error if accessed outside the block.
Block-scoped variables in JavaScript are not accessible outside of their block. They have limited scope to the block they are declared in, and attempting to access them outside of that block results in an "undefined" value. This behavior helps prevent unintended variable conflicts and maintains better code isolation.

You’re working on a web application where you need to ensure that the created object removes its resources such as network connections before the creation of a new object. Which design pattern would you apply to ensure this?

  • Dispose Pattern
  • Singleton Pattern
  • Builder Pattern
  • Factory Pattern
To ensure that an object removes its resources before creating a new one, you would apply the Dispose Pattern. The Dispose Pattern is commonly used to release resources explicitly, like closing network connections, files, or database connections, when they are no longer needed. It helps prevent resource leaks and ensures efficient resource management.

How is a method in a JavaScript object typically defined?

  • Using the let keyword
  • As a variable within a function expression
  • As a named function within the object
  • By using the new keyword
A method in a JavaScript object is typically defined as a named function within the object. These functions are associated with the object and can be invoked using dot notation. Methods allow objects to encapsulate behavior, making them a key aspect of object-oriented programming in JavaScript.

What is the primary difference between Runnable and Callable interfaces?

  • Callable can be scheduled for future execution.
  • Callable can run without being wrapped in a thread.
  • Runnable allows returning a result.
  • Runnable can be used for multi-threading.
The primary difference between Runnable and Callable interfaces is that Callable allows you to return a result from the computation, whereas Runnable does not. Callable is typically used when you need a result from a task that can be scheduled for future execution, while Runnable is a simple interface for a task that does not return a result.

The ________ method in the Stream API returns an equivalent stream that is sequential.

  • filter
  • map
  • parallel
  • sequential
In the Stream API of Java, the sequential() method is used to return an equivalent stream that is sequential in nature. This method can be useful when you want to ensure that subsequent operations on the stream are executed in a sequential order.