Fendadis John has Published 98 Articles

How MySQL SUM() function evaluates if it is used with SELECT statement that returns no matching rows?

Fendadis John

Fendadis John

Updated on 22-Jun-2020 05:09:31

When MySQL SUM() function used with SELECT statement that returns no matching rows then there is nothing to evaluate and it returns NULL as output. Sometimes, we thought it must return 0 as output but 0 is a number itself and for no matching rows it not significant to return ... Read More

Generics in Java

Fendadis John

Fendadis John

Updated on 21-Jun-2020 15:13:08

It would be nice if we could write a single sort method that could sort the elements in an Integer array, a String array, or an array of any type that supports ordering.Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of ... Read More

Formatted Output in Java

Fendadis John

Fendadis John

Updated on 21-Jun-2020 15:10:18

String provides format() method can be used to print formatted output in java.System.out.printf() method can be used to print formatted output in java.Following example returns a formatted string value by using a specific locale, format and arguments in format() methodExampleimport java.util.*; public class StringFormat {    public static void ... Read More

Garbage collection in Java

Fendadis John

Fendadis John

Updated on 21-Jun-2020 15:04:53

Java Garbage collector tracks the live object and objects which are no more need are marked for garbage collection. It relieves developers to think of memory allocation/deallocation issues.JVM uses the heap, for dynamic allocation. In most of the cases, the operating systems allocate the heap in advance which is then ... Read More

Generating OTP in Java

Fendadis John

Fendadis John

Updated on 21-Jun-2020 15:00:56

Generate OTP is now a requirement on most of the website now-a-days. In case of additional authentication, system generates a OTP password adhering to OTP policy of the company. Following example generates a unique OTP adhering to following conditions −It should contain at least one number.Length should be 4 characters.Exampleimport ... Read More

foreach in Java

Fendadis John

Fendadis John

Updated on 21-Jun-2020 14:45:45

There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.Programming languages provide various control structures that allow for more complicated ... Read More

Flexible nature of java.lang.object

Fendadis John

Fendadis John

Updated on 21-Jun-2020 14:35:44

The java.lang.Object class is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.Class DeclarationFollowing is the declaration for java.lang.Object class −public class ObjectClass constructorsSr.No.Constructor & Description1Object()This is the Single Constructor.Class methodsSr.No.Method & Description1protected Object clone()This method ... Read More

Floating point operators and associativity in Java

Fendadis John

Fendadis John

Updated on 21-Jun-2020 14:24:45

Following programs shows the float arithmetic can cause dubious result if integer values are used using float variables.Examplepublic class Tester {    public static void main(String[] args) {       float a = 500000000;       float b = -500000000;       float c = 1; ... Read More

Enum in Java

Fendadis John

Fendadis John

Updated on 21-Jun-2020 13:33:36

The java.lang.Enum class is the common base class of all Java language enumeration types.Class DeclarationFollowing is the declaration for java.lang.Enum class −public abstract class Enum extends Object implements Comparable, SerializableClass constructorsSr.No.Constructor & Description1protected Enum(String name, int ordinal)This is the single constructor.Class methodsSr.No.Method & Description1protected Object clone()This method throws CloneNotSupportedException.2int compareTo(E ... Read More

Different ways to print exception messages in Java

Fendadis John

Fendadis John

Updated on 21-Jun-2020 12:48:19

Following are the different ways to handle exception messages in Java.Using printStackTrace() method − It print the name of the exception, description and complete stack trace including the line where exception occurred.catch(Exception e) { e.printStackTrace(); }Using toString() method − It prints the name and description of the exception.catch(Exception e) { ... Read More

Advertisements