• How to do Hello World

    I want to make hello world help please

    2 days ago

    1 reply

  • How Do I Use Java’s Files API To Read an Entire File at Once?

    I want to read the full file contents into a string. Is Files.readString(path) the right method, or do I need something else for large files?

    3 days ago

    1 reply

  • Why Is My Interface Default Method Not Being Called?

    I expected the default method to run, but Java keeps using the overridden version even when I remove it. interface A { default void hello() { System.out.println("Hello from A"); } } class B implements A { // I removed the override but it's still not calling A's method? }

    3 days ago

    0 replies

  • How Do I Prevent Java From Using Old .class Files After Compilation?

    Every time I recompile, Java still runs the old version of my code. How do I clear or correctly configure my build/output directory?

    3 days ago

    0 replies

  • Why Is This Java Stream Not Filtering Correctly?

    The stream should remove odd numbers, but it outputs all numbers unchanged. List<Integer> list = List.of(1, 2, 3, 4, 5); list.stream() .filter(n -> n % 2 == 0) .forEach(System.out::println); But instead of printing 2 and 4, it prints all 5 numbers. Why?

    3 days ago

    0 replies

  • Why Is My Java App Slower on EC2 but Fast Locally?

    My Spring Boot API performs well locally but is noticeably slower after deploying to EC2. curl -w "@curl-format.txt" -o /dev/null -s https://myapi.com/health

    3 days ago

    1 reply

  • How Do I Serialize a Java Object Into JSON Using Jackson?

    I added Jackson to my project, but calling ObjectMapper.writeValueAsString() throws an exception. Do I need getters/setters or annotations?

    3 days ago

    0 replies

  • Why Isn’t My Thread Sleeping Correctly?

    The program should print a message every second, but it prints everything instantly. What’s wrong? for (int i = 0; i < 5; i++) { System.out.println("Tick " + i); Thread.sleep(1000); // Error: Unhandled exception }

    3 days ago

    0 replies

  • Is This Soft Delete Pattern Correct?

    I added an is_deleted column to implement soft deletes. Just want to confirm this approach is correct. ``java @Query("UPDATE Post p SET p.isDeleted = true WHERE p.id = :id") void softDelete(@Param("id") Long id);

    3 days ago

    0 replies

  • How Do I Use a Debugger in IntelliJ To Step Into Methods?

    When I press “Step Into,” IntelliJ skips over third-party library calls. How do I force it to enter external source code?

    3 days ago

    1 reply

  • HTMX Request Reloads Full Page Instead of Fragment

    Trying to update a comment section using HTMX, but the entire page reloads. <div hx-post="/comment/add" hx-target="#comments"></div>

    3 days ago

    0 replies

  • Why Does My HashMap Return Null Even When the Key Exists?

    This should return "John", but I'm getting null. What’s wrong with my HashMap logic? Map<Integer, String> map = new HashMap<>(); map.put(1, "John"); Integer id = new Integer(1); System.out.println(map.get(id)); // prints null

    3 days ago

    1 reply

  • Why Is My @RestController Returning HTML Instead of JSON?

    My API is expected to return JSON, but instead I keep getting an entire HTML page. @GetMapping("/api/user") public UserDto getUser() { return new UserDto("john", 25); }

    3 days ago

    0 replies

  • Why Is My Spring Boot Application Not Restarting Automatically?

    I installed Spring Boot DevTools, but changing my Java files does nothing until I manually restart. Is there something else I need to enable?

    3 days ago

    0 replies

  • Best Way to Loop Through a List in Modern Java?

    There are so many ways to iterate through a list — which one is considered best practice now? List<String> list = List.of("A", "B", "C"); list.forEach(System.out::println);

    3 days ago

    0 replies

  • How Do I Run JUnit Tests From the Command Line?

    I have JUnit tests in src/test/java, but running mvn test doesn’t detect them. Do I need a plugin or a naming convention for test classes?

    3 days ago

    0 replies

  • PostgreSQL “relation does not exist” Error

    I get this exception when launching the app, but the table definitely exists. org.postgresql.util.PSQLException: ERROR: relation "users" does not exist

    3 days ago

    0 replies

  • Why Does This for-loop Not Update My Array?

    This code is supposed to replace negative numbers with 0, but it doesn’t change anything. What’s wrong with it? int[] nums = {-1, 5, -3, 7}; for (int n : nums) { if (n < 0) { n = 0; } } System.out.println(Arrays.toString(nums)); // Still prints negatives

    3 days ago

    0 replies

  • @Autowired Not Injecting My Repository — Why?

    Spring Boot refuses to inject my repository into a service. I don’t know what I’m doing wrong. - Using Spring Boot 3 - No XML config - Tried constructor injection too @Service public class UserService { @Autowired private UserRepository repo; }

    3 days ago

    0 replies

  • How Do You Use Lombok in a Java Project?

    I installed Lombok in IntelliJ, but my project still shows errors on @Getter and @Builder. What steps are required to ensure Lombok works properly with IDEs and Maven/Gradle?

    3 days ago

    0 replies