Found 7442 Articles for Java

Java Program to Compute the Running Total of a List

Shriansh Kumar
Updated on 30-Jul-2024 16:44:30

1K+ Views

A running total (also known as an accumulated total) of a list represents the sum of a sequence of elements. As new elements are added to the sequence, the running total continuously updates. To perform this operation in Java, we can use for loop and while loop in our program. The program will have a time complexity of O(n), where n is the number of elements in the list because it loops through the list once and performs a constant-time operation for each element in the list. List is an interface of Java Collection Framework that stores collections of objects. ... Read More

Java Program to Compute the Area of a Triangle Using Determinants

Bharti Kumari
Updated on 10-Apr-2023 15:56:57

388 Views

Introduction The Java program to compute the area of a triangle using determinants is a concise and efficient program that calculates the area of a triangle given the coordinates of its three vertices. This program is useful for anyone studying or working with geometry, as it demonstrates how to use basic arithmetic and algebraic calculations in Java, and how to read in user input using the Scanner class. The program prompts the user to enter the coordinates of three points of the triangle, which are then read in and used to calculate the determinant of the matrix of coordinates. The ... Read More

Java Program to Compare Two Objects

Shriansh Kumar
Updated on 31-Jul-2024 19:55:42

1K+ Views

To compare objects in Java, check the properties or the hash value of given objects. If the properties of both objects matches, then they are equal. If either property is different, it indicate that the objects are not equal. NOTE: Don't use equality operator (==) to compare objects as it checks only their memory location. Objects comparison should be done based on the properties not location. How to Compare Objects in Java? To compare two objects in Java, use the following approaches − By overriding equals() method Without overriding equals() method ... Read More

Java program to combine two list by alternatively taking elements

Bharti Kumari
Updated on 21-Aug-2024 00:06:57

1K+ Views

Introduction The Java program to combine two lists by alternatively taking elements is a simple code snippet that takes in two lists of any type of object that can be stored in a list and returns a new list that contains elements from both input lists alternately. The program defines a method called alternateMerge that takes two lists as input and returns a new list that contains elements from both lists alternately. It determines the size of both lists and loops through the larger of the two lists. For each index in the loop, it adds the element from the ... Read More

Java Program to Check the Accessibility of an Static Variable By a Static Method

Bharti Kumari
Updated on 10-Apr-2023 15:50:34

311 Views

Introduction In Java, we can define variables and methods as static. A static variable or method belongs to the class itself rather than to the individual objects of the class. Therefore, we can access a static variable or method using the class name, without creating an object of the class. In this program, we will explore how to check the accessibility of a static variable by a static method. We will define a class with a static variable and a static method that accesses the variable. We will then call the static method to check if it can access the ... Read More

Java Program to Check if two Arrays are Equal or not

Bharti Kumari
Updated on 10-Apr-2023 15:48:30

2K+ Views

Introduction In Java, we can check if two arrays are equal or not by comparing their elements. If the elements in both arrays are the same and appear in the same order, then the two arrays are considered equal. One way to check the equality of two arrays is to use the Arrays.equals method provided by the java.util package. This method takes two arrays as arguments and returns a boolean value indicating whether they are equal or not. The method compares the elements of the arrays in the same order, so if the order of the elements is not important, ... Read More

Java vs C#

Rudradev Das
Updated on 10-Apr-2023 15:59:23

445 Views

Java is a dynamic, secured and class based high level object oriented programming language developed by Oracle Corporation. On the other hand; C# is a .Net Framework object oriented programming language developed by Microsoft. Java and C# both are the general purpose programming paradigm or basically known as the imperative environment for coding. And these two languages are capable to provide some high level results as output. In a broad view there are many differences between these two OOPs − Java Runtime Environment designed to run a Java code where C# runs on CLR Environment (Common Language Runtime). Java ... Read More

Java Program to search ArrayList Element using Binary Search

Rudradev Das
Updated on 10-Apr-2023 15:50:56

567 Views

Searching is a sorting process to find a particular information from a set of random elements. In a Linear Data structure, there are two types of searching process - Linear Search Binary Search Linear search is a simple searching method by which we can find an element from a data source in a sequential manner. For this searching process the best execution time is 1 and worse is always considered as n. Binary search is a searching process of a particular key element from a stock of multiple elements which follows divide and conquer approach. In this search ... Read More

Java TreeSet Special Method

Rudradev Das
Updated on 10-Apr-2023 15:44:02

270 Views

The TreeSet class in Java environment is a container interface set that is mainly use to store tree. There are two different ways in this class. An AbstractSet Class - It is a collection interface, part of the Java Collection Framework. NavigableSet interface - It is a navigable collection set in Java Collection. Here in the Java environment, TreeSet inherits AbstractSet class and carry through the NavigableSet. Some important aspects of TreeSet implementation − It takes unique data as input. Don't save insertion order of the data. Sorts elements in an ascending order. Thread unsafe. ... Read More

Java TreeMap Special Methods

Rudradev Das
Updated on 10-Apr-2023 15:38:22

250 Views

The TreeMap is a method class collection framework in Java environment. It is storing key to implement a Map Interface or a Map Navigation with a MapAbstract class. After the sorting process the keys of that map will store in the natural order in a consistent manner. The implementation of a TreeMap may not be in an organized manner because the specific map can be addressed by multiple threads. A TreeMap function implemented by using a self-balancing Red-Black binary tree. This method is really efficient to perform addition, remove and retrieve for some elements with O(log n) time complexity. Now ... Read More

Advertisements