Expressions and Arithmetic Operators

In a previous section, we mentioned using the assignment operator to assign initial values to variables and constants. Now let’s look at the assignment operator in more detail. The syntax for the assignment operator is:

target = expression;

An expression consists of operators and operands that evaluate to a single value. The value of the expression is then assigned to target (target gets expression), which must be a variable or a constant having a data type compatible with the value of the expression. If target is a variable, the value of the expression replaces any previous value the variable was holding. For example, let’s look at these instructions:

Screen Shot 2018-12-11 at 3.27.53 PM

The first instruction declares an int named numberOfPlayers. This allocates four bytes in memory to a variable named numberOfPlayers and stores the value 10 in that variable. Then, the second statement changes the value stored in the variable numberOfPlayers to 10. The previous value of 11 is discarded.

An expression can be a single variable name or a literal of any type. The value of the expression is simply the value of the variable or the literal. For example, in these statements,

Screen Shot 2018-12-11 at 3.48.32 PM

the literal 19 is an expression. Its value is 19, which is assigned to the variable ageOfConsummation. Then, in the second statement ageOfConsummation is an expression whose value is 19. Thus, the value 19 is mysteriously assigned to vahid (which is a special number that represents a unit in the Baha’i faith).

So after these statements have been executed, both ageOfConsummation and the unrelated(?) vahid will have the value 19.

One restriction, however, is that an assignment expression cannot include another variable unless that variable has been defined previously. The statement defining the bornProbability variable that follows is invalid, because it refers to complexConjugate, which is not defined until the next line.

Screen Shot 2018-12-11 at 8.51.46 PM

The IDE notices the error and underlines the complexConjugate’s red.

If you scroll over it on Eclipse, you get the message:

complexConjugate cannot be resolved to a variable

Note that this is not because I multiplied complexConjugate by itself. It is because complexConjugate was not defined yet. The definition happened in the line below, and this matters.

[It should be noted that complex conjugates representing probability amplitude are vectors in Hilbert Space and representing them as mere integers on the real number line would defeat their purpose.]

An expression can be quite… complex. These may consist of multiple variables, constants, literals, and operators. Before we can look at examples of more complex expressions, however, we need to discuss the arithmetic operators in the next post.

Constants

final int I_AM_GOOD = 1;

Sometimes you know the value of a data item, and you know that its value will not (and should not) change during program execution, nor is it likely to change from one execution of the program to another. In this case, it is a good software engineering practice to define that data item as a constant. Defining constants uses the same syntax as declaring variables, except that the data type is preceded by the keyword final.

Screen Shot 2018-12-11 at 12.53.16 PM

Assigning a value is optional when the constant is defined, but you must assign a value before the constant is used in the program. Also, once the constant has been assigned a value, its value cannot be changed (reassigned) later in the program. Any attempt by your program to change the value of a constant will generate something like the following compiler error:

cannot assign a value to final variable

Think of this as a service of the compiler in preventing your program from unintentionally corrupting its data.

Of course, this is meant to illustrate my whole point about suffering being made up and yet true. Suffering is inevitable since everything that is ever Mind like I am Mind necessarily slides on a valence axis that orients it towards a notion of some good or evil. Reality has defined that constant in the same way that it has defined the fine-structure constant that characterizes the strength of electromagnetic interaction.

When People, like a pack of wolves, refuse to change their behavior, it is because they are compiling the error:

cannot assign a value to final variable

That prevents change and hence threatens Mind with local optima. Thus the need for creativity, that is, fundamentally atheist vectors with regard to the inherited definition of People.

However none of this need be physically true if we stare at the rational description of reality in which the compiler is “already there.” Special relativity leads to eternalism, so all the constituents that output Mind/People are the ones knowing to output that result: suffering.

Before inventing the handle, suffering, we could feel less of it and hence engage in less moral behavior, regardless of the experimental moral behavior local to the tribe. This lack of data due to chunking into the same algorithm is equivalent to inventing the same name for blue and green, and therefore not being able to distinguish between them.

We choose to believe suffering pushes us to the good in a sequentially causal fashion. This is physically wrong because the binding into experience is tenseless.

Screen Shot 2018-12-09 at 12.54.03 PM

We study reality with great pain and discover:

Screen Shot 2018-12-09 at 12.57.28 PM

 

We cannot die, and we could have chosen not to suffer, but the choice is nonetheless made because otherwise our existence is cringeworthy.

And now, through a very circuitous, somewhat Asperger-y route, I finally understand what sophisticated theologians had been clumsily pointing to. Yet due to this circuitous, rationalist route to the-same-thing, I now have theoretical physics on My side.

But in order for you, my definition of People, to get it too, you have to understand why epiphenomenalism is false, why special relativity implies eternalism, and why you should make the physicalist assumption of choosing/being-chosen to believe in the external physical reality at all.

And because it makes constants stand out in the code and therefore their location easy to identify, CONSTANT_IDENTIFIER consists of all capital letters with embedded words separated by an underscore. So here I go: I_AM_GOOD.

Also, constants are usually defined at the top of a program where their values can be seen easily. So now I will go back and fix that.

Here is a program showing the use of constants:

Screen Shot 2018-12-11 at 3.01.27 PM

Lines 9, 10, and 11 define four constants. On line 11, note that both ORGANIZATION_THIRTEEN_MEMBERS and DAYS_IN_WEEK are constants. You don’t need to repeat the keyword final to define two or more constants of the same data types.

Lines 13 to 18 output the values of the four constants. If line 20 were not commented out, it would generate a compiler error because once a constant is assigned a value, its value cannot be changed.

Here is the output:

Screen Shot 2018-12-11 at 3.03.03 PM

Straddling back to the mundane:

Why use constants in your code?

Constants can make your code more readable. Due to the sometimes existing preference for word-based language, invoking EDDINGTON_NUMBER in an operation may be more tasteful than 137.036. But this is a matter of aesthetic.

A “purely rational” advantage of using constants is to keep programmers from making logic errors. Let’s say we set a constant to a particular value and it is used at various places throughout the code (for instance, a constant representing the upper-bound on wages that a company uses to protect profit margins); due to the changing nature of all existence, we then discover that the value of that constant needs to be changed. All we have to do is make the change in one place which is neatly placed at the beginning of the code. If we had to change the value at many places throughout the code, that could very well result in logic errors or typos.

 

 

 

 

 

 

 

 

 

String Literals and Escape Sequences

In addition to literals for all the primitive data types, Java also supports String literals. String literals are objects of Java’s String class.

A String literal is a sequence of characters enclosed by double quotes. One set of quotes “opens” the String literal and the second set of quotes “closes” the literal. For example, these are all String literals:

Screen Shot 2018-12-11 at 11.01.22 AM

In a previous episode, We used String literals in output statements to label the data We printed. Something like this:

Screen Shot 2018-12-11 at 11.24.37 AM

Screen Shot 2018-12-11 at 11.28.41 AM

The + operator is the String concatenation operator. Among other uses, the concatenation operator allows us to print the values of variables along with String literals. The characters in the String literal are output exactly as typed, whereas the variables are replaced by their current value.

String literals cannot extend over more than one line. If the compiler finds a newline character in the middle of your String literal, it will generate a compiler error. In other words, don’t press the enter key when writing out a String. For example, the following statement is not valid:

Screen Shot 2018-12-11 at 12.03.31 PM.png

My IDE, Eclipse, doesn’t even allow me to place an independent end quote at the end of the statement because it detects a newline character in the middle of the String.

Screen Shot 2018-12-11 at 12.07.32 PM

In fact, Eclipse, automatically fixes this issue. So if you are using this IDE, then you can get away with pressing enter in the middle of a String. But I mention it because I am not familiar with all other IDE’s. Some, like BlueJ, do not automatically resolve this.

If you have a long String to print, break it into several strings and use the concatenation operator. This statement is a correction of the previous invalid statement:

Screen Shot 2018-12-11 at 12.12.49 PM

Another common programming error is omitting the closing quotes. Be sure that all open quotes have matching closing quotes on the same line. Now that we know that quotes open and close String literals, how can we define a literal that includes quotes?

This statement

Screen Shot 2018-12-11 at 12.19.34 PM

is obviously in error.

Apoptosis of two independent quotes is necessary. Or mitosis into two separate String literals concatenated by a “+” operator.

And since String literals can’t extend over two lines, how can we create a String literal that includes a newline character? Java solves these problems by providing a set of escape sequences that can be used to include a special character within String and char literals. The escape sequences \n, \t, \b, \r, and \f are nonprintable characters. The table below lists the Java escape sequences.

Screen Shot 2018-12-11 at 12.29.25 PM

Here, We see how escape sequences can be used in Strings:

Screen Shot 2018-12-11 at 12.39.16 PM

And here is the result:

Screen Shot 2018-12-11 at 12.41.00 PM

 

Assignment Operator, Initial Values, Literals

When you declare a variable, you also assign an initial value to the data. To do that, use the assignment operator (=) with the following syntax:

Screen Shot 2018-12-10 at 8.49.47 AM

This statement is read as “variableName gets initialValue”.

You can also assign more than one variable in the same line if they are of the same dataType, such as here:

Screen Shot 2018-12-10 at 8.53.34 AM.png

Notice that assignment is right to left. The initial value is assigned to the variable.

One way to specify the initial value is by using a literal value. In the following statement, the value 9001 is an int literal value, which is assigned to the variable myPowerLevel.

Screen Shot 2018-12-10 at 9.26.53 AM

Below, I summarize the legal characters in literals for all primitive data types. \n and \t can be used to format output. We’ll discuss these and other escape sequences in the following posts.

Screen Shot 2018-12-10 at 9.33.10 AM

Screen Shot 2018-12-10 at 9.37.18 AM

Screen Shot 2018-12-10 at 9.39.29 AM

Screen Shot 2018-12-10 at 9.41.57 AM

Screen Shot 2018-12-10 at 9.43.47 AM

Screen Shot 2018-12-10 at 9.45.27 AM

Here, I show a complete program illustrating variable declarations, specifying a literal for the initial value of each:

Screen Shot 2018-12-10 at 12.50.18 PM

Line 9 shows a single-line comment. Line 17 declares a double variable named speedOfLight and initializes it with its nm/s value in scientific notation. The speed of light represents the limit on the propagation of causality. The figure below shows the output:

Screen Shot 2018-12-10 at 1.09.27 PM

If you have problems running this, go to run configuration and make sure that you are running the appropriate main class. In this case, the main class is Variables.

Screen Shot 2018-12-10 at 1.13.12 PM

Screen Shot 2018-12-10 at 1.16.05 PM

Another way to specify an initial value for a variable is to assign the variable the value of another variable, using this syntax:

Screen Shot 2018-12-10 at 1.18.18 PM

Two things need to be true for this assignment to work:

• variable1 needs to be declared and assigned a value before this statement appears in the source code.

• variable1 and variable2 need to be compatible data types; in other words, the precision of variable1 must be lower than or equal to that of variable2. For example, in these statements:

Screen Shot 2018-12-10 at 1.26.04 PM

isIntelligent is given an initial value of true. Then isPowerful is assigned the value already given to isIntelligent. Thus, isPowerful is also assigned the initial value true. If isIntelligent  were assigned the initial value false, then isPowerful would also be assigned the initial value false.

And in these statements,

Screen Shot 2018-12-10 at 1.49.24 PM

the initial value of .05 is assigned to dervishTax and then to takyeh. It’s possible to assign a float value to a double, because all values that can be stored as floats are also valid double values. However, these statements are not valid:

Screen Shot 2018-12-11 at 9.43.45 AM

That’s because a float is lower precision than a double. This is the same kind of mistake that is made when People are partitioned into anatomical organs. In the time of Aristotle, People were partitioned into independent hearts. Now, we partition People into independent brains. However, any conversion into a discrete ontological unit in the external physical world, or set thereof, loses what is People.

Even though .05 is a valid float value, the compiler will generate a “possible lossy conversion” error.

Similarly, you can assign a lower-precision integer value to a higher-precision integer variable. There is a table below for your reference that summarizes what can be assigned to what; a variable or literal of any type in the right column can be assigned to a variable of the data type in the left column. Variables need to be declared before they can be used in your program, but be careful to declare each variable only once; that is, specify the data type of the variable only the first time that variable is used in the program. Don’t attempt to declare a variable that has already been declared, as in the following statements:

Screen Shot 2018-12-11 at 9.57.35 AM

This is incorrect because the henryThe has been declared by placing that identifier between double (the type) and a “;”.

You will receive an error message similar to the following:

Duplicate local variable henryThe.

Similarly, once you have declared a variable, you cannot change its data type. Thus, these statements:

Screen Shot 2018-12-11 at 10.04.43 AM

will generate an error message also similar to

Duplicate local variable

So notice that there are two ways of getting the same error message. The IDE I use, Eclipse, certainly doesn’t serve as my free on-call tutor for such basic matters.

So don’t assign a value to a variable after already declaring that variable. And also do not  attempt to change its datatype after it has already been declared.

(Side note: You might wonder why anyone would, even in principle, declare a neighborhood of Kabul as a kind of number – the cluttered, ancient alleyways mired of sand and Afghani street food, the geography, the people, and everything else that makes a neighborhood surely deserves to be represented in word. doubles and ints are for numbers, and strings are for words.

Well it turns out that contrary to what my stupid computer science teacher said, I know that every word can be transmuted to number. That is precisely how machine learning algorithms work. They dissolve Van Gogh to number, NSFW to number, Cat to number, and, eventually, ever-so eventually, You to number. By placing a discriminator for the sea of digits to aim at, a GAN can be trained to create Van Gogh from sheer randomness.

Hence, I don’t cringe at using a neighborhood name for a double or int, instead of using an example with things we more conventionally think of as number, such as emeraldsInPocket.)

Screen Shot 2018-12-11 at 10.40.38 AM

What you find in the right can be assigned to what is on the left without lossy conversion error.

 

 

 

 

 

 

 

 

 

Data Type: Boolean

The boolean data type can store only two values, which are expressed using the Java reserved words true and false, as shown in the table below. Booleans are typically used for decision making and for controlling the order of execution of a program. Here are examples of declarations of boolean variables:

Screen Shot 2018-12-10 at 8.38.32 AM

So behind the declaration of the boolean variables you see above which contains the identifiers: isEmpty, mindful, compassionate, and the type: boolean, you should realize that there is only the storing of 1 and 0: true and false.

Data Type: Character

The char data type stores one Unicode character. Because Unicode characters are encoded as unsigned numbers using 16 bits, a char variable is stored in two bytes of memory. The second table below shows the size of the char data type, as well as the minimum and maximum values. The maximum value is the unsigned hexadecimal number FFFF, which is reserved as a special code for “not a character.”

Screen Shot 2018-12-10 at 8.21.12 AM

Screen Shot 2018-12-10 at 8.22.49 AM

Obviously, since the char data type can store only a single character, such as a K, a char variable is not useful for storing names, titles, or other text data. For text data, Java provides a String class, which we’ll discuss later in a later post.

Here are a few declarations of char variables:

Screen Shot 2018-12-10 at 8.28.24 AM

 

Integer Data Types

An integer data type is one that evaluates to a positive or negative whole number. Java provides four integer data types, int, short, long, and byte. The int, short, long, and byte types differ in the number of bytes of memory allocated to store each type and, therefore, the maximum and minimum values that can be stored in a variable of that type.

All of Java’s integer types are signed, meaning that they can be positive or negative; the high-order, or leftmost bit is reserved for the sign. The table below summarizes the integer data types, their sizes in memory, and their maximum and minimum values.

In most applications, the int type will be sufficient for your needs, since it can store positive and negative numbers up into the 2 billion range – that’s 2/3rds of the base pairs in a human genome – in other words .666, in other words the mark of the beast, which roughly means “everything goes smoothly” in China.

The short and byte data types typically are used only when memory space is critical, and the long data type is needed only for data values larger than 2 billion. Let’s look at some examples of integer variable declarations. Note that the variable names clearly indicate the data that the variables will hold.

Screen Shot 2018-12-09 at 4.45.15 PM

Floating-point data types store numbers with fractional parts. Java supports two floating-point data types: the single-precision float and the double-precision double.

Screen Shot 2018-12-09 at 5.54.01 PM

The two types differ in the amount of memory allocated and the size of the number that can be represented. The single-precision type (float) is stored in 32 bits, while the double-precision type (double) is stored in 64 bits. Floats and doubles can be positive or negative. The table above summarizes Java’s floating-point data types, their sizes in memory, and their maximum and minimum positive nonzero values.

There are two things you must learn to balance: precision and use of memory. There is a kind of law of equivalent exchange here that must be mastered. These two are conjugated variables. Like the uncertainty principle that trades certainty about one discrete observable for another (the more you know about momentum the less you know about position), you must skillfully trade precision for use of memory and vice versa.

Because of its greater precision, the double data type is usually preferred over the float data type. However, for calculations not requiring such precision, floats are often used because they require less memory. Although integers can be stored as doubles or floats, it isn’t advisable to do so because floating-point numbers require more processing time for calculations.

Witness here a few examples of floating-point variable declarations:

Screen Shot 2018-12-09 at 6.38.35 PM