Here's an example Java code to query MongoDB for a JSON file for user 'Alexander':

```
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.util.JSON;

public class MongoDBExample {
   public static void main(String[] args) {
      try {
         // Connect to MongoDB
         MongoClient mongo = new MongoClient("localhost", 27017);
         
         // Access database named 'test'
         DB db = mongo.getDB("test");
         
         // Access collection named 'users'
         DBCollection collection = db.getCollection("users");

         // Query for user 'Alexander'
         String query = "{'name':'Alexander'}";
            
         // Find the json document for Alexander
         String json = collection.findOne(JSON.parse(query)).toString();

         // Output the result
         System.out.println(json);
         
         // Close the connection
         mongo.close();
      } catch (Exception e) {
         System.err.println(e.getClass().getName() + ": " + e.getMessage());
      }
   }
}
```

This example uses the MongoDB Java Driver to connect to a local MongoDB instance, access the 'test' database, and query the 'users' collection for a user named 'Alexander'. The result is printed to the console.

Note that the query is passed as a string parameter to the `findOne()` method, and is parsed using the `JSON.parse()` method. This allows you to construct arbitrary queries as JSON strings, which is a useful feature when querying MongoDB from Java.
Scrivi un programma Java per interrogare mongoDB per un file json per l'utente &quot;Alexander&quot;.