Found 9150 Articles for Object Oriented Programming

Java Program to Add the nth Square Series

Shriansh Kumar
Updated on 30-May-2025 17:29:59

299 Views

The sum of the nth squares series is a form of arithmetic progression where the sum of squares is arranged in a sequence with the initial term as 1, and n being the total number of terms. 12 + 22 + 32 + ... + n2 In this article, we will discuss a Java program to add the nth square series. But, before that, let's see an example scenario: Example Scenario: Input: num = 6 Output: sum = 91 It will be calculated as: 12 + 22 + 32 + 42 + 52 + 62 = 1 ... Read More

Java Program to Allocate and Initialize Super Class Members using Constructor

Shriansh Kumar
Updated on 06-Jun-2025 13:57:24

485 Views

In Java, super refers to the parent class instance, and to inherit members of the super class to the child class, we use the extends keyword. Before writing a Java program to allocate and initialize super class members using a constructor, let's go through some concepts we are going to use in this article. What is Constructor? A Java constructor is a class member that initializes instance variables of a class. It is very similar to a method, but the difference is that methods can return a value, but a constructor does not return any value because it can't have any return ... Read More

Java Program to Add two Numbers without using Arithmetic Operator

Shriansh Kumar
Updated on 19-Jun-2025 15:46:18

4K+ Views

Arithmetic operators such as "+", "-", "*", and "/" are used to perform mathematical operations like addition, subtraction, multiplication, modulo, and division. We have added two numbers using the "+" operator, but in this article, we are going to learn a few Java programs that can add two numbers without using arithmetic operators. The following operators best serve this purpose: Increment operators (++) Bitwise operators ... Read More

Java Program to Calculate Interest for FDs and RDs using Inheritance

Shriansh Kumar
Updated on 06-Jun-2025 14:04:57

872 Views

Inheritance is a concept that allows us to access the properties and behaviors of one class in another class. The class whose methods and member variables are inherited is known as the super class or parent class, and the class that inherits these methods and member variables is known as the child class or subclass. In Java, we use the extends keyword to inherit a class. Problem Statement Write Java programs that calculate interest for Fixed Deposits (FDs) and Recurring Deposits (RDs) using inheritance. The program should prompt the user to choose between FD and RD, enter the amount and duration, ... Read More

Java Program to Calculate difference between two Time Periods

Shriansh Kumar
Updated on 19-Jun-2025 10:19:22

824 Views

We are given two time periods, and our task is to write a Java program to calculate the difference between them. For this problem, we can use classes and methods of java.time, java.util, and java.text packages. SimpleDateFormat class Date class LocalDate class Period class parse() method between() method As we move further in this article, we will understand the uses of these classes and methods in calculating the difference between two time periods. Some examples ... Read More

Java Program to Add Characters to a String

Shriansh Kumar
Updated on 30-May-2025 17:54:49

13K+ Views

Java Program to Add Characters to a String Java provides different ways to add characters to a string. We can add characters in the beginning or at the end or at any position according to the need. In this article, we are going to see three different approaches to do so: Using '+' operator Using methods of StringBuffer and StringBuilder classes ... Read More

Java program to check whether the number is divisible by 5

Tapas Kumar Ghosh
Updated on 14-Feb-2025 18:29:41

4K+ Views

In mathematics, the divisibility rule of 5 states that if the number ends with 0 or 5 then it will divisible by 5. There is another way to identify the divisibility rule of 5, if the remainder comes to 0 it returns the number is divisible by 5. The mod(%) operator is normally used in programming when it comes to divisibility. Following are some examples which helps you to understand the divibility rule of 5 − Given number is 525, the number ends with 5 and it is divisible by 5. Given number is 7050, the number ends with ... Read More

Java program to show inherited constructor calls parent constructor by default

Rudradev Das
Updated on 18-Nov-2024 22:30:58

337 Views

In this article, we will learn about constructors in Java. Constructors initialize objects when they are created. We will also see how the parent constructor is called in inheritance. Problem StatementWe will demonstrate possible approaches to show how the inherited constructor calls the parent constructor by default.Different approaches The following are the different approaches to show how the inherited constructor calls the parent constructor by default− Demonstrating inheritance properties ... Read More

Java Program to Show Different Access Levels

Rudradev Das
Updated on 02-Jan-2025 19:12:41

265 Views

In this article, we will explore the use of access modifiers in Java by demonstrating their functionality in different scenarios. Access Modifiers Access modifiers are used to set the feature of visibility of some particular classes, interfaces, variables, methods, constructors, data members, and the setter methods in Java programming language. In a Java environment, we have different types of access modifiers. Default - If we declare a function, it will be visible only within a particular package. ... Read More

Java program to set minimum and maximum heap size

Rudradev Das
Updated on 15-Oct-2024 10:39:06

723 Views

The Java heap is a particular memory area which is used to store the objects and represent them as or by an instance in Java Virtual Machine. The Java heap can be shared between two threads as long as the environment is occupied by some running applications. The heaps are sorted in a stack memory and follow the Last In First Out (LIFO) method after the creation of an object in JVM. When the size of the heap memory is compared to the stack, the spare objects are cleared by the GarbageCollector automatically. The heap memory is divided into three ... Read More

Advertisements