Question Authors' Forum

Java questions

 
Picture of Richard Lobb
Java questions
by Richard Lobb - Tuesday, 21 August 2018, 10:05 PM
 

A user emailed me the following questions, relating to Java, which I thought I would answer on the forum. 

Couple of observations:

1) When Check button was pressed for a java_program (Question type), it always expected the class name as prog. Message: Error: Could not find or load main class prog
 
2) Under Java restriction on attempts, I had chose "Full screen pop-up with some JavaScript security". However, the answer window is coming auto text selection preventing the smooth editing. Any way to cancel this automatic text selection?
 
.3) Conducted a sample test for a group of 35 students using Joberserver on i5 Core Desktop with 4GB RAM and 1TB disk. The test was fine. However, not all users pressed "check" at same time instant. Any suggestion on Jobeserver sizing if I try to scale this facility for our entire college, say with 3500 students' simultaneous lab access.
 

(1) Can you show me the code that was being submitted please? I can't replicate the problem. Is that a verbatim quote of the error message?

You can get a message of a vaguely similar form if you submit a program that doesn't match the following perl regular expression:

'/(^|\W)public\s+class\s+(\w+)[^{]*\{.*?public\s+static\s+void\s+main\s*\(\s*String/ms'

That pattern is used to determine what name to give the file before compiling it. It the pattern match fails the program is named prog.java and you should see a warning

WARNING: can't determine main class, so source file has been named 'prog.java', which probably won't compile.

This isn't a totally reliable way to determine the main class name but if people know that's the form of answer expected for a java_program question they should soon get the hang of it. The following program code works fine for me, as an example.

public class Twaddle
{
    public static void main(String[] args)
    {
        System.out.println("Hello world!");
    }
}

(2) I've never used that setting. I just had a quick play and it seemed to work fine for me in Chrome but Firefox did some weird things. Since the problems probably involve some combination of the Ace editor, the particular browser JavaScript engine and the Moodle JavaScript code that provides the functionality, it's almost certainly outside of my control. But you might want to look into using Chrome. The only other suggestion I can make is that you can try turning off the Ace editor (click Customise in the question editing page, then set Input UI to "None" for the student answer). But you then lose all the nice code-editing capabilities of course.

(3) 2500 students submitting code in Java sounds wildly optimistic to me, by a factor of around 10. A single Java compile-and-run of a trivial program takes around 1 CPU sec so you're look at 45 CPU minutes to handle all those students submitting just a single question. I doubt the base Moodle system can handle it either. See this thread for more discussion of this topic.

Richard

Picture of Utpal Das
Re: Java questions
by Utpal Das - Tuesday, 21 August 2018, 11:55 PM
 

(1) main method can be declared in any class that is either of public access or default access. While Coderunner works for a public class, using default class is being an issue. Surprisingly, "class prog" works!



Picture of Richard Lobb
Re: Java questions
by Richard Lobb - Wednesday, 22 August 2018, 11:10 AM
 

If you declare your main class as public, I think you'll find the problem goes away.

Richard

Picture of Utpal Das
Re: Java questions
by Utpal Das - Wednesday, 22 August 2018, 5:14 PM
 

Absolutely. The problem statements can be slightly rephrased: "Write a Java program for ..... Ensure to declare a public class for calling the main method."