Hi guys,

I'm still quite new to programming and have an exam soon where we have to hand-write programs(no IDE). Never done this before, just you guys all give fantastic guidance, i wanted to see what you all thought. Any general advice would be appreciated!

Theres some small things im unsure of like if you write a small program is it ok to put it all in a public static void main? or should i include method calls in the psvm? or should i not include psvm and use public void main() to call methods?

Also when asked to declare an array is:

int[] numbersArray = {41, 87, 54, 34, 24, 100, 33, 51}

okay ? (i mean i know it works, but is that all that would be expected of you?) I read somewhere that an array should(or has to) always declare how many elements there will be inside. Or is that done here by simply initialising the 8 elements? I've seen an array declared as ...array = new array[12] etc, i really dont understand the difference or why you would do the latter.

Thank you (I know its a bit of a mess, sorry lol)

Dani AI

Generated

Short, practical checklist for handwriting Java in an exam (expanded from the replies by , and ).

Start by reading the question carefully. If it asks for a full program, include a class declaration and the exact JVM entry point public static void main(String[] args). If it asks for a single method, write only that method and state the assumed class/signature. Sketch a brief outline before you write code so you can avoid mid-page insertions (good point from ).

Keep main tiny and clear. For small tasks a single main is acceptable, but better practice is to call helper routines so the grader can see the structure. Two common, easy-to-write patterns:

public class Exam {
    public static void main(String[] args) {
        helper();
    }

    static void helper() {
        // algorithm here
    }
}

or, to use instance methods:

public class Exam {
    public static void main(String[] args) {
        new Exam().run();
    }

    void run() { /* instance logic */ }
}

Arrays: there are two common styles — allocate with a known size (new int[n]) and fill later, or use an initializer at declaration. Use the array property length inside algorithms (never hard-code sizes). When iterating, prefer for (int i = 0; i < arr.length; i++) to avoid off-by-one bugs (echoing ’s point about dynamic sizing).

Handwriting tips that actually score: number lines or blocks, write the skeleton first, put braces even for one-line blocks, use clear names, comment assumptions (input format, bounds), show a short example input/output, and annotate if you omit imports or utility code. If unsure about exact syntax, write a clear, correct algorithm and indicate any small assumptions so graders can award partial credit.

Recommended Answers

All 3 Replies

I.M.H.O.
1. Very tiny programs can go in the main(...) method, but it's far better practice to split programs up into classes and methods and just use main to get them started.
2. Declaring an array like that is absolutely fine. Just check that the following code gets the array size dynamically and does not hard-code the length (in case the declaration changes)
3. You have to declare an array with explicit size eg [12] if you are going to put the data into itr later.

Thats great man thanks.

I had to handwrite my programs during tests in Pascal, very annoying. Though I'd imagine it'd be more annoying for the teacher to grade 30 papers like that. Here's a tip, plan out ahead of time what you're going to write. On paper it's a lot harder to insert a new line in the middle of the page ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.