Found 9326 Articles for Object Oriented Programming

Java Program to Add the nth Square Series

Shriansh Kumar
Updated on 25-Apr-2023 18:04:40

124 Views

Sum of nth squares series is a form of arithmetic progression where sum of squares is arranged in a sequence with initial term as 1, and n being the total number of terms. 12 + 22 + 32 + ….. + n2 In this article, we will discuss java program to add the nth square series. Approach 1: Using Iterative approach Let’s understand the logic for program with a simple example. Example If we take input as num = 6 It will be calculated as: 12 + 22 + 32 + 42 + 52 + 62 = ... Read More

Java Program to Allocate and Initialize Super Class Members using Constructor

Shriansh Kumar
Updated on 25-Apr-2023 18:04:07

258 Views

In java, super refers to the parent class and to inherit one class to another class we use extends keyword. Before making a java program to allocate and initialize super class members using constructor, let’s go through some concepts we are going to use in this article. What is Constructor? Constructor is very similar to methods but the difference is that methods define the behavior of an object but constructor is used to initializing those objects. We can provide any name of our choice to methods but a constructor must have same name as class name. Also, methods ... Read More

Java Program to Add two Numbers without using Arithmetic Operator

Shriansh Kumar
Updated on 25-Apr-2023 18:03:03

2K+ Views

Arithmetic operators such as +, -, *, / are used to perform mathematical operations like addition, subtraction, multiplication, modulo and division. We all have done addition of two numbers using + operator but in this article, we are going to see a few java programs that can add two numbers without using arithmetic operators. The following operators best serve this purpose − Increment operators (++) − They are used to increment value of a variable by 1. It is of two types pre increment and post increment. Pre increment operator first increases the value and then, uses it for ... Read More

Java Program to Calculate Interest for FDs and RDs using Inheritance

Shriansh Kumar
Updated on 25-Apr-2023 18:02:38

584 Views

Inheritance is a concept that allows us to access the properties and behaviors of one class to another class. The class whose methods and member variables are inherited is known as super class or parent class and the class that inherits these methods and member variables is known as child class or sub class. In java, we use ‘extends’ keyword to inherit a class. In this article, we will discuss a java program to calculate interest for FDs and RDs using Inheritance. First, create these four java files in your local machine ide − Acnt.java − This file will ... Read More

Java Program to Calculate difference between two Time Periods

Shriansh Kumar
Updated on 25-Apr-2023 18:02:07

473 Views

To work with date and time in java, we need to import java.time, java.util and java.text packages. We are going to use the following classes and methods provided by these packages to calculate difference between two time periods in java − 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. Approach 1: Using SimpleDateFormat and Date class SimpleDateFormat − It is a class in java that allows us to convert date to string (formatting) and convert string to ... Read More

Java Program to Add Characters to a String

Shriansh Kumar
Updated on 31-May-2024 14:39:39

5K+ Views

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 approaches to do so − Using ‘+’ operator Using methods of StringBuffer and StringBuilder class Using substring() method Approach 1: Using ‘+’ Operator In this section, we will add a character to a string using the concatenation operator. Example public class Main { public static void main(String[] args) { String ... Read More

Java program to check whether the number is divisible by 5

Tapas Kumar Ghosh
Updated on 20-Apr-2023 12:02:43

2K+ 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. Let’s take an example of this. Given number is 525, the number ends with 5 and it is divisible by 5. Given number is 7050, the number ends with 0 and it is divisible by 5. Given number ... Read More

Java Program to Show Inherited Constructor Calls Parent Constructor By Default

Rudradev Das
Updated on 12-Apr-2023 17:56:38

217 Views

What are the constructors? Constructors are used to initialize the values of a particular object. The default constructor is a constructor which has no parameters. These constructors are used to create objects, which don't have any specific value as the initial. In java, there is a keyword super(). This method is widely used in Java environment when the inheritance applied on a Java code. This super() class is used to call to the constructor of the parent class. The parent class must contain two public constructors which takes two int parameters. As we know the constructors cannot be inherited in ... Read More

Java Program to Show Different Access Levels

Rudradev Das
Updated on 13-Apr-2023 11:54:48

176 Views

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 visible only within a particular package. Private - If we declare a function, it will visible only within a particular class only. Protected- If we declare a function, it will visible only within a particular package or for all sub classes. Public - If we declare a function, it will visible ... Read More

Java Program to Set Minimum and Maximum Heap Size

Rudradev Das
Updated on 12-Apr-2023 17:51:06

508 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 a heap memory is compared to stack, the spare objects are cleared by the GarbageCollector automatically. The heap memory are divided into three parts ... Read More

Advertisements