Core Java interview questions
BigDecimal and Money, Code Reading and Debugging, Code Reading and Refactoring to Objects, Code Reading and State Safety, Code Reading with Collections, Code Reading with Exceptions
473 questions with answers and explanations · 472 flashcards
Questions (page 8 of 10)
- In an e-commerce application, why is it useful to have a method like boolean isEligibleForFreeShipping(double cartTotal)?Multiple choiceMedium
- Which of the following is NOT a valid method declaration in Java?Multiple choiceEasy
- What will the following code output if 'prices' is an empty array?Multiple choiceEasy
- Given a boolean 'isHoliday' and a 'customerType' string, how would you structure an if-else statement to give discounts only on holidays to 'VIP' customers?Multiple choiceHard
- In a large HashMap, what is a potential drawback of all keys having the same hashCode?Multiple choiceMedium
- In the context of Java interfaces, what is a default method?Multiple choiceMedium
- Which of the following is a valid way to declare a double representing a product price?Multiple choiceEasy
- Which loop structure would be most appropriate for applying a discount to each item in a cart when the number of items is unknown?Multiple choiceMedium
- Which Scanner method would you use to read a floating-point number from the console?Multiple choiceEasy
- What is autoboxing in Java?Multiple choiceEasy
- What happens if a class implements two interfaces that have methods with the same signature?Multiple choiceMedium
- Given the code snippet below, what will be the result of the comparison using '=='?Multiple choiceMedium
- Which of the following variable names is best for storing the total amount in a shopping cart?Multiple choiceMedium
- When does a local variable declared inside a method stop existing?Multiple choiceEasy
- Which of the following is a checked exception?Multiple choiceMedium
- Why might you choose 'int' over 'long' for storing the number of items in a small store's inventory?Multiple choiceMedium
- Why does using Integer.valueOf(int) over new Integer(int) matter in practice?Multiple choiceHard
- What do these Integer == comparisons print with and without cache-range values?Multiple choiceMedium
- Why might you choose to use a wrapper type instead of a primitive in a Java domain model?Multiple choiceMedium
- In the expression 'total = (price + tax) * discount;', which part is calculated first?Multiple choiceMedium
- Which code correctly declare a variable to store a product's name?Multiple choiceEasy
- Why is left == right risky when left and right are Integer objects?Multiple choiceHard
- What happens if you try to access a local variable outside its block scope?Multiple choiceMedium
- In an e-commerce application, what can be a consequence of shadowing a local variable by declaring another with the same name in an inner block?Multiple choiceHard
- Why does the following code throw a ClassCastException at runtime? class Payment {} class CreditCardPayment extends Payment {} class CashPayment extends…Multiple choiceHard
- Consider the following code snippet. What is the output of the code?Multiple choiceMedium
- In Java, which of the following is true about method overriding?Multiple choiceMedium
- Which of the following is a reason to prefer using a wrapper type over a primitive type in a Java domain model?Multiple choiceEasy
- Which primitive data type would you use to store the number of products available in stock?Multiple choiceEasy
- Which Java keyword would you use to declare that a method can throw an exception?Multiple choiceEasy
- What happens when you compare two Integer objects using the == operator?Multiple choiceMedium
- Given the following code, which method will be executed when display() is called?Multiple choiceMedium
- Why does the 'throws' keyword in a method signature matter in practice?Multiple choiceEasy
- What will be the value of 'total' after the following code executes? int total = 50; total += 30;?Multiple choiceMedium
- In Java, how can you determine if a product is in stock if its quantity is stored in an integer variable named 'stock'?Multiple choiceMedium
- In an e-commerce application, why might it be problematic to use the same variable name for different purposes in a single method?Multiple choiceHard
- How would you explain a potential pitfall of relying on autoboxing in a loop in an interview?Multiple choiceMedium
- In which case would using a primitive type over a wrapper type be more appropriate?Multiple choiceEasy
- In the context of an e-commerce application, what does the expression '(cartTotal > 100) && (hasDiscount)' evaluate?Multiple choiceMedium
- In a method that calculates discounts for multiple products, why should you avoid using the same variable name for different calculations within nested blocks?Multiple choiceHard
- When recalculating a discount in a checkout system, what is a potential pitfall of reusing the same variable name within nested blocks?Multiple choiceHard
- Why might 'long' be a good choice for tracking the total number of orders in a large e-commerce system?Multiple choiceHard
- Which practice is the safest default for managing variable scope inside methods when calculating the shipping cost?Multiple choiceMedium
- What is one downside of autoboxing in Java?Multiple choiceMedium
- When should a custom exception be created in an e-commerce application?Multiple choiceHard
- Which of the following is a valid declaration for a product's stock quantity in Java?Multiple choiceEasy
- Why is exception propagation important in a Java application?Multiple choiceMedium
- Given the following code, why does it compile and execute successfully? interface Order { void process(); } class OnlineOrder implements Order { public void…Multiple choiceHard
- What happens when a checked exception is not declared or handled in Java?Multiple choiceMedium
- Which wrapper class is NOT immutable in Java?Multiple choiceEasy