Skip to content

Java – and more on Java and a bit more…

August 24, 2011

Java – the kingpin of computer programming languages, at least by usage %.  This is a popular usage tool that supports this idea.  In the interest of staying relevant, fresh and sharp, i have been working in Java over the past couple months.  I am reminded of a few things along the way.  First, even though I do not need to practice and learn Java for any current projects, i may in the future.  This is called planning, not sitting idlely when i have time, but rather pushing the envelope a bit, lighting a fire beneath my own feet.  I do not need someone to tell me to do this, i just DO IT.

Java – In my job, i support on-line courses.  I ran across a Java course and starting taking the course as a student.  Why not? its a semester long course that i have taken over a couple weeks.  The concepts are the same as other languages, control structures, data structures, error trapping, data types, OO (inheritance, encapsulation, polymorphism, abstraction) are also the same.  What is NOT the same is the implementation or syntax.

Its take time, lots and lots of it to grok this stuff.  I have been working for years as a programmer and have grokked a lot of stuff, but there is a lot of stuff I have not grokked (Grok = really understanding something to a deep expert level).

Probably one of the things i have grokked over the years is to not worry about memorizing syntax, since you can look it up.  Rather, understand what the existing design patterns are for commonly occurring problems.  I have also grokked the beauty of the MVC design pattern when dealing with large applications.  Separate the “concerns” of a program into these three entities and you will have a maintainable, extensible application.

Back to Java. Additional thought as they come into my head while typing.  As i have been creating lots of little Java programs i am reminded that Java can run on any computer that has a JVM installed on it.  Most Windows computers have a JVM, so any compiled java code can run on it.  No need to add any annoying variables, like classpath to the system. just run your class that has the main method in it and away it goes.  To develop java applications, you do need a compiler, which probably needs to be downloaded and installed on your computer.  Look for what is called a JDK (java developer kit).  This *kit, includes a compiler that is needed to convert your Java source code into bytecode.

Think of classes as little individual blue prints for future objects.  Think of inheritance as the way you can define characterists just ONCE for many slightly different implementations of your objects.  Think of all those zombies that act very similar, the way they spawn, the way they move, run, growl, hit and are hit.  All these behaviours/characteristics are probably defined in a base or super class that slightly different types of zombies extend.  For that matter, think of any monster or villane in your fav. game and they all are derived from a shared class.  If a creature has unique attributes, they are encapsulated into a more specific class.

Think of those creatures and how they do different things depending on other things that may have happened during game play. Java allows you to overload a method signature while creating different behavior, depending on how that method is called.  This is polymorphic behavior.

Let me come back to the surface a bit, and stick to some simpler concepts.

Java is so very case sensitive.

Don’t copy and paste code, as appealing as it may seem, you will end up fixing syntax bugs when you compile because you wont look critically enough at the code you are copying/pasting.  Not to mention that if you are copy/pasting code, it probably means you should push it UP the hierarchy tree to a more base or parent class and let the classes that you are copy/pasting in extend or inherit from it.

Some classes are what i will call driver classes, or main classes or entry way classes.  They are the class that contains the main method, the main static method.  Static because this class will not be instantiated like the other classes.

the non-main classes or most classes should then have a constructor class, which shares the class name.  IE, if the class is named Bob, then the constructor method is also called bob – noting the difference between the case.  That’s following best practices of class definitions Uppercase, while methods are lower.

The main static class is the one where other objects are created.  In Java that very common method is always this:

public class Somename{

public static void main(String[] args){



Its a best practice to only create a single class per file.  This means you will have a lot of small individual .java files once everything is compiled.  This is a best practice not a dictum *we don’t like those too much. For a project them, expect to see a bunch of files and a bunch of matching Classname.class files once they all compile, in the same folder or directory.  This is common stuff.  When you want to use the class(s) think of them as a package.

A package is a common Java convention or entity that allows you to organize and import as a group, when needed.

Think of Java as a vast collection of a bunch of little classes that have relationships with each other.  The packages are used to help organize the classes into related groups.  The API is a face to that collection of classes.  When you build a program, the more complex it becomes the more you will rely on using existing classes to handle alot of the work.  Some of the common functionality are contained in the Java core, meaning you do not have to import files into your class.

When you DO have to import files into you class, it goes FIRST.  Like this:

import java.util.*;

public class Someclass{





Other people will want to look at your classes and may want to use them.  This means they will want to know what your class does and how to speak to it, what kind of data does it require to do the work being advertised.  This is another hallmark of good OO design using Java, the concept of hiding the implementation of your class behind an interface.  The person looking or browsing the classes probably DOES NOT CARE ABOUT HOW THE WORK IS DONE, but does care about what they have to do to use it.  When you build an interface to your class, you are providing a window into your class that people can look to see how to speak to and what to say.  The interface, which is a type of class, does not contain only details, only the names of methods that exist in your class and the types of data they require to do their work.  This use of interfaces accomplished data hiding or abstraction.  The implementation details are abstracted away.




From → Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: