- Notifications
You must be signed in to change notification settings - Fork0
rishiraj88/JavaCoreSnippets
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
programs and code snippets to showcase the might and versatility of Java platform (as of Core Java API), algorithms implemented using Java language (out of JavaSE), and the types & methods to refer & use in other projects and repositories
First of all, let's have a look at some of the updates and advancements in Java library (aptly called Java API).
- improvement in performance and memory management
- security and cryptography
- modernized Java APIs
- JVM changes
- languages and syntax
- more structured concurrency and threading
- deprecation and "end-of-life"
New features available in Java 21 which we missed in Java 17 and earlier versions. Features, which are most notable and stand as the best candidates for frequent use, are listed below:
- Virtual threads (from Java 19)

- Usage of
recordtypes in conditionals. Very useful withif(reference instance Type)tests.
if(publicParameter instanceof SpecificType) {}- labels for
switchcases. These are very similar toinstanceofchecks.
case TierOne test -> future = test.callActionOne();case TierTwo test -> future = test.callActionTwo();
- String literals (a preview feature) to build parameterized text strings. These are similar to string literals / template strings of modern JavaScript and f-strings of python. The template processor
STRis automatically imported and is available to use without any explicit import or declaration. More template processors includeRAWandFMT. Remember"fmt"of Go (Golang)?
String vmUserName = localSystem.retrieveUserName();String helloVitrualWorld = STR."Hola \{vmUserName}";- One major pathchanger about Java Collection Framework is: the introduction of "sequenced collections":
SequencedCollection,SequencedSetandSequencedMap.
public interface SequencedCollection extends Collection // since 21public interface SequencedMap extends Map // since 21public interface SequencedSet extends SequencedCollection, Set // since 21
- My favorite as it is about security and encryption: Key Encapsulation Mechanism (KEP) to secure symmetric keys.
- TODO: Add updated screenshots
- Implementation examples are in the project code under
Java21APIalong with the checklist of which of the features have been tested.
New features available in Java 17 over Java 14. Features, which are most notable and stand as the best candidates for frequent use, are listed below:
- restore always-Strict floating-point semantics: It ensures same results of floating-point calculations on every platform.
- enhanced pseudo-random number generators: class java.util.Random implements interface java.util.random.RandomGenerator. Such new implementations of pseudo random number generators allow for better support for stream-based programming.
- new macOS rendering pipeline
- macOS/AArch64 port
- deprecate the Applet API for removal
- strongly encapsulate JDK internals
- pattern matching for switch (preview)

- remove RMI activation
- sealed classes
- remove the experimental AOT and JIT compilers
- deprecate the Security Manager for removal
- Foreign Function and Memory API (incubator)
- Vector API (second incubator)
- context-specific deserialization filters
To add the screenshots for Java 17 features to README for quick illustration. Screenshots are already inassets directory.
The additional and formally introduced features available in Java 14. These are the features added to JLS in the versions later to version 11. Most frequently used features are:
- Enhanced
instanceofoperator for safe type conversion: Now useif (obj instanceof String str)instead ofif (obj instanceof String)to get a pre-cooked variablestrof typeString, for example, to utilise inside the concerned code block.
- More explanatory NullPointerException message. Run the super-method
mainofNullPointerExceptionPlusto get:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "java14.RoleClass.getPrivileges()" is nullat java14.NullPointerExceptionPlus.main(NullPointerExceptionPlus.java:7)
- Record as a Type: a smarter tool to fulfill the need of final classes. Example:
record UserRecord(String name, String userId, int pin) {}
- More consice
switch. It returns a value, so it is aptly called a switch expression. Example:
return switch(inputNumber) {case 0 -> "zero";case 1,3,5,7,9 -> "odd";case 2,4,6,8,10 -> "even";default -> "Go take some rest.";};- Text block to assign pre-formatted, with indentation, literal value to a String reference. The value can be supplied without using a reference variable, too. Example:
String strTextBlock = """Das sind die 10 besten Arbeitgeber:innen Deutschlands Platz 1: dm-drogerie markt GmbH + Co. KG Platz 2: Techniker Krankenkasse Platz 3: Ford-Werke GmbH Platz 4: Porsche AG Platz 5: Evonik Industries AG Platz 6: Merck KgaA Platz 7: Bayer AG Platz 8: BMW Group Platz 9: Deloitte Patz 10: Roche Deutschland Holding GmbHUnd diese Arbeitgeber:innen sind f�r Frauen am bestenFazit: Es lohnt sich Firmen-Bewertungen zu checken""";
The nice features available in Java 11 over our good old friend Java 8. Most notable additions are:
- Method
T[] Collection.toArray(IntFunction<T[]> generator )to use instead of first generating a stream and then invokingA[] Stream.toArray(IntFunction<A[]> generator);
- Methods
String Files.readString(Path.of(filePath))andPath Files.writeString(Path.of(strFilePath),"string content", StandardOpenOption).
- Class
java.net.http.HttpClientcapable of making GET, PUT, POST requests easily.

- Running a Java class directly with
javacommand as in$ java MainClass.javawithout generating a.classfile a priori.
- Usage of
varkeyword for variable declaration in lambda expressions:(@Nonnull var a,@Nullable var b) -> System.out.println(a + b)
- Method
Optional.isEmpty()to check if the contained value is null. Its definition straight from Java API is:public boolean isEmpty() { return value == null; }
- A number of new methods foster our most-loved class
java.lang.String. These are:isBlank(),strip(),stripLeading(),stripTrailing(),repeat(intCount)

Code fragments and executable programs testing many variants and conditions with standard language features of Java API. Some of the.java files here are:
- ArrayIntersection.java
- DefaultElementValue.java
- ExceptionsFinally.java
- FindDuplicatesInArrayByMap.java
- FindDuplicatesInArrayByStream.java
- Main.java
- MainInterface.java
- MedianOfTwoArrays.java
- SecondLargest.java
- SingleInArray.java
- StreamCollectMethods.java
- SuperThisChild.java
- ZeroAndNonZero.java
- innerclasses/{InnerClassInitInOuterClass.java}
- stream/{Address.java Customer.java StreamMappingDemo.java}
Guidelines on the preferred usage of major Java 8 features and API methods:
- Java 8 DateTime code samples.md
- Java 8 Functional Interfaces in Java API.md
- Java Concurrency API.md
- Java Stream collector-s methods.md
- PoC implementations of the gists will keep on adding gradually.
About
programs and code snippets to showcase the might of Java platform (Java API and JLS), algorithms implemented using Java language, and types and methods useful for countless projects
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.




