Just a few tidbits of information I reference pretty regularly for anything Java.
Java was the language of choice for all my CS classes in college but my first few career roles had nothing to do with programming except for a contract job using the LAMP stack. The IT side of my financial services roles were mostly .NET.
When I moved to Big Blue I had to refresh my Java knowledge, primarily for a project using IBM Operational Decision Manager (ODM). The IBM ODM rules platform at the time had a couple of ways to create what it called a Business Object Model (BOM) which is essentially a vocabulary of nouns and verbs that can be used to author business rules.
For example – you might have an object called “a Customer” with properties like “name” (String) and “age” (Integer) and “can purchase alcohol” (Boolean). When you wanted to write a rule about that object you could simply write something like:
If the age of the customer is more than 21 then make it true that the customer can purchase alcohol.
The BOM was supported by a Executable Object Model (XOM) which could be sourced from an XML Schema or a library of Java classes.
It was easy enough in Eclipse to create a class with some parameters and Eclipse would automatically create the “getters” and “setters”. Some of the real work came when you had to decide what functionality resided on the Java side as public or private methods and what functionality did you want to add into the BOM.
But either way – I had to refresh my basic Java skills and some of these notes came in handy.
Creating Objects
- Declaration: The code set in bold are all variable declarations that associate a variable name with an object type.
- Instantiation: The new keyword is a Java operator that creates the object.
- Initialization: The new operator is followed by a call to a constructor, which initializes the new object.
Interfaces (“implements”)
• public class UsingClass implements InterfaceClass
• The Interface class InterfaceClass defines a set of empty constants and methods
• The using class UsingClass has to actually define a method body (make the methods do something) for all methods defined in the Interface (in this example InterfaceClass)
• This creates a standard (like an API) for how to engage with the class
Inheritance (“extends”)
• When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class. In doing this, you can reuse the fields and methods of the existing class without having to write (and debug!) them yourself.
• A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass
• public class Bicycle {…..}
• public class MountainBike extends Bicycle {…}
• MountainBike has access to all of the variables and methods of Bike
• MountainBike can use the same method names of Bike (which means MountainBike overrides the Bike method)
• super.methodName() calls the method of the Super Class (the model that was extended)