This Java implementation of the number guessing game works similarly to the Python version. Here's a brief explanation of the key differences and Java-specific features:

We use the Random class to generate random numbers and the Scanner class for user input. The game logic is contained within the main method of the NumberGuessingGame class. We use try-catch to handle potential input errors (like non-integer inputs). We close the Scanner at the end of the game to prevent resource leaks.

To run this game:

Save the code in a file named NumberGuessingGame.java. Compile it using a Java compiler (e.g., javac NumberGuessingGame.java). Run the compiled program (e.g., java NumberGuessingGame).