development-programming-language-java.html
* created: 2025-09-21T15:42
* modified: 2025-11-12T17:08
title
Java :|
description
Java is a language you could use.
related notes
Java is a language
Java is a language that promises to run everywhere (that supports the Java runtime). It is a language that has a syntax. It is a language some people use. It is a language I'm not really excited about.
File Structure
Java follows a pretty basic schema, where each class is located in its own files which shares the same name.
Example: public class HelloWorld { ... } would be found in HelloWorld.java
Semantics && Syntax
Java is a object oriented langues, meaning it is based around classes.
Variables
Variables are defined using the type followed by an identifier.
SomeClass myClass;
Assigning a value to a variable is done by the use of the = symbol.
myClass = new SomeClass();
Key words
TODO: labels (break search)
class: define a class
new: instantiate a new instance of a class
public: denotes public visibility
private: denotes private visibility
try: wraps code that might throw an exception
catch: catches the exception thrown in the try block
finally: wraps code that always runs after the try catch block (even if there is a return statement before)
while: loop a code block until a condition is met (evaluates at the beginning)
do: loop a code block until a condition is met (evaluates at the end)
break: interrupt a loop
final: used to declare const values (value cannot be changed)
Primitive datatypes
byte: 8 bit
short: 16 bit integer
int: 32 bit integer
long: 64 bit integer
float: 32 bit floating point (IEEE 754)
double: 64 bit double precision floating point
boolean: true or false
Typecasting
Java allows for safely cast from a smaller space to a larger space without explicit casting.
Example: byte -> short -> int
Operands
+: addition
-: subtraction
*: multiplication
/: division
%: modulo (rest of division)
++: increment by one
--: decrement by one
/=: divide and assign the result
>: larger then comparison
||: logical or (as in either x or y)
Comments
Doc comments contain general information about the program and it's functionality. These can include:
@author
@version
@param
@return
@throws
{@link}
{@docRoot}
Example:
/**
* A Java program.
*
* @author Thomas P. (thomas@example.com)
* @version 1.01, 09/2025
*/
Inline comments are commonly used to provide some context to the reader. Example:
// This implementation is trash.
Arrays
Error handling
Exception
When to throw an Exception:
- The application logic encounters an issue
- You can handle it gracefully (even if "graceful" means printing an error and exiting)
Error
When to throw an Error:
- The JVM runtime system is compromised
- There's nothing reasonable the application can do
Tooling
OpenJDK: The Open Java Development Kit is an implementation of Java Standard Edition. It encompasses tools and library's required to work-on and compile Java projects like:
- javac: The Java transpiler, which is used to compile files with a
.java ending to files with a .class ending. Files with the .class ending get interpreted and executed by the Java runtime.
- java: The Java runtime. To execute a program run
java {ProgramName} ({ProgramName} represents the entry class of the program).
- javadoc: Used to auto-generate HTML-Docs of a given program by referencing the doc comments.