Author

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

Java – Storing Integer Value of Bit-Mask

In this tutorial, we will guide you how to show an integer’s 1s position on bit level. Example: 26 => {1, 3, 4} Use java.util.BitSet to store, well, a set of bits. Util.java package com.cloudberry.com.my; import java.util.BitSet; public class Util{ public static BitSet fromInt(int num) { BitSet bs = new BitSet(); for (int k =... » read more

JavaScript – How to get response from an asynchronous call

Promise in JavaScript is very handy for asynchronous task such as fetching a URL. Developers who use Promise a lot, often will have to call then() with 1 callback function in it. promise.then((result) => {}); promise.then(function(result){}); Prior to Promise, developers tend to use callback functions to handle asynchronous call in JavaScript. However, callback functions have... » read more