Last active
June 22, 2024 07:43
-
-
Save GoldenStack/2a76d333cf21452e1c4145fffcca568f to your computer and use it in GitHub Desktop.
Hello World: Absolute Pain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is the first line: line number one. */ | |
/* This is the beginning of this Java source file (not to be confused with a Java class file). */ | |
///////////////////////////////////////////////////////////////////// | |
// IMPORTANT NOTE: // | |
// // | |
// Apparently people are skeptical that this was written by hand. // | |
// (See https://goldenstack.net/skeptical.png) // | |
// I promise that this was one hundred percent handwritten. // | |
// // | |
// Check out the version history of this gist - // | |
// I wrote a less verbose version of this an entire year before // | |
// ChatGPT was even released. It's real. I promise. // | |
// // | |
// I also have multiple intermediate versions of this same file. // | |
// // | |
///////////////////////////////////////////////////////////////////// | |
/* | |
File Metadata: | |
Indentation: 4 spaces (no tabulation) | |
Encoding: 8-bit Unicode Transformation Format ( | |
Line Separator: \n | |
IQ Point deficit directly caused by writing documentation: 54 | |
*/ | |
/* | |
The following text is the license that the entirety of this Java source file falls under. In this case, there is not really a | |
license - it falls under "all rights reserved". | |
Copyright 2021-2024 GoldenStack - ALL RIGHTS RESERVED. | |
*/ | |
/** | |
* This is the HelloWorld Java class. This class is intended to print the text "Hello, World" to the console via the instance | |
* method (also known simply as a method) {@link java.io.PrintStream#println(String)} that is a member of the Java class | |
* {@link java.io.PrintStream}, which is obtained by calling {@link System#out}. Note that, although it is possible for | |
* {@link System#out} to be modified, this is irrelevant for this current case, and standard out will still be printed to. | |
* | |
* @author The sole author and producer of the code in this Java source file is GoldenStack, although the idea to create a | |
* class that maintains such a level of verbosity was fabricated by hydrogen (which, conveniently, is an inferior | |
* element to gold). | |
* @version 2.0 (updated in 2024 to include more words and significantly extended diction) | |
* @since 2021-11-3 | |
* @date The current date is Friday, June Twenty First, Two Thousand and Twenty Four. The next (chronologically) complete | |
* lunar eclipse occurs on the date of the Twenty Fifth of March, Two THousand and Twenty Five. | |
* As of the original creation of this paper, the date was Wednesday, November Third, Two Thousand and Twenty One, | |
* and the next (as of the aforementioned date) complete lunar eclipse had been on May Sixteenth, Two Thousand and | |
* Twenty Two, although this has already passed. | |
* @precondition The precondition for this program is the same as the vast majority of other Java programs: that there is, | |
* quite simply, a Java Virtual Machine that functions according to the official Java Virtual Machine | |
* specifications, linked at {@link https://docs.oracle.com/javase/specs/jvms/se8/html/index.html}. | |
* @postcondition The postcondition of this program, explained in a very high-level manner (abstracting away, of course, | |
* the more specific details as to what precisely occurs on the target computer), is that the string of | |
* characters as denoted in "Hello, World", followed by a newline character (\n), have been appended to | |
* the program's standard output stream (STDOUT, or the console) and that the standard output stream has | |
* been flushed and, if relevant, rendered. | |
* @purpose The purpose of the creation of this program is twofold: first (as opposed to "firstly" which is not a word in the | |
* English language), that there is a functional Java Runtime Environment, according to the aforementioned | |
* specification, that is capable of printing text to the standard output stream, but, second, to also provide a | |
* sufficiently detailed explanation of how and why this program functions to aid any particular reader. | |
* @license Please witness the preceding parts of this file to read the license - specifically, as of writing, lines | |
* nineteen through thirty two. | |
*/ | |
// The purpose of the next few lines is to plainly declare the class "HelloWorld" as public. | |
// Although only "public" and "class" are keywords-"HelloWorld" is an identifier-each token has its own important meaning. | |
public // The "public" keyword here denotes that the following class may be accessed from any location; | |
// in other words, there are no restrictions (unlike protected, package-private, and private) as to where the class | |
// can be used. In the Java language, though, the primary class in each file has to be somewhat accessible to outside | |
// users, regardless. | |
class // The "class" keyword here denotes that the following class, already known to be public to other clients, is, | |
// in fact, a class. A class is the only structure that is allowed to be present at this part of the file, at least | |
// at the time of writing, but it must be specified anyway. | |
HelloWorld // The string "HelloWorld" decides the name that the class will take. This class name must be identical to | |
// the name of the file containing it, omitting, of course, the file extension - which must be ".java". | |
// Side note: most identifier restrictions are because of the Java compiler, not the Java Runtime Environment. | |
// Although (with some exceptions) the only characters allowed in identifiers by the Java compiler are | |
// alphanumeric characters, the Java runtime environment supports all UTF-8 characters (as identifiers are | |
// stored in the UTF-8 text encoding) except ".", ";", "[", and "/". This is a very small list of disallowed | |
// characters, allowing names containing spaces, parentheses, most brackets, the percent symbol, and the | |
// well-named octothorpe, as well as emojis. Do note, though, that these will be impossible to use from the | |
// Java language, as they cannot be referred to in normal Java code. | |
// Source: {@link https://web.archive.org/web/20211215193426/https://twitter.com/JornVernee/status/1471200711207796750} | |
{ // This opening curly bracket (also called a curly brace in some contexts) indicates that a block of code will follow. | |
// Using known context, it can be stated that this block must contain a class definition, allowing fields, methods, | |
// functions, variables, subclasses - or even nothing at all. | |
// In the case of this Java source file, though, what follows is the rest of the "Hello, World" program. | |
/** | |
* The following method is intended to append the characters in the string "Hello, World", followed by a newline | |
* character, to the running program's standard output stream. | |
* For more information on how this is done, please read the documentation for the Java class {@link HelloWorld}, | |
* which should be located previously in this file. | |
* | |
* @param args The "args" parameter (short for "arguments", as in the arguments provided to this Java program) indicates | |
* that it requires an array of strings to be passed in. | |
* An array is simply a collection of values of a given type T, where the number of values in the array | |
* cannot change, while the individual elements that are in the array may be changed. | |
* Note that it may not forever be a given that elements in an array may be changed; if the JEP | |
* (Java Development Kit Enhancement Proposal) <a href="https://openjdk.java.net/jeps/8261007"> | |
* https://openjdk.java.net/jeps/8261007</a> is ever fully implemented into a proper Java version, arrays | |
* have the potential to be permanently frozen. This, as of the time of writing, is irrelevant to the current | |
* program's functionality; it simply serves as a notice. | |
* A string (as defined in the Java language) is an array of bytes. Although the API provided by strings | |
* supports every Unicode defined character, they may be encoded internally as either LATIN1 or UTF16. | |
* LATIN1 is intended to provide a fast alternative for strings that have one-byte characters, while UTF-16 | |
* supports every character in the Unicode text standard. Strings may be manipulated, technically, although | |
* this simply returns a copy, leaving the original string unchanged. | |
* @author The sole author and producer of the code in this Java source file is GoldenStack, although the idea to create a | |
* class that maintains such a level of verbosity was fabricated by hydrogen (which, conveniently, is an inferior | |
* element to gold). | |
* @since 2021-11-3 | |
* @date The current date is Friday, June Twenty First, Two Thousand and Twenty Four. The next (chronologically) complete | |
* lunar eclipse occurs on the date of the Twenty Fifth of March, Two THousand and Twenty Five. | |
* As of the original creation of this paper, the date was Wednesday, November Third, Two Thousand and Twenty One, | |
* and the next (as of the aforementioned date) complete lunar eclipse had been on May Sixteenth, Two Thousand and | |
* Twenty Two, although this has already passed. | |
* @precondition The precondition for this program is the same as the vast majority of other Java programs: that there is, | |
* quite simply, a Java Virtual Machine that functions according to the official Java Virtual Machine | |
* specifications, linked at {@link https://docs.oracle.com/javase/specs/jvms/se8/html/index.html}. | |
* @postcondition The postcondition of this program, explained in a very high-level manner (abstracting away, of course, | |
* the more specific details as to what precisely occurs on the target computer), is that the string of | |
* characters as denoted in "Hello, World", followed by a newline character (\n), have been appended to | |
* the program's standard output stream (STDOUT, or the console) and that the standard output stream has | |
* been flushed and, if relevant, rendered. | |
* @purpose The purpose of the creation of this program is twofold: first (as opposed to "firstly" which is not a word in the | |
* English language), that there is a functional Java Runtime Environment, according to the aforementioned | |
* specification, that is capable of printing text to the standard output stream, but, second, to also provide a | |
* sufficiently detailed explanation of how and why this program functions to aid any particular reader. | |
* @license Please witness the preceding parts of this file to read the license - specifically, as of writing, lines | |
* nineteen through thirty two. | |
*/ | |
// The purpose (not to be confused with porpoise) of the documentation assigned to the following few lines of code | |
// is to declare the function (not to be confused with a method [an instance function]) "main", that takes a single | |
// argument of type `String[]` and returns nothing, and is static. | |
// Although there is a mix between keywords, identifiers, and otherwise special or reserved symbols (not including | |
// `const` and `goto`, which are reserved, and thus unusable, in the Java language specification, but are completely | |
// unused in both the actual Java language specification and the actual Java language implementation/runtime), each | |
// token has its own important meaning. | |
public // The "public" keyword here denotes that the following function may be accessed from any location; | |
// in other words, there are no restrictions (unlike protected, package-private, and private) as to where the | |
// function can be used. However, this is not particularly relevant for the entry point (the main function), | |
// as the runtime has the theoretical capability to access it regardless. | |
static // The "static" keyword indicates that the following function is, in fact, a function, and not a method. | |
// This means that it does not require an instance of its containing class (in this case, "HelloWorld"), | |
// in order to be run. Furthermore, it does not have the implicit parameter `this` (with the type of, in this | |
// case, `HelloWorld`) contained within the list of its parameters. | |
void // The "void" keyword used here indicates that there is no return value for this function. This is technically | |
// equivalent to a unit, as this function must return but there is only one possiblity for what it returns: | |
// nothing. This, somewhat intuitively, allows returning from the function with a `return;` statement without | |
// any value, and allows the possibility for not all branches of the function to have an explicit return, as | |
// an empty return is, essentially, implicitly added. | |
main // The string, or token, "main" determines the name of the following function. Although this could be anything, | |
// literally excluding everything that is not a valid identifier and technically excluding everything that contains | |
// ".", ";", "[", and "/" - see the documentation for the "HelloWorld" token for a more in-depth explanation - | |
// the only valid identifier for a static function of this nature that has the capability to be recognized by an | |
// unmodified Java Runtime Environment as an entry point to the Java program is "main". Importantly, though, some | |
// runtimes and IDEs (integrated development environments) may allow running programs with entry points of other | |
// names. | |
( // This opening parentheses character indicates, in this context, that the parameters for the `main` function | |
// must follow. The parameters must be delimited with commas, although it is permitted for there to be no parameters, | |
// and there must, for this Java program to compile, be a pair of closing parentheses. | |
// However, the entry point must have the parameters that follow. | |
String[] // This indicates that the next parameter, in this case the first parameter, in the `main` function is of | |
// the type `String[]`. This is significant because computer programs, generally, have a list of textual | |
// inputs provided to them; this manifests in the Java programming language as `String[]`. | |
// It is also possible to write `String...`, indicating a function with a number of parameters that has a | |
// variable length, which will indeed work as an entry point as well, but this will compile to an array | |
// of strings as well. | |
// An array is simply a collection of values of a given type T, where the number of values in the array | |
// cannot change, while the individual elements that are in the array may be changed. Note that it may not | |
// forever be a given that elements in an array may be changed; if the JEP (Java Development Kit | |
// Enhancement Proposal) <a href="https://openjdk.java.net/jeps/8261007"> | |
// https://openjdk.java.net/jeps/8261007</a> is ever fully implemented into a proper Java version, arrays | |
// have the potential to be permanently frozen. This, as of the time of writing, is irrelevant to the | |
// current program's functionality; it simply serves as a notice. | |
// A string (as defined in the Java language) is an array of bytes. Although the API provided by strings | |
// supports every Unicode defined character, they may be encoded internally as either LATIN1 or UTF16. | |
// LATIN1 is intended to provide a fast alternative for strings that have one-byte characters, while | |
// UTF-16 supports every character in the Unicode text standard. Strings may be manipulated, technically, | |
// although this simply returns a copy, leaving the original string unchanged. | |
args // The token or identifier "args" indicates that the first and only parameter to the `main` function has been | |
// bestowed with the name "args". This, unlike many other naming decisions in creating an entry point to a Java | |
// program inside a Java class, does not have any more naming restrictions than a standard Java identifier | |
// (anything, literally excluding everything that is not a valid identifier and technically excluding | |
// everything that contains ".", ";", "[", and "/" - see the documentation for the "HelloWorld" token for a | |
// more in-depth explanation); if one likes, they would be able to name it "banana". | |
) // This closing parentheses character indicates, in this context, that the list of parameters for the `main` function | |
// is complete; that is, there are no more parameters to be specified. This closing parentheses character is the | |
// counterpart, dual, or converse to the opening parentheses character that began the list of parameters. | |
{ // This opening curly bracket (also called a curly brace in some contexts) indicates that a block of code will follow. | |
// Using known context, it can be stated that the following block must contain a list of ordered statements, or, | |
// because the return type of the `main` function is `void`, nothing. | |
// In the case of this Java source file, though, what follows is a statement that feeds the characters in the string | |
// "Hello, World", followed by a newline character to this Java program's standard output stream. | |
// The following statement (not to be confused with an expression) feeds the characters in the string "Hello, World" | |
// into this Java program's standard output stream. | |
// If this is too hard to understand, I suggest looking at some guides that you can find on | |
// {@link https://www.google.com}. I promise, it's not too hard. | |
System // The token "System" refers to the class {@link java.lang.System}. It's used for accessing the requisite | |
// output streams for feeding textual characters into this program's standard output. | |
. // The token "." indicates access to a member of, in this case, the {@link java.lang.System} class. | |
// Whatever token follows it must be relevant to a member of the aforementioned class. | |
out // The token "out" refers to the output stream that is a member of the `System` class. It's a static variable | |
// assigned to the aforementioned class. This is the PrintStream that can be used to output textual characters. | |
. // This token "." fulfills the same purpose as the previous "." token: it simply accesses a member of the "out" | |
// stream. | |
println // The token "println", with current context, refers to the method `println` stream that belongs to the | |
// `PrintStream` class; it can be called to display a string of characters, along with a newline character, | |
// in the current program's output. | |
( // This opening parentheses character indicates, in this context, that the parameters for the `println` function | |
// must follow. The parameters must be delimited with commas, although it is permitted for there to be no | |
// parameters, and there must, for this Java program to compile, be a pair of closing parentheses. | |
// However, the `println` function requires a parameter to follow. | |
// This is different from the `main` function in that it represents calling a function, instead of defining one. | |
// This has largely different implications, but the parentheses that surround the parameters/arguments help show | |
// how the two are counterparts, or how they're related. | |
"Hello, World" // This code refers to the string literal representing the characters "Hello, World". | |
// This has more semantics than embedding a character array in the compiled file (in the case of | |
// Java, a Java Archive [JAR]) - this is how many other programming languages work, but not | |
// Java. It also doesn't allocate a mutable string on the heap. Instead, Java allocates this | |
// string literal as an immutable string, and considers it within Java's "string pool"; in fact, | |
// if there is already a string literal with this exact content in Java's string pool, no | |
// allocation will be performed. This can be a large optimization in some cases, but it also | |
// leads to excess memory lying around, potentially making the program much more memory | |
// intensive. Furthermore, passwords submitted via user applications, while likely not in danger | |
// of entering the string pool (as they are not literals and strings are rarely interned), still | |
// exist in memory for longer than is desired. It is often safer to use a `char[]` and to zero | |
// the array of characters when needed. | |
// Essentially, this line performs a lot of implicit operations that are of no importance here, | |
// but can often have outside implications. | |
) // This closing parentheses character indicates, in this context, that the list of parameters for the `println` | |
// function is complete; that is, there are no more parameters to be specified. This closing parentheses | |
// character is the counterpart, dual, or converse to the opening parentheses character that began the list of | |
// parameters. In total, one parameter had been provided to the `println` function. | |
; // This semicolon indicates the end of the single statement that is contained within the `main` function. | |
// Apparently, it's quite common for people to forget this, but remembering them as denoting the end of a statement | |
// does tend to help. However, semicolons are not mandatory at the end of, for example, `if` and `for` statements. | |
} // This closing curly bracket indicates that there will be no more statements included within the `main` function. | |
// If you want to replicate this for yourself, try holding the shift key and pressing the key that has the "{" symbol | |
// at the top. If you use a keyboard layout that does not include this, good luck. | |
} // This closing curly bracket indicates that there will be no more components included within the `HelloWorld` class in this | |
// Java source file. After this, only local/private classes are allowed - no public-facing classes are permitted here. If | |
// one attempted to replace this with a closing square bracket, the code would fail to compile. | |
/* The end of this Java source file. Note: there is an empty line after this, so this is not technically the true end of this | |
file. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment