Upcasting and Downcasting in Java

In this tutorial we are going to understand the concept of upcasting and downcasting in Java with example and learn about their use in the modern programming techniques. Upcasting in Java Upcasting basically refers to moving up in the class hierarchy. So what does the last line mean? We are going to understand this using a simple example where Game is the base class and Cricket and Chess are two of its subclasses. Game.java




Read more

Perfect Number in Java

Here you will know about perfect number in Java with program and example. What is Perfect Number? The number said to be perfect number when sum of all positive divisors of that number excluding that number itself in divisors is equal to that number. Or, sum of all positive divisors of that number including that number is 2 times of the number. Key Points: The number of divisors of perfect number will be even. Most of the perfect numbers are

Read more

Java Program to Find GCD of Two Numbers Using Euclidean Algorithm

Here you will get java program to find gcd of two numbers using recursion and euclidean algorithm. Greatest Common Division (GCD) of two numbers is largest number that divides both of them completely. GCD is also called as Highest Common Factor (HCF). There are various ways to find GCD but Euclidean Algorithm is the most efficient way. Euclid’s algorithm GCD of two numbers a and b can be obtained by following algorithm. gcd (a, b) = gcd (a – b, b),

Read more

Static Keyword in Java

In this tutorial you will learn about static keyword in Java with example code. Static keyword in java mainly used for memory management process. In Java static keyword can be used in following cases. With Variables With Methods With Blocks With Nested Class Lets discuss each of them one by one. Static Keyword in Java Static Variable in Java We can declare static variable by simply writing static keyword before normal variable. Static variables are memory efficient as memory for

Read more

Advantages and Disadvantages of Java Language

Here I will discuss about some important advantages and disadvantages of Java language. Advantages of Java There are several advantages or merits of java that are explained below. Platform Independent It is one of the biggest merit of java language. When a java program is compiled it is converted into .class file or byte code. The .class file is platform independent and can run on any platform like windows, mac, linux, etc. This property is known as Write Once Run

Read more

Pascal Triangle in Java

Here you will learn about pascal triangle in java with a program example. What is Pascal’s Triangle? It is a triangular array of the binomial coefficients. It is a number pattern which starts with 1 at top and then placing numbers below it in triangular pattern. Each number is obtained by adding two numbers above it. Take below example, here 4 is obtained by adding 1 and 3 above it. Below I have shared the java program to print pascal

Read more

How Many Ways to Create Object in Java?

How many ways to create object in Java? The answer is there are many ways but in this tutorial I am sharing the 5 ways to do this. Using new Keyword Using object cloning Using Class.forName() Using Class Loader Using Object Deserialization Below I have discussed each of these methods one by one with example.   How Many Ways to Create Object in Java? Method 1: Using new Keyword It is most common and popular method to create object in

Read more
1 2 3 4