Programming Articles - Page 2484 of 3366

How to read the data from a properties file in Java?

Vivek Verma
Updated on 23-Jun-2025 11:31:51

34K+ Views

Java supports file-handling; it provides various classes that provide various methods to read, write, update, and delete data from files in our local system. A properties file is a simple text file with a ".properties" extension that contains configuration data in the form of key-value pairs. It is mostly used in Java applications to manage settings such as database configuration, application messages, or environment variables. How to read Data from a Properties File in Java? To read data from the properties file, you can use the Properties class in Java. This is a subclass of the Hashtable class and it represents a persistent ... Read More

How to instantiate a static inner class with reflection in Java?

raja
Updated on 24-Nov-2023 09:18:44

2K+ Views

A static inner class can be instantiated without the need for an instance of the outer class. In general, an Inner class is a part of nested class, called Non-static nested classes in Java. The types of inner classes are member inner class, anonymous inner class, and local inner class. We can instantiate a static inner class with reflection using InnerClass.class.newInstance(). If we need an instance of the outer class to instantiate a non-static inner class, we can specify it before a new operator. Example import java.lang.reflect.*; public class InnerclassWithReflectionTest { public static void main(String args[]) { ... Read More

Average numbers in array in C Programming

sudhir sharma
Updated on 01-Jul-2020 12:08:59

284 Views

There are n number of elements stored in an array and this program calculates the average of those numbers. Using different methods.Input - 1 2 3 4 5 6 7Output - 4Explanation - Sum of elements of array 1+2+3+4+5+6+7=28No of element in array=7Average=28/7=4There are two methodsMethod 1 −IterativeIn this method we will find sum and divide the sum by the total number of elements.Given array arr[] and size of array nInput - 1 2 3 4 5 6 7Output - 4Explanation - Sum of elements of array 1+2+3+4+5+6+7=28No of element in array=7Average=28/7=4Example#include using namespace std; int main() {    int arr[] = { 1, 2, 3, ... Read More

Add minimum number to an array so that the sum becomes even in C programming

sudhir sharma
Updated on 09-Aug-2019 13:22:25

235 Views

Given an array, add the minimum number (which should be greater than 0) to the array so that the sum of array becomes even.Input - 1 2 3 4, Output - 2Explanation - Sum of array is 10, so we add minimum number 2 to make the sum even.Method 1: calculate the sum of all elements of the array, then check if the sum is even then add minimum number is 2, else add minimum number is 1.Input - 1 2 3 4, Output - 2Explanation - Sum of array is 10, so we add minimum number 2 to make the sum even.Example#include using namespace std; int ... Read More

Arithmetic Mean in C programming

sudhir sharma
Updated on 09-Aug-2019 13:15:22

3K+ Views

Arithmetic mean is the sum of a collection of numbers divided by the number of numbers in the collection.Basic properties of Arithmetic MeanThe mean of n numbers x1, x2, . . ., xn is x. If each observation is increased by p, the mean of the new observations is (x + p).The mean of n numbers x1, x2, . . ., xn is x. If each observation is decreased by p, the mean of the new observations is (x - p).The mean of n numbers x1, x2, . . ., xn is x. If each observation is multiplied by a nonzero ... Read More

Will a finally block execute after a return statement in a method in Java?

Vivek Verma
Updated on 14-May-2025 19:25:38

21K+ Views

Yes, the finally block will be executed even after a return statement within a try or catch block in a Java method. Finally Block after the Return Statement Usually, the return statement will be the last in a Java method. If you try to add any statements after the return in Java, an error will be generated.  public class Sample { public String demoMethod() { System.out.println(); return null; System.out.println("This statement will generate an error"); } ... Read More

C Program for Tower of Hanoi

sudhir sharma
Updated on 01-Jul-2020 11:35:25

13K+ Views

The tower of Hanoi is a mathematical puzzle. It consists of three rods and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top. We have to obtain the same stack on the third rod.The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules−Only one disk can be moved at a time.Each move consists of taking the upper disk from one of the stacks and ... Read More

C++ Program for Dijkstra’s shortest path algorithm?

sudhir sharma
Updated on 09-Aug-2019 13:08:53

16K+ Views

Dijkstra's algorithm (or Dijkstra's Shortest Path First algorithm, SPF algorithm) is an algorithm for finding the shortest paths between nodes in a graph, which may represent, for example, road networks. The algorithm creates a tree of shortest paths from the starting vertex, the source, to all other points in the graph.Dijkstra’s algorithm finds a shortest path tree from a single source node, by building a set of nodes that have minimum distance from the source.The graph has the following−vertices, or nodes, denoted in the algorithm by v or u.weighted edges that connect two nodes: (u, v) denotes an edge, and ... Read More

C/C++ Program for nth Catalan Number?

sudhir sharma
Updated on 13-Aug-2019 06:45:25

615 Views

Catalan numbers are a sequence of numbers. Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively-defined objects.Cn is the number of Dyck words of length 2n. A Dyck word is a string consisting of n X's and n Y's such that no initial segment of the string has more Y's than X's. For example, the following are the Dyck words of length 6XXXYYY XYXXYY XYXYXY XXYYXY XXYXYY.Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, Cn counts the number of expressions containing n pairs of parentheses which ... Read More

C Program to Multiply two Floating Point Numbers?

sudhir sharma
Updated on 01-Jul-2020 11:36:53

770 Views

Float is a shortened term for "floating-point." By definition, it's a fundamental data type built into the compiler that's used to define numeric values with floating decimal points. A floating-point type variable is a variable that can hold a real number, such as 4320.0, -3.33, or 0.01226. The floating part of the name floating point refers to the fact that the decimal point can “float”; that is, it can support a variable number of digits before and after the decimal point.floating pointCategoryTypeMinimum SizeTypical Sizefloating pointfloat4 bytes4 bytesdouble8 bytes8 byteslong double8 bytes8, 12, or 16 bytesFloating-point rangeSizeRangePrecision4 bytes±1.18 x 10-38 to ... Read More

Advertisements