1622948160
A singleton class in Java is defined as that class that has only one object, i.e. only one instance of the class. The restricting of the instance to only one per class helps in coding particular programs that require only one instance of the class. The only instance of a singleton class is given a global point of access.
Singleton class is one of the important design patterns in Java programming. Singleton classes help in limiting resources and optimising them; it is used a lot in database connections or sockets. There are implementation syntaxes for singleton class, and a good developer must know about it. Let us see the implementation of the singleton class in Java.
#software development #java #singleton #singleton in java
1600135200
OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE). It contains the virtual machine, the Java Class Library, and the Java compiler. The difference between the Oracle OpenJDK and Oracle JDK is that OpenJDK is a source code reference point for the open-source model. Simultaneously, the Oracle JDK is a continuation or advanced model of the OpenJDK, which is not open source and requires a license to use.
In this article, we will be installing OpenJDK on Centos 8.
#tutorials #alternatives #centos #centos 8 #configuration #dnf #frameworks #java #java development kit #java ee #java environment variables #java framework #java jdk #java jre #java platform #java sdk #java se #jdk #jre #open java development kit #open source #openjdk #openjdk 11 #openjdk 8 #openjdk runtime environment
1622948160
A singleton class in Java is defined as that class that has only one object, i.e. only one instance of the class. The restricting of the instance to only one per class helps in coding particular programs that require only one instance of the class. The only instance of a singleton class is given a global point of access.
Singleton class is one of the important design patterns in Java programming. Singleton classes help in limiting resources and optimising them; it is used a lot in database connections or sockets. There are implementation syntaxes for singleton class, and a good developer must know about it. Let us see the implementation of the singleton class in Java.
#software development #java #singleton #singleton in java
1620458875
According to some surveys, such as JetBrains’s great survey, Java 8 is currently the most used version of Java, despite being a 2014 release.
What you are reading is one in a series of articles titled ‘Going beyond Java 8,’ inspired by the contents of my book, Java for Aliens. These articles will guide you step-by-step through the most important features introduced to the language, starting from version 9. The aim is to make you aware of how important it is to move forward from Java 8, explaining the enormous advantages that the latest versions of the language offer.
In this article, we will talk about the most important new feature introduced with Java 10. Officially called local variable type inference, this feature is better known as the **introduction of the word **var
. Despite the complicated name, it is actually quite a simple feature to use. However, some observations need to be made before we can see the impact that the introduction of the word var
has on other pre-existing characteristics.
#java #java 11 #java 10 #java 12 #var #java 14 #java 13 #java 15 #verbosity
1624070700
In this tutorial, we’ll take a look at how to declare and initialize arrays in Java.
We declare an array in Java as we do other variables, by providing a type and name:
int[] myArray;
To initialize or instantiate an array as we declare it, meaning we assign values as when we create the array, we can use the following shorthand syntax:
int[] myArray = {13, 14, 15};
Or, you could generate a stream of values and assign it back to the array:
int[] intArray = IntStream.range(1, 11).toArray();
int[] intArray = IntStream.rangeClosed(1, 10).toArray();
int[] intArray = IntStream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).toArray();
To understand how this works, read more to learn the ins and outs of array declaration and instantiation!
#java #how to declare and initialize an array in java #array in java #assign #declare #declare and initialize an array in java
1624097700
Recently I was solving an interesting bug that came down to comparing two Double
variables with equals
method. It looks innocent, what can be wrong with something like firstDouble.equals(secondDouble)
?
The problem here is with how doubles are stored. To fit them into 64bytes (usually) they are rounded.
See the example below:
Double firstDouble = 0d;
for (int i = 1; i <= 42; i++) {
firstDouble += 0.1;
}
Double secondDouble = 0.1 * 42;
System.out.println(firstDouble); // 4.200000000000001
System.out.println(secondDouble); // 4.2
System.out.println(firstDouble.equals(secondDouble)); // false
This inaccuracy is caused by rounding errors.
We need to use a different approach to compare those doubles.
#java #double comparison in java #double comparison #comparisons #double