<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Academic Writing Tips]]></title><description><![CDATA[Academic Writing Tips]]></description><link>https://danielf09.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6ab7b00693ff1d68fc34c559/ba8658cc-45e2-4d48-968c-40686862ff17.png</url><title>Academic Writing Tips</title><link>https://danielf09.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Sun, 01 Nov 2026 11:05:37 GMT</lastBuildDate><atom:link href="https://danielf09.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Common Java Errors Beginners Make and How to Fix Them]]></title><description><![CDATA[Nine common Java errors beginners hit, from cannot find symbol to NullPointerException, with the code that causes each one and a simple fix.]]></description><link>https://danielf09.hashnode.dev/common-java-errors-beginners-make-and-how-to-fix-them</link><guid isPermaLink="true">https://danielf09.hashnode.dev/common-java-errors-beginners-make-and-how-to-fix-them</guid><category><![CDATA[Java]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[Programming Tips]]></category><category><![CDATA[debugging]]></category><category><![CDATA[Study ]]></category><category><![CDATA[education]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[danielfoster]]></dc:creator><pubDate>Mon, 19 Oct 2026 08:59:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ab7b00693ff1d68fc34c559/3bb8a722-619a-4e96-92e4-21db73ee235c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Ask someone who has just finished their first Java module what they remember most, and a surprising number will say the red text. Not the syntax or the lectures, but the wall of error messages that appears at 11pm the night before a submission. Most of those errors aren't exotic. A small set of them accounts for the bulk of what beginners run into, they turn up in almost the same form every year, and each one has an ordinary cause once you know how to read the message. The real problem is that compiler messages are written for people who already understand the issue, so they feel hostile when you don't. Students who search for <a href="https://primeassignmenthelp.co.uk/Java-Assignment-Help/">Java programming assignment help</a> tend to say the same thing: they could fix the bug if someone would just explain what the compiler meant. So this post goes through nine of the most common ones, showing the message, the code that triggers it, and the fix. Everything here runs on a plain JDK, no frameworks needed.</p>
<h2>Read the error before you change anything</h2>
<p>Java errors come in two flavours. Compile errors appear before the program runs and come with a file name and line number. Runtime exceptions appear while the program is running and come with a stack trace.</p>
<p>One rule saves a lot of time: fix only the first compile error, then compile again. A single early mistake, like a misspelled variable, can trigger a whole list of errors further down that disappear on their own once the first one is gone.</p>
<h2>1. cannot find symbol</h2>
<pre><code class="language-text">error: cannot find symbol
  symbol:   variable totl
</code></pre>
<pre><code class="language-java">int total = 0;
for (int i = 0; i &lt; 5; i++) {
    totl += i;
}
</code></pre>
<p>Java can't find anything called <code>totl</code>. Nine times out of ten it's a typo. The other usual causes are using <code>string</code> instead of <code>String</code>, writing <code>system.out</code> in lowercase, or declaring a variable inside a loop or <code>if</code> block and then using it after the block has closed. Variables only live inside the braces where they were created.</p>
<p><strong>Fix:</strong> correct the spelling or move the declaration to a wider scope.</p>
<h2>2. incompatible types: possible lossy conversion</h2>
<pre><code class="language-text">error: incompatible types: possible lossy conversion from double to int
</code></pre>
<pre><code class="language-java">double price = 19.99;
int rounded = price;
</code></pre>
<p>Java refuses to squeeze a <code>double</code> into an <code>int</code> silently because the decimal part would be lost. You have to say you meant it.</p>
<pre><code class="language-java">int truncated = (int) price;               // 19
int rounded = (int) Math.round(price);     // 20
</code></pre>
<p>Note that the cast just chops the decimals off. If you wanted normal rounding, use <code>Math.round</code>.</p>
<h2>3. missing return statement</h2>
<pre><code class="language-java">static String grade(int mark) {
    if (mark &gt;= 70) {
        return "Distinction";
    } else if (mark &gt;= 40) {
        return "Pass";
    }
}
</code></pre>
<p>The compiler looks at every possible path through the method. If a mark of 30 gets in, no branch returns anything, so it stops you. It doesn't matter that you "know" the mark will always be valid.</p>
<p><strong>Fix:</strong> end with a branch that covers everything left.</p>
<pre><code class="language-java">    } else {
        return "Fail";
    }
</code></pre>
<h2>4. variable might not have been initialized</h2>
<pre><code class="language-java">int total;
if (scores.length &gt; 0) {
    total = scores[0];
}
System.out.println(total);
</code></pre>
<p>Same logic as the missing return. If the <code>if</code> condition is false, <code>total</code> never gets a value, and Java won't let you read a local variable that might be empty.</p>
<p><strong>Fix:</strong> give it a starting value where you declare it, <code>int total = 0;</code>.</p>
<h2>5. Comparing strings with ==</h2>
<p>This one doesn't produce an error message at all, which is why it's so annoying.</p>
<pre><code class="language-java">Scanner sc = new Scanner(System.in);
String answer = sc.nextLine();

if (answer == "yes") {
    System.out.println("Confirmed");
}
</code></pre>
<p>You type <code>yes</code> and nothing happens. The <code>==</code> operator checks whether two variables point at the same object in memory, not whether the text matches. It sometimes appears to work with hard-coded strings because Java reuses identical literals, which makes the bug look random.</p>
<pre><code class="language-java">if ("yes".equals(answer)) {
    System.out.println("Confirmed");
}
</code></pre>
<p>Putting the literal first also means a null <code>answer</code> won't crash the comparison. Use <code>equalsIgnoreCase</code> if capitals shouldn't matter.</p>
<h2>6. ArrayIndexOutOfBoundsException</h2>
<pre><code class="language-text">Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
</code></pre>
<pre><code class="language-java">int[] marks = {62, 71, 58};
for (int i = 0; i &lt;= marks.length; i++) {
    System.out.println(marks[i]);
}
</code></pre>
<p>An array of length 3 has valid positions 0, 1 and 2. The <code>&lt;=</code> lets the loop run one step too far. The message even tells you the bad index and the real length, so read both numbers.</p>
<p><strong>Fix:</strong> use <code>i &lt; marks.length</code>, or skip the index altogether with <code>for (int mark : marks)</code>.</p>
<h2>7. NullPointerException</h2>
<pre><code class="language-java">Student[] group = new Student[3];
System.out.println(group[0].getName());
</code></pre>
<p><code>new Student[3]</code> creates three empty slots, not three students. Calling a method on an empty slot is what throws the exception. The fix is to create the object first, <code>group[0] = new Student("Aisha");</code>. If you want to see how to work through the trace line by line, there's a longer walkthrough on <a href="https://writeupcafe.com/how-to-fix-a-nullpointerexception-in-java-without-just-guessing">reading a NullPointerException stack trace</a> that goes through the common causes.</p>
<h2>8. Scanner skipping a line of input</h2>
<pre><code class="language-java">Scanner sc = new Scanner(System.in);
System.out.print("Age: ");
int age = sc.nextInt();
System.out.print("Name: ");
String name = sc.nextLine();
</code></pre>
<p>The program jumps straight past the name prompt and <code>name</code> comes back empty. When you type <code>21</code> and press Enter, <code>nextInt()</code> takes the number but leaves the Enter keypress sitting in the buffer. Then <code>nextLine()</code> reads that leftover and returns immediately.</p>
<pre><code class="language-java">int age = Integer.parseInt(sc.nextLine());
String name = sc.nextLine();
</code></pre>
<p>Reading everything with <code>nextLine()</code> and converting afterwards avoids the problem for good.</p>
<h2>9. Integer division giving 0</h2>
<pre><code class="language-java">int passed = 7;
int total = 9;
double rate = passed / total;
System.out.println(rate);   // 0.0
</code></pre>
<p>Both sides are <code>int</code>, so Java does the division as integers and throws away the remainder before the result ever reaches the <code>double</code>. The type on the left of the <code>=</code> doesn't change how the right side is calculated.</p>
<pre><code class="language-java">double rate = (double) passed / total;   // 0.7777777777777778
</code></pre>
<h2>Quick reference</h2>
<table>
<thead>
<tr>
<th>Message or symptom</th>
<th>Usual cause</th>
<th>Quick fix</th>
</tr>
</thead>
<tbody><tr>
<td>cannot find symbol</td>
<td>Typo or wrong scope</td>
<td>Check spelling and where the variable was declared</td>
</tr>
<tr>
<td>lossy conversion</td>
<td>double assigned to int</td>
<td>Cast, or use Math.round</td>
</tr>
<tr>
<td>missing return statement</td>
<td>A path with no return</td>
<td>Add a final else or return</td>
</tr>
<tr>
<td>might not have been initialized</td>
<td>Variable only set inside an if</td>
<td>Give it a starting value</td>
</tr>
<tr>
<td>String comparison never true</td>
<td>Using == on strings</td>
<td>Use .equals()</td>
</tr>
<tr>
<td>ArrayIndexOutOfBounds</td>
<td>Loop runs one step too far</td>
<td>Use &lt; instead of &lt;=</td>
</tr>
<tr>
<td>NullPointerException</td>
<td>Object never created</td>
<td>Construct it before use</td>
</tr>
<tr>
<td>Scanner skips input</td>
<td>Leftover newline</td>
<td>Read with nextLine() and parse</td>
</tr>
<tr>
<td>Result is 0.0</td>
<td>Integer division</td>
<td>Cast one side to double</td>
</tr>
</tbody></table>
<h2>The habit that helps more than any single fix</h2>
<p>Most beginners read the error as "something is wrong somewhere" and start editing. The message nearly always gives you a file, a line number and a specific complaint. Read those three things out loud before touching the keyboard. After a few weeks the common errors stop feeling like errors and start feeling like labels, because you'll recognise the pattern before you've finished reading the line.</p>
<p>It also helps to change one thing at a time and recompile. If you fix three things at once and the program works, you won't know which change mattered, and next time the same bug appears you'll be guessing again. That read-first habit is also how Java support at <a href="https://primeassignmenthelp.co.uk/">Prime Assignment Help</a> tends to approach debugging with students, going through the message and the line number before touching any code.</p>
]]></content:encoded></item></channel></rss>