CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Double Class in Java

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor

Double Class in Java

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 ยท 3 min read ยท 0 Comments
Share: in X

The java.lang.Double class is a wrapper class for the primitive type double. This means that it provides a way to treat a double value as an object.

This can be useful for a variety of purposes, such as:

  • Encapsulating a double value so that it can be passed around as an object.
  • Converting a double value to a string and vice versa.
  • Performing mathematical operations on double values.
  • Handling special double values, such as NaN and Infinity.

The Double class provides a number of methods for working with double values. Some of the most commonly used methods include:

MethodDescription
valueOf()Converts a string to a double value. If the string cannot be parsed as a double, then a NumberFormatException is thrown.
toString()Converts a double value to a string.
parseDouble()Converts a string to a double value. If the string cannot be parsed as a double, then a NumberFormatException is thrown. This method is similar to valueOf(), but it does not throw an exception if the string cannot be parsed. Instead, it returns the value NaN.
doubleValue()Returns the double value of a Double object.
isNaN()Returns true if the value of a Double object is NaN. NaN is a special double value that represents a number that is not a number.
isInfinite()Returns true if the value of a Double object is Infinity. Infinity is a special double value that represents a number that is infinitely large.

Following is an example of how to use the Double class to encapsulate a double value:

Double d = new Double(12.34);

This code creates a Double object that encapsulates the value 12.34. The Double object can then be passed around as an object, or it can be used to perform mathematical operations.

Following is an example of how to use the Double class to convert a double value to a string:

String str = Double.toString(12.34);

This code converts the double value 12.34 to a string and stores it in the variable str. The string "12.34" can then be used for any purpose that requires a string.

Following is an example of how to use the Double class to handle special double values:

Double d = Double.NaN;
if (d.isNaN()) {
  System.out.println("The value of d is NaN");
}

This code creates a Double object that is initialized to NaN. The isNaN() method is then used to check if the value of the Double object is NaN. If it is, the System.out.println() statement is executed.

The Double class is a powerful tool for working with double values in Java. It provides a number of methods that make it easy to encapsulate, convert, and manipulate double values. The Double class can be used in a variety of real-world applications, such as:

  • Scientific computing
  • Financial applications
  • Statistical analysis
  • Data science

Related Posts:

  • java.lang.Long Class in Java
  • Primitive data types in Java
  • Control Statements in Java
  • java.lang.Character Class in Java
  • java.lang.Boolean class in Java
  • Arrays of Primitive Types in Java
Tags:javalanguage-fundamentals
Was this article helpful?
โ† Previous Articlejava.lang.Number Class
Next Article โ†’Float Class in Java

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
ยฉ 2026 CoderSathi. All rights reserved. Privacy Policy ยท Sitemap