Tag: basic
The goal of this tutorial is to set up a maven and Spring Boot configuration allowing to build and package the project as jar file as well as war file which can be deployed under an application server like Tomcat. Through this tutorial, we will be able to build and . . . Read more
The twin of a word is a word written with the same letters (independent of case), but not necessarily in the same order.For example “Outlook” is the twin of “Lookout”. The isTwin(a, b) method returns true if b is the twin of a or false if it is not. a . . . Read more
1. Difference between JDK and JRE : The JRE is the Java Runtime Environment. It is a collection of everything needed to run a compiled Java program, including the Java Virtual Machine (JVM), Java class library, java command, and other frameworks. However, it cannot be used to create new programs. . . . Read more
In order to compare the values of two strings, we use the equals() method or Objects.equals() method. Objects.equals() checks for null before calling equals() method. While the == operator is used to compare the references of two string objects. Output :
Output :
We consider the sequence of numbers in which a number is followed by the same number plus the sum of these digits. For example 34 is followed by 41 (41 = 34 + (3+4)). 41 is itself followed by 46 (46 = 41 + (4+1)). Two sequences with different starting . . . Read more
Check if a string is composed of parentheses and square brackets recursively in Java The program below identifies a string composed of parentheses ( ) and square brackets [ ]. A string of this type is considered correct : If it is an empty string or null If the string . . . Read more
The main difference between name() and toString() is that name() is a final method, so it cannot be overridden. The toString() method returns the same value that name() does by default, but toString() can be overridden by subclasses of Enum. 1. Using default name method : Output : 2. Overriding . . . Read more
1. Initialize a HashMap : 2. Iterate over keys : 3. Iterate over values : 4. Iterate over both key and value : 5. Full example : Output :
We can convert String to an int in java using Integer.parseInt() method. This method may throw NumberFormatException. We can also convert String into Integer by using Integer.valueOf() method which returns instance of Integer class. This method may throw NumberFormatException.