Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Java Articles
Page 176 of 450
Java Program for focal length of a spherical mirror
In this article, we will learn two different approaches to computing the focal length of a spherical mirror using Java. While the second method makes use of Object-Oriented Programming (OOP) concepts for a more generic and flexible approach the first method is a simple functional implementation. Finding Focal Length Spherical mirrors play a vital role in optical systems, from telescopes and microscopes to vehicle rearview mirrors. These mirrors, either concave or convex, focus or diverge light, respectively, based on their geometry. The focal length, a key characteristic of spherical mirrors, determines how the mirror bends light.The focal length of a ...
Read MoreJava Regex to extract maximum numeric value from a string
In this article, we will learn to extract the maximum numeric value from a string using Java’s regex. While Java provides several ways to handle string manipulation, regular expressions (regex) offer a powerful and efficient tool for such tasks. Problem Statement The maximum numeric value is extracted from an alphanumeric string. An example of this is given as follows − Input String = abcd657efgh234 Output Maximum numeric value = 657 Using Java Regex and Pattern Class Java provides the Pattern and Matcher classes to work with regular expressions. The Pattern class compiles a regular expression, and the Matcher class is ...
Read MoreFinal vs Immutability in Java
The final keyword in Java may be employed to define a constant value as well as prevent a variable, method, or class from being changed or overridden. On the other side, immutability describes an object's characteristic of keeping a constant state across the course of its existence. The values of an object don't change after it is formed. Variables, methods, and classes are constrained by the "final" keyword, but immutability goes a step further by guaranteeing that the object's whole state is preserved. Let us learn the key differences between final vs immutability in this article. Final in Java ...
Read MoreCreate an Integer object in Java
To create an Integer object in Java is quite easy. Let us learn about the following two ways for this purpose. Before moving to the coding section, let's briefly discuss the Integer class. The Integer class is a wrapper class in Java, which can be used to encapsulate a primitive int value in an object. Using an Integer Constructor You can create an Integer object using the Integer constructor by passing a primitive int value. In Java, a constructor is a special method whose name is exactly the same as the class name. Example The following example creates an Integer ...
Read MoreHow to read data from scanner to an array in java?
The Scanner class of the java.util package gives you methods like nextInt(), nextByte(), nextFloat(), etc., to read data from the keyboard. To read an element of an array, use these methods in a 'for' loop. Let us have a brief explanation of the methods of nextInt(), nextByte(), and nextFloat() from the Scanner class in Java. Reading Integer Data Using nextInt() Method The nextInt() method is used to read the next token from the input as an integer. It is commonly used for reading integer values from the keyboard. Example In the following example, we use the nextInt() method of the ...
Read MoreWhat is the difference between PATH and CLASSPATH in Java?
In Java, the terms Path and ClassPath refer to different things and are used for different purposes. Let's discuss them one by one with a suitable example − Path The path environment variable is used to specify the set of directories that contains execution programs. When you try to execute a program from the command line, the operating system searches for the specified program in the current directory and, if available, executes it. In case the programs are not available in the current directory, the operating system verifies in the set of directories specified in the 'PATH' environment variable. Setting ...
Read MoreFloating-point hexadecimal in Java
In this article, we use the '%a' format specifier to represent floating-point numbers in their hexadecimal form. This is useful when you need precise control over the representation of floating-point values. For Formatter, import the following package − import java.util.Formatter; Now creating a 'Formatter'object to format the data− Formatter f = new Formatter(); Using the format() method with the %a format specifier to convert a floating-point number to its hexadecimal string.− f.format("%a", 298.45) Example 1: Basic Example In this example, we format the floating-point number '298.45' to its hexadecimal representation using the '%a' format specifier with a 'Formatter' object ...
Read MoreHow can I edit a .jar file?
Editing a .jar File? Java Archive files, commonly known as .jar files, are packaged collections of compiled Java classes and associated resources. Editing a .jar file can be useful for tasks like modifying configurations or updating resources. However, since .jar files are compressed and designed for execution, editing them requires specific tools and methods. This guide explains the steps to edit a .jar file effectively. Why Would You Need to Edit a .jar File? To update or modify configuration files (like .properties or .xml files). To replace or update resource files (e.g., images or audio). To debug or analyze ...
Read MoreHow can I edit a .jar file?
Editing a .jar File? Java Archive files, commonly known as .jar files, are packaged collections of compiled Java classes and associated resources. Editing a .jar file can be useful for tasks like modifying configurations or updating resources. However, since .jar files are compressed and designed for execution, editing them requires specific tools and methods. This guide explains the steps to edit a .jar file effectively. Why Would You Need to Edit a .jar File? To update or modify configuration files (like .properties or .xml files). To replace or update resource files (e.g., images or audio). To debug or analyze ...
Read MoreJava 8: Difference between two LocalDateTime in multiple units
Difference Between Two LocalDateTime Java 8 introduced a powerful Date and Time API that provides developers with better control over date and time operations. One common requirement is to calculate the difference between two LocalDateTime objects in various units such as days, hours, minutes, and seconds. This article explains how to achieve this using Java 8's Duration and ChronoUnit classes. Understanding LocalDateTime LocalDateTime is a class in Java 8 that represents a date-time without a time-zone. It is often used in applications where the time zone is not needed. Calculating differences between two LocalDateTime instances is straightforward with the new ...
Read More