CloudBerry

Effective Programming

Java – Use Annotation to create Custom Constraint

Imagine, given a situation where you want to check if a required String field whether has emptied value or not. The simplest way is to use if keyword to check whether a given field which its type is String whether is emptied or null. if (("").equals(userModel.getFirstName())){ ...... } In addition to the above-mentioned method, one... » read more

Java – Arbitrary Number of Arguments – the 3 dots

In some Java codes, you might come across, 3 dots like this: It is known as Varargs. foo(String... values) With varargs, a method, function or even constructor can be passed in an arbitrary number of arguments. Varargs are useful, when developers are not sure how many of a particular type of argument will be passed... » read more

Java – What is Functional Interface

To create a functional interface You may come across codes like this ()->{ System.out.println("Hello World"); }, a bracket first then follow by an arrow, if you have ever written JavaScript before, it is known as arrow function in JavaScript. In Java land this is known as functional interface. To create a functional interface, all you... » read more

JavaScript – Checking against NaN

NaN stands for Not-a-Number in JavaScript. Sometimes when writing JavaScript codes, you might need to check whether a variable is a number or not. For example, you declare a variable foo and assign NaN to the variable, i.e let foo = NaN;. Then you might think checking can be done this way: let foo =... » read more

Java – Pass-by-Value II

Pass By Value Continue from the previous post. We are going to validate and verify whether this statement is true or not, which is Java is always pass-by-value. Business Objects as Arguments Student.java public class Student { private String name; public String getName() { return name; } public void setName(String name) { this.name = name;... » read more

Java – Pass-by-Value I

How Arguments Are Passed in Java No matter reference type or primitive type of arguments, Java is always pass-by-value. Each time a method is invoked, a copy for each argument is created in the stack memory and the copy version is passed to the method. If the original variable type is primitive, then simply, a... » read more

Java – Variable Types Explained

There are 2 types of variables in Java, namely primitive & reference. Primitive Type Primitive-type variables are always stored inside the stack memory. Stack is a memory space that holds method-level variables that are short-lived in addition to references to other objects in the heap. Example of primitive type variables: Data Type Default Value (for... » read more

Java – Unary Operator Prefix and Postfix Operand Explained

Increment/Decrement Unary Operators The beauty of unary operators is that, they require only single operand to get the same result as compare to the arithmetic operators; they perform various operations such as increment(++)/decrement(–) a value by one, negating an expression, or inverting the value of a boolean. Operator Description ++ Increment operator; increments a value... » read more