Java Private Constructor

Here you will learn about java private constructor. What is private constructor in Java? We can make a constructor private by using private access modifier. Private constructor prevents the instantiation of class from outside. If needed we can create the instance only inside the class. Where to use Java private constructor? We can use private constructor in following two situations. 1. Singleton Design Pattern In single design pattern we have a singleton class that can have only one instance. The

Read more

Convert Decimal to Binary in Java

Here you will get program to convert decimal to binary in Java. Below I have shared 3 different methods for java decimal to binary conversion. Also Read: Convert Binary to Decimal in Java Convert Decimal to Binary in Java 1. Integer.toString() Method We can convert a decimal number to binary using toString() method of Integer class. This method takes two arguments, first argument is the decimal number and second is the base in which we want to convert. For binary the

Read more

Caesar Cipher in Java (Encryption and Decryption)

Here you will get program for caesar cipher in Java for encryption and decryption. Caesar Cipher is an encryption algorithm in which each alphabet present in plain text is replaced by alphabet some fixed number of positions down to it. Take below example. Plain Text: ABCD Key: 3 Cipher Text (Encrypted Message): DEFG As key is 3 so each alphabet will be replaced by an alphabet 3 places down to it. To decrypt a cipher text, the reverse of encryption process is followed.

Read more

Factorial Program in Java Using Loop and Recursion

Here you will get factorial program in java using loop and recursion. What is Factorial? We can find factorial of any number by repeatedly multiplying it with all the numbers below it which are greater than 0. For example factorial of 3 is 6 (1 x 2 x 3). Factorial Program in Java Using Loop

Output enter a number: 6 factorial = 720 Factorial Program in Java Using Recursion

Comment below if you have any doubts regarding java

Read more

Java Program for Prime Number

Here you will get java program for prime number. A number is said to be prime number if it is only divisible by 1 or itself. For example 2, 3, 5, 11, 13, etc are prime numbers. We can check a number is prime or not by following method. If all the numbers between 2 to n/2 doesn’t divide n completely then n is prime otherwise not. Java Program for Prime Number

  Output enter a number: 11 prime

Read more

Java Program for Palindrome Number

Here you will get java program for palindrome number. A number is said palindrome if its is equal to its reverse. For example, 131 is palindrome while 123 is not. Below I have shared two ways to check palindrome in java. Java Program for Palindrome Number Method 1: In this method we will reverse the number and then compare it with original number.

Output Enter a number: 121 Number is Palindrome   Method 2: In this method we will

Read more

Fibonacci Series in Java Using Loop and Recursion

Here you will get program for fibonacci series in java using loop and recursion. The series in which next term is calculated by adding previous two terms is called fibonacci series. Example: 0 1 1 2 3 5 8 13 21 34 Program for Fibonacci Series in Java Using Loop

Output How many terms? 10 0 1 1 2 3 5 8 13 21 34 Program for Fibonacci Series in Java Using Recursion

  Comment below if you have doubts or

Read more

Java Program to Reverse a Number

Here you will get java program to reverse a number with while loop and recursion. When we divide a number with 10 then the remainder is the last digit of number and quotient is the number without last digit. / operator is used find quotient and % operator is used to find remainder. We use this concept to reverse the number. Example: Initially n = 123, reverse = 0 Step 1: remainder = n % 10 = 123 % 10

Read more
1 2 3 4 5 9