Java Development

Categories
j4va development

Check out the Development tag for another article on Java.

While most of this site is about exploiting Java, remember that exploiting Java sometimes requires advanced knowledge of Java. Let's take a quick look at a snippet of code.

class j4vaThrow
{

	void printJohn()
	{
		String name = "Peter";
		String age = "48";

		String description = name + " is " + age + " years old.";
		System.out.println("result:" + description);
		throw new RuntimeException("It was a bad idea.");		
	}

	// public 

	public static void main(String [] args)
	{
			j4vaThrow a = new j4vaThrow();
			a.printJohn();
	}

}

Runtime Exceptions have a specific use. Unlike normal exceptions, Runtime Exceptions don't need to be caught. Looking the documentation, we can see that NullPointerException is a subclass of RuntimeException. That means that if you set a variable to null and then call a method, you get a NullPointerException and the compiler won't complain about it. Why do we care about this? There's a great article here about Java Anti-Patterns.