Java introduction to BigDecimal

BigDecimal represent immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. The BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion. The toString() method provides a canonical representation of a BigDecimal. Why we need BigDecimal? We already have double, … Read more

Java equals() and hashCode()

Difference between comparison and equality check In many cases we have to compare objects. There are different type of comparison. In some cases you need to order (sort) some object based on some rules. Then in Java you can use Comparable and Comparator. In other cases we need to check if the object are logically … Read more

Java introduction String

The String class represents character strings in UTF-16 encoding. All string literals in Java programs, such as “abc”, are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created. String buffers ( StringBuffer and StringBuilder ) support mutable strings. Because String objects are immutable they can be … Read more

Java method overriding

In Java method overriding can exist when there is Parent-Child classes and the child class provide specific implementation of a method that is also present in the Parent class. Chair [ Parent class ] | int weight() [ Method of the Chair class ] | | [Armchair extends Chair] \/ Armchair [ Child class ] … Read more

Java method overloading

In this example we cab see how use method overloading in Java, multiple methods can have the same name in the same class with different parameters. This is possible because methods in Java are distinguished by their method signature. The method signature is the combination of the method name and the parameter list. In Java … Read more

Java introduction int type

One of the Java primitive types is int (integer, whole number) type. You can use it to create variables which can contain positive and negative whole numbers. The range of the int values are from -2147483648 until 2147483647. Example program with some common operations with int: Output:

Java introduction to boolean

One of the primitive data types in Java is boolean. You can create boolean with boolean keyword. This type of variables can only contain true or false as values. This data types are very useful when used with if, while statement which are (decision-making statement with boolean conditions) or when we need to use logical … Read more