Category Archives: Java Basics

Factorial of Large Number in Java

It is not possible to store factorial for large number like 50 into inbuilt data types like integer or long. Because factorial of 50 has almost 60 digits. Imagine how we can store it in int or long. We can find factorial of such numbers using BigInteger class defined in java.math package.  Below program shows… Read More »

Program to Convert Binary to Decimal in Java

Here you will get program to convert binary to decimal in Java. There are mainly two ways to convert a binary number to decimal number in Java. 1. By using parseInt() method of Integer class. 2. By using user defined logic. Program to Convert Binary to Decimal in Java By using Integer.parseInt() Integer.parseInt() method takes… Read More »

Java Program to Find Current Date and Time

We can find current date and time in Java in two ways. The first way is to use Date class and second way is to use Calendar class. Below I have shared Java program to find current date and time. First I am defining the date and time format using DateFormat and SimpleDateFormat class and… Read More »

Program for Armstrong Number in Java

Armstrong number is a n digit number such that the sum of digits raised to the power n is equal to the number. For example: 153 is armstrong number because here n=3 and 13+53+33=153. 120 is not armstrong number because 13+23+03!=120. Below I have shared a Java program that checks whether a number is armstrong… Read More »

Anonymous Class in Java

Anonymous class in Java is a class without name. Its name is decided by the compiler. It enables us to declare and instantiate the class at the same time. It is like local class except that it does not have any name. We can use it only once. Anonymous class is also known as anonymous… Read More »

Java Escape Sequences With Program Example

A character preceded by a backslash () is known as escape sequence. There are total 8 escape sequences in Java which have special meaning to the compiler. When we use an escape sequence in print statement then the compiler interpret it accordingly. All the escape sequences with program example is given below. Java Escape Sequences… Read More »

Type Casting in Java

Converting one data type to another data type is known as type casting. Type Casting in Java is of two types i.e. Implicit Type Casting which is also known as Automatic Type Casting and Explicit Type Casting. Implicit or Automatic Type Casting In this, smaller data type is converted to bigger data type which is also… Read More »

Data Types and Naming Conventions in Java

Data Types in Java Used to represent the type of memory allocation. Used with variables and methods. These are fixed. Primitive Data Types Primitive data types are defined already by the programming language. In Java there are 8 primitive data types. Non-Primitive Data Types Non-Primitive data types are defined by the user. They are Class,… Read More »