Today I’ll be introducing data types in Java programming to you using Abbot & Costello through the Feynman Technique. For more information on the Feynman Technique/20 hour Method, head here.
Java (not JavaScript) is described as a “class-based object-oriented programming language that is designed to have as few implementation dependencies as possible”, per Wikipedia. To put it simply, it’s a bunch of code blocks used to make programs, such as online games, 3D images, banking sites, Android apps, etc.
The operations, or code blocks, come in two basic versions: identifier and expression.
- The identifier is used for names and functions (can only use numbers).
- An expression is used for formulas or strings (don’t use numbers, unless as a word). The words/numbers (as words) are represented within “_”.
In Java, data types identify which types of operations can be done on an identifier or expression. They are listed below:
- Strings (lives inside quotation marks “_”)
- Characters aka char (use single apostrophes, ie. ‘n’ or ‘g’).
- Booleans (True or False)
- Numeric
Samples to try to make this less confusing:
| Sample | Yes/No | Reason |
| 30 + 14 | Yes | identifier, two legit numbers |
| 14 + “Arnold” | No | Can’t mix 2 non-like types |
| “Hola ,” + “amigos!” | Yes | Expression, two legit words within “_”. |
| salary + yearlyBonus | Yes | These are really numbers represented by words. There are no “_”. |
| itemPrice – 10 | Yes | The itemPrice is actually a word that represents a number. |
| “salesDiscount” – itemPrice | No | The salesDiscount isn’t a number, but a “string” (a word), while the itemPrice is actually a number represented by a word. |
Strings in More Detail
Strings are described as a bunch of objects put together in quotations (” “). The difference in numbers vs strings can best be summed up this way: numerically 3+1= 4, however, within strings “3” + “1” = “31”.
I swear this is NOT an Abbot & Costello skit!
Because Java is an “object-oriented” language, it treats anything in quotation marks as just an object, and won’t mix the two. As in the sample above, since “3” and “1” are treated as objects, the “+” only puts them side by side, which is why the objects combined become “31” rather than 4.
When we say that “anything within quotation marks are considered an object”, we mean it. I’ve seen one programmer who used emojis in quotes as an object in their code.
Numeric Subtypes:
Java is rather particular about their numeric types. I realize there’s a lot of overlap here, however when working with numeric types, usually you want to pick the type that best personifies the numeric value you’re seeking to represent. For instance, if you’re looking to work with numbers, no greater than 127, then BYTE, if beyond that, then SHORT is your next choice. For decimal points, FLOAT or DOUBLE would be your go-to. Regardless of options, you do have a choice that best suits your needs and there is forgiveness in the overlap.
- Integral:
- int (integer) = any VALUE between -2,147,483,648 to 2,147,483,647
- long (long integer) = any VALUE between -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
- Floating:
- float – 127 digits AFTER the decimal point.
- double – 1,023 digits AFTER the decimal point
- Byte: any value between -128 to +127
- Short: any value between -32,768 to +32,767
- Char: alphabetic characters representing a numeric value and ASCII
In Java. the information in a string is treated as an array and if you’re familiar with some of the methods that are available for arrays in JavaScript, they are akin to shortcuts in a mac vs. PC, however, they do have minor differences, which I won’t cover here.
As for booleans, they are usually used for comparisons or to turn loops (repeating processes) on/off (true/false values).
…and in the case of the video above, even though the boolean value is False, the damn loop just keeps going and will crash your browser!
For more information on Java, check out these links below:
- W3Schools – Java Introduction
- Geeks for Geeks – Introduction to Java
- IBM Developer – Introduction to Java Programming
Thanks for reading!
Pingback: Java : Variables (Naming, Declaring, and Assigning) | Janifer
Pingback: MySQL: Tables | Janifer
Pingback: JavaScript: Converting & Checking Numbers | Janifer
Pingback: Java: Program Anatomy & Primitive Data Type Application | Janifer