Archives: Basics

Java – Enum Example

Example to create Enum in Java

— In Java (from 1.5) an Enum is a special data type that enables for a variable to be a set of predefined constants.
— Keyword ‘enum’ is used to define an Enum.
— Because they are constants, the names of an enum type’s fields are in uppercase letters.



Java – Convert String to Long

Converting String to Long in Java

Output:

String to long conversion using valueOf :2323232
String to long conversion example using Long object: 4444444444444444444
String to long conversion using parseLong() method: 999999999999999999
String to long conversion using decode() method: -1023454
String to long example in hex format decode() method: 65535
String to long example in octal format decode() method: 511


Java – Create Immutable Class

Immutable Class Example in Java

— An immutable class in Java is one whose content can not be changed once created.
— In Java there are many immutable classes like String, Boolean, Byte, Short, Integer, Long, etc.