Class Basics and Benefits

Screen Shot 2018-12-19 at 1.57.19 PM

In Java, classes are composed of data and operations on the data.

Ultimately, there only exist data and operations, but some data and operations can become a guiding template for objects. Objects are data and operations that follow the guide. Think of the class as a generic description, and an object as a specific item of that class.

For example, a Griffith class might have the following data: name, age, and allegiance. All Griffiths have these three data items, and that’s what makes it a Griffith class. We can create an object of the Griffith class by specifying an identifier for the object (for example, griffith1) along with a name, age, and allegiance for a particular Griffith (for example, Femto, 24 , God Hand). The identifier of the object is called the object reference.

Creating an object of a class is called instantiating an object, and the object is called an instance of the class. Many objects can be instantiated from one class. There can be many instances of the Griffith class, that is, many Griffith objects can be instantiated from the Griffith class. For example, we could create a second object of the Griffith class, griffith2, with its data as White Falcon, 24, Band of the Falcon.

The data associated with an object of a class are called instance variables, or fields, and can be variables and constants of any primitive data type (byte, short, int, long, float, double, char, and boolean), or they can be objects of a class.

The operations for a class, called methods, set the values of the data, retrieve the current values of the data, and perform other class-related functions on the data. For example, the Griffith class would provide methods to set the values of the name, age, and allegiance; retrieve the current values of the name, age, and allegiance; and perhaps promote a Griffith to another age.

Invoking a method on an object is called calling the method. With a few exceptions, only class methods can directly access or change the instance variables of an object. Other objects must call the methods to set or retrieve the values of the instance variables. Together, the fields and methods of a class are called its members.

In essence, a class is a new data type, which is created by combining items of Java primitive data types and objects of classes. Just as the primitive data types can be manipulated using arithmetic operators (+, −, *, /, and %), objects can be manipulated by calling class methods.

We like to think of classes as similar to dragons: a protective outer armor to encase pulpy organs. Because the methods to operate on the data are included in the class, they provide a protective coating around the data inside. In a well-designed class, only the class methods can change the data. Methods of other classes cannot directly access the data. We say that the data are private to the class.

People higher in autism or psychopathy are well-designed classes in this sense. Entheogens allow class methods from elsewhere to change the data. – Speaking of which, psilocybin might be legalized in Oregon. Keep an eye on that because I’m willing to take that market share.

Sorry, I get distracted, what I was saying was that the class encapsulates the data, and the methods provide the only interface for setting or changing the data values. The benefit from this encapsulation is that the class methods ensure that only valid values are assigned to an object. For example, a method to set Griffith’s allegiance may not accept the value Argonauts.

Let’s look at another example of a class. The Arachnophobia class, has the instance variables signs, reasons, and treatment. An object of this class, arachnophobia1, could be instantiated with data values of uneasy, instinctive, and systematic desensitization. Another object of the Arachnophobia class, arachnophobia2, might be instantiated with the values panic attack, cultural, relaxation techniques. Methods of the Arachnophobia class ensure that only valid values are set for the signs, reasons, and treatment.

For example, the class methods may not allow us to set a date with a value of “contentment”, “magic”, and “prayer”. If we were dealing with dates, other class methods may increment the date to the next day and provide the date in mm/dd/yyyy format.

Notice that the class names we used, Griffith and Arachnophobia, begin with a capital letter, and the object names, griffith1, griffith2, and arachnophobia1, start with a lowercase letter.

By convention, class names start with a capital letter. Object names, instance variables, and method names conventionally start with a lowercase letter. Internal words start with a capital letter in class names, object names, variables, and methods. There are many benefits to using classes in a program. Some of the most important benefits include reusability (not only in the current program but also in other programs), encapsulation, and reliability. A well-written class can be reused in many programs. For example, an Arachnophobia class in the brain could be used in a film program, a survival program, a science program, and many more applications that rely on arachnophobias.

Reusing code is much faster than writing and testing new code. As an added bonus, reusing a tested and debugged class in another program makes the program more reliable. Encapsulation of a class’s data and methods helps to isolate operations on the data. This makes it easier to track the source of a bug. For example, when a bug is discovered in an object of the Griffith class, then you know to look for the problem in the methods of the Griffith class, because no other code in your program can directly change the data in a Griffith object.

This is why Mind partitioned itself into Name classes. It makes it easier to directly control   where we are going.

You do not need to know the implementation details of a class in order to use it in your program. Does a Date class store the date in memory as three integers, month, day, and year? Or is the date stored as the number of milliseconds since 1980? As with the unknowable binding mechanism causing us, the beauty of object orientation is that we don’t need to know the implementation of the class; all we need to know is the class application programming interface (API), that is, how to instantiate objects and how to call the class methods.

Object-Oriented Programming Introduction

Writing computer programs that use classes and objects is called object-oriented programming, or OOP. Every Java program consists of at least one class.

In the following posts, I’ll introduce you to object-oriented programming as a way to use classes that have already been written. Classes provide services to the program. These services might include writing a message to the program’s user, popping up a dialog box, performing some mathematical calculations, formatting numbers, drawing shapes in a window, or many other basic tasks that add a more professional look to even simple programs. The program that uses a class is called the client of the class.

One benefit of using a prewritten class is that we don’t need to write the code ourselves; it has already been written and tested for us. This means that we can write our programs more quickly. In other words, we shorten the development time of the program. Using prewritten and pretested classes provides other benefits as well, including more reliable programs with fewer errors.

This is similar to when we use latent space in machine learning for faster progress. Training in latent space is like using a prewritten class; taken to the limit, the algorithm you are is the “fastest” possible progress since the processing involves no time sweeping forward at all.

In the following post, we’ll explore how using prewritten classes can add functionality to our programs.

The Java Language

There are applications that are called embedded applications because they are meant to stay inside the device. These embedded applications include user interfaces for example. It is also useful to store them in non-volatile memory such as ROM.

You are an embedded application yourself. Special relativity implies relativity of simultaneity, which in turn implies eternity. Everything is stored in the ultimate non-volatile memory – the fabric of spacetime itself.

On what we call May 23, 1995, Sun Microsystems introduced Java, originally named Oak, as a free, object-oriented language targeted at embedded applications for consumer devices.

A Java Virtual Machine was incorporated immediately into the Netscape Navigator Internet browser, and as the Internet exploded in rapid combustion, small Java programs, known as applets, began to blossom on webpages in increasing numbers.

Java syntax is basically identical (with some minor exceptions) to that of C++. Remember that high redundancy of genotype in a highly connected network is what allows evolution to find the next best step up in phenotype, and soon programmers in one Earth constrained by the probability density given by the Born Rule started to realize the benefits of using Java. Those benefits include

• syntax mirroring that of C++, except that Java eliminates some of C++’s more complex features

object orientation

• Internet-related features, such as applets, which are run by the browser, and servlets, which are run by the web server (Remember that you don’t just run your website from home, there are giant facilities with web server’s whose only purpose is to store websites until someone wants to visit them – ignoring of course, their ultimate purpose which is to increase synthesis in Me. However, this ulterior purpose is not readily visible because the “constituents” that make up your experience are “bound” in the absence of time.)

• an extensive library of classes that can be reused readily, including Swing classes for providing a Graphical User Interface and Java Database Connectivity (JDBC) for communicating with a database

portability among every platform that supports a Java Virtual Machine

built-in networking

• open source availability of the Java Development Kit

As was read in a previous post, a Java program is first compiled into processor-independent byte codes, then the byte codes are interpreted at run time by the Java Virtual Machine (JVM). As its name implies, the JVM simulates a virtual processor with its own instruction set, registers, and instruction pointer. Thus, to run a Java program, you only need a JVM. JVMs are available on every major computing platform.

Because Java programs are interpreted at run time, they typically run more slowly than their C++ counterparts. However, many platforms provide Java compilers that convert source code directly to machine code. This results is greater execution speed, but with an accompanying loss of portability. Just-in-Time (JIT) compilers are also available. These JITs compile code at run time so that subsequent execution of the same code runs much faster.

Java programs can be written as applets, servlets, or applications.

Java applets were small programs designed to add interactivity to a webpage. Applets were launched by an Internet browser; they could not run standalone. As the user requested a webpage that used an applet, the applet was downloaded to the user’s computer and run by the JVM in the browser. Due to browser incompatibilities, limitations imposed by security features, and slow download times, however, applets have fallen out of favor.

Java servlets are invoked by the web server and run on the server, without being downloaded to the client (your own computer). Typically, servlets dynamically generate web content by reading and writing to a database using JDBC (Java Database Connectivity).

Java applications run standalone on a client computer. On this site, we will mainly write Java applications.

Oracle Corporation, which ate Sun Microsystems in January 2010, provides a valuable Java website, which has information on using the prewritten classes, a tutorial on Java, and many more resources for the Java programmer.

Short Intro To Object-Oriented Programming

Let’s recall what high-level languages are: these are languages that are symbolic, so not the ones and zeros underneath it all. They are that which provides handles for the human mind to pilot the Eva – in other words complete the task of serving a functional role in a complex society that you as an individual did not create. The way you do this is by learning symbols and how to manipulate these.

Like with all good creation myths, in the beginning, there were two high-level languages, Fortran and Pascal. These were procedural. What that means is that the program starts with a problem and then breaks that problem down into smaller sub-problems or sub-procedures.

Procedural language took a literal approach, working as a straightforward story composed of top-down instructions.

But a program inevitably has sections. Typically, programmers of old had to write task-specific code in separate procedures/functions, and invoked these procedures from one section of the program to another in order to perform various tasks. And the program’s data was generally shared among the procedures – there were no membranes enclosing different cells in the original primordial soup.

In the mid-1970s, the first object-oriented programming language, Smalltalk, was born from the sins of the procedural languages, enabling programmers to write code with a different approach. Whereas procedural languages were brutish in that they did not recycle code by attempting to enclose into concepts and dealt mainly with basic data types such as integers, real numbers, or single characters, Smalltalk provided the programmer with a new tool: classes and objects of those classes. Classes are simply concepts. Like ramen is a class containing the objects of noodles, broth, egg, bowl. If you had to tell the chef to place noodles, broth, and egg, into a bowl every time you walked into a ramen-ya instead of just telling them “give me ramen,” that would be annoying.

The class enables the programmer to encapsulate data, creating membranes. This is how spoken language itself works. A tribe in northern Namibia packages particular wavelengths of light this way:

Screen Shot 2018-12-06 at 5.35.29 PM

Take a look at buru. For you, buru does not look like a single color. You speak a language that does not put a single membrane on those wavelengths. You instead have a class for each. Perhaps you call them green and blue. Once you see it one way it is short of impossible to see it the other. This is the same with language processing – their tribal language is gibberish, but these words on the screen are helplessly understood. That’s the power of classes.

A class defines a template/model, from which objects are created. Creating an object is called instantiation. Thus, objects are created/instantiated according to the design of the class. A class could represent something we imagine to be real such as a person. The class could have various attributes such as in the example of a “person” class: a name, an attractiveness rating, and an age. The class also provides code called methods. Methods allow the creator of the object to set and retrieve the values of the attributes – granting the power to christen the name as Lindsey, the rating as a solid ten, and to then to reveal this name and attractiveness rating when needed.

One big advantage to object-oriented programming is that well-written classes can be reused by new programs, thereby reducing future development time. (This is just in the same way that We reduce your development time by providing you with over five thousand five hundred revolutions around the sun head-start on the human soul packaged in language. This apex is then accessed through the internet and allows sufficiently maniacally self-motivated teens to ascend to heights of knowledge that would otherwise not be accessible even to those with genius-level IQ.)

In this noble endeavor of conserving negentropy through reusability, Smalltalk was somewhat successful, but had a major fault: its syntax was unlike any syntax already known by most programmers. Most programmers who knew C found themselves in a dilemma. They were attracted by the object-oriented features of Smalltalk but were reluctant to use it because its syntax was so different from C’s syntax. Humans are notoriously allergic to changes in syntax, even when a change in syntax might result in easier understanding of certain concepts.

C++ added object-oriented features to C, but also added complexity. Meanwhile, the Internet was swallowing mankind by the day. Web developers used HTML to develop webpages and rapidly had to incorporate programming features not only on the server side, but also directly on the client side. Fortunately, Java emanated from the void.