%%
- [[Software Engineering]]
- [[Software Development]]
%%
Java is a programming language created by [[Oracle]] for enterprise-level applications. It is an interpreted language, which means that it requires a VM to interpret and run its code. Its main interesting idea is that of the [[JVM]].
## Key advantages
Java's key feature is the inclusion of the [[JVM]], which gives it some unique advantages (and disadvantages).
### Java is platform-independent.
Java code runs on all machines without any changes. It does this by abstracting away the machine-dependent code into a [[JVM]]. The JVM does introduces another layer of complexity, but it gives Java a modular approach, where the right JVM just needs to be installed on each machine and all machines can run the same code.
## Java is supposed to be "self-regulating": it manages resources for you.
The JVM comes with default allocations of memory, but it also lets you tweak it.
- [[Heap memory]] size: initial heap size (`-Xms`), max heap size (`-Xmx`), Java thread stack size (`-Xss`)
- Claiming heap memory up front might also prevent contention of resources
[[Garbage Collection]] behavior
- minimum percentage of [[Heap memory]] free after GC (`-XX:MinHeapFreeRatio`) - basically a way to control how aggressive GC is
- maximum percentage of heap memory free after GC (`-XX:MaxHeapFreeRatio`) - a limit for the aggressiveness of the GC
Perhaps this feature was more important when virtual machines were more expensive or more difficult to provision, or when many enterprises were using on-premise data centers so they had a limited amount of hardware. However, these days, anyone can just provision a machine on the cloud in a few minutes, so it doesn't make sense to still have this extra layer. Instead, we can just use the native resources of the hardware.
### Java programs make security patching easier
Java effectively separates application code into the part that third-party developers write and the part that Oracle maintains, which is contained in the JVM. An advantage of this approach is that the JVM takes care of all the security-related updates and patching, leaving developers free to write actual application code.
For users, this could also translate to increased security, as they don't have to rely on application developers to manually patch bugs.
## [[Installing Java]]
## Performance
- [[Java performance issues]]
- for all interpreted languages
- can't be compiled down to machine instructions like [[Go]]
- [[Heap memory]] vs Stack memory
- heap not directly accessible AND it has an overhead, so it can be very inefficient
- Java threads currently default to 1MB
- Source: https://www.baeldung.com/jvm-configure-stack-sizes
- This is incorrect, and was based on a faulty assumption. [^dzone] Instead, the memory used is defined by the stack depth.
- [[JMeter]]'s Java implementation of the HTTP Request sampler has limitations - unsure if this is limited to JMeter or if it is a fundamental flaw in Java.: [[Limitations of Java HTTP implementation]]
- [[Simme Aronsson]] thinks Java has poor [[Developer Ergonomics]]
- having to write getters or setters for properties -- boilerplate
- having to hook up Maven/Gradle
-
[^dzone]: Bouda, P. (2019). _How much memory does a Java thread take?_ Retrieved from https://dzone.com/articles/how-much-memory-does-a-java-thread-take . [[How Much Memory Does a Java Thread Take - DZone Java]]