Posts

Showing posts from June, 2015

How to - Java Interfaces and Abstrac Classes

Today's topic - what is an interface? And what the hell does that have to do with abstract classes? As you can see, we introduce this program not as a class, but an interface. Inside the interface there are methods, which can or can not contain any kind of parameters but the bodies of these methods are empty.  But why would you want that .__. Look at the interface as a kind of blueprint. When you are a contractor and you are supposed to build a whole neighbourhood with 14 houses that look the same (kitchen, 2 bedrooms, 3 baths and a porch) you might not want to sit down at your desk 14 times and draw plans for every single house if they are going to look the same fucking way in the end ._. Sure, you might want to paint one green and the other red - but that can be added later on. So our interface is a blueprint for a type of class that should in the future be used over and over again, with the same kinds of methods in them. Note here: once you implement an interface int

How To - Java Methods

Let's begin with the basics.  In the first post we took a look at the small Program HelloWorld which printed the message Hello World out into our command line. This was a very simple program and with a basic command, but when we write scripts or programs that calculate values, or help sorting stuff we will need methods. We will write a program that calculates the middle value of two fixed values we give the method. Try to read the code and understand what part stands for what: - class name, main method, what is being called in the main method So here again in line 1 we have a public class with the class name MiddleVal for Middle Value, then open brackets to open the class body, line 2 contains the main method (which makes this class autonomous in itself) which also calls out method in the 3. line with 2 parameters that we give to the method. Now we can take a closer look into line 6 - what does the method in line 3 actually do? It's called public static int midd