About the author:

All posts by Terence:

Why an ArrayList cannot contain primitives in Java

Why an ArrayList in Java cannot contain primitives like int, double or char

In Java, an ArrayList is a very convenient object that allows us to create and manage variable-length arrays. However, in Java, an ArrayList also has a weird quirk. You cannot declare an ArrayList that uses Java primitives. Below are a few examples:

import java.util.ArrayList;

public class ArrayListTest {
	public static void main(String[] args) {
		ArrayList<int> intList = new ArrayList<int>();
		ArrayList<double> doubleList = new ArrayList<double>();
		ArrayList<char> charList = new ArrayList<char>();
	}
}
Continue reading
XAMPP phpMyAdmin not accessible in Windows

XAMPP phpMyAdmin is not accessible (in Windows)

XAMPP is a great tool for web developers because it packages a couple of applications used for web hosting into one program, and it allows websites to be tested locally on a computer. Unfortunately, because it links multiple applications together, it is pretty error-prone.

One of the errors that might happen is that you might not be able to access XAMPP’s phpMyAdmin, which provides users with an interface to modify the local SQL database. In this article, we go through the various reasons why this might occur, as well as how you can fix them.

Continue reading
Copypasta HTTP security headers
Image icon by vectorjuice from FreePik

Copypasta HTTP security headers for your Apache website

While I was doing SEO for this blog in the past few couple of days, I’ve come across a set of HTTP security headers I’ve never heard of before. These are a set of HTTP headers that you can deploy on your website(s) to tell browsers how to interact with your site in a variety of situations, and they can help to prevent things like cross-site request forgery or iFrame injection XSS attacks from happening on your site, as well as improve your website(s) SEO score (apparently).

Needless to say, I immediately sought to implement them. If you’re looking for some settings that you can copy and paste right into your own web server, read on further.

Continue reading
XAMPP cannot start on macOS - Cannot calculate MAC address

XAMPP can’t start on macOS — cannot calculate MAC address

If you are running XAMPP on macOS, you may run into a variety of problems that may prevent you from starting the program. One of these problems is an error that says “cannot calculate MAC address” when you try to start the program.

Error starting XAMPP stack
The error message is not very helpful.

If your error message says something else, you may want to check out the other articles on XAMPP for macOS:

  1. XAMPP Apache not starting on macOS
  2. XAMPP MySQL not starting on macOS
Continue reading
CodeLobster IDE, a free PHP, HTML, CSS and JavaScript / TypeScript editor

CodeLobster IDE — A free PHP, HTML, CSS and JavaScript / TypeScript editor for web developers

If you’re just starting your foray into the world of web development, you’re probably wondering what kind of code editor or Integrated Development Environment (IDE) to use. In most other branches of coding, like application or games development, you’re probably only going to deal with 1 or 2 programming languages concurrently. In web development, however, you’re almost always going to be dealing with at least 3 languages concurrently, so it’s going to feel very different from almost any other branch of coding.

Especially if you’re new to web development, having to deal with so many languages in one go (and having to be familiar with the native libraries of each of the languages) can be rather overwhelming, and the developers of CodeLobster IDE seem to understand this very well.

Continue reading
Fixing the e.indexOf is not a function error

Fixing the “e.indexOf is not a function” error on your website

If you have a WordPress site that was built before August 2020 (when WordPress 5.5 decided to stop supporting jQuery Migrate), or if you manage a site that recently weaned off jQuery Migrate, you might run into errors where the parts of your site that run on Javascript stop working.

When you open the Developer tools of your browser (that’s the F12 key for most browsers), you might also see an error message that looks something like this.

Uncaught TypeError: e.indexOf is not a function
    at S.fn.load (jquery.min.js?ver=3.6.0:2:84932)
    at headings.min.js?ver=3.19.4:1:2579
    at headings.min.js?ver=3.19.4:1:2706
Continue reading
Why is calling setters in Java constructors discouraged?

Why is calling setters from constructors discouraged in Java?

In Java, coders are discouraged from calling setter functions in class constructors. Even though doing so can sometimes reduce the amount of repeated code.

Consider the following class:

Unit.java

public class Unit {
	protected int health;

	public Unit(int hp) {
		// Prevents health for being set to 0 or less.
		if(hp <= 0)
			throw new IllegalArgumentException("Health must be more than 0.");
		health = hp;
	}

	public void setHealth(int hp) {
		// Prevents health for being set to 0 or less.
		// Repeat of the code in the constructor.
		if(hp <= 0)
			throw new IllegalArgumentException("Health must be more than 0.");

		health = hp;
	}

}

Instead of doing the check twice across 2 functions to ensure the incoming hp value is correct, it might occur to some coders that we can call the setter within the constructor instead, to reduce the amount of repeated code:

Unit.java

public class Unit {
	protected int health;

	public Unit(int hp) {
		// Prevents health for being set to 0 or less.
		if(hp <= 0)
			throw new IllegalArgumentException("Health must be more than 0.");
		health = hp;
		setHealth(hp);
	}

	public void setHealth(int hp) {
		// Prevents health for being set to 0 or less.
		// Repeat of the code in the constructor.
		if(hp <= 0)
			throw new IllegalArgumentException("Health must be more than 0.");

		health = hp;
	}
}

This, however, is discouraged, because (according to textbooks) setters like setHealth() can be overriden by child classes, creating unexpected or buggy behaviour in these child classes.

Continue reading