100% Practical EdTech & External TPC Platform

Learn. Practice. Prepare.
Get Hired by Top MNCs

Industry-focused training, real company test practice, premium mock tests, and career tools - Everything you need to build a successful IT career.

AICTE Approved Programs
Industry Expert Mentors
Placement Assistance
Trusted by 500+ Colleges
StudyEcart Premium Practical Training & TPC Framework
🏆

Gold Standard

100% Practical Tech Training

💼

Referrals

Placement Assistance

🗣️

MNC Prep

MNC Mock Interview Drills

Proven Pipeline

Our Career Acceleration Ecosystem

A modular, 5-step strategic framework mapping career growth from learning paths to top MNC placements.

📖 01

Practical Learning

Master high-demand tech stacks via hands-on development exercises.

✏️ 02

Mock Assessments

Rigorous aptitude log drills, logical analytics, and custom technical metrics training sheets.

📄 03

Portfolio Assembly

Engine optimization runs to produce ATS-compliant resumes and map robust code architectures.

💻 04

Hiring Simulators

Pass real company tests (TCS, Infosys, Wipro, Accenture) inside authentic custom web environments.

🏆 05

Corporate Placement

Secure verified off-campus recruitment pipelines and join premium MNC engineering teams.

Java Tutorial : Understanding Java Floating Literals: Decimal, Hexadecimal & Scientific Notation Explained

Wednesday, August 28, 2024

Test Your Knowledge

Take this quiz to test your understanding of Floating Literals in Java.


Introduction

In Java, floating-point literals represent decimal numbers with a fractional part. These literals can be expressed in different formats, such as Decimal, Hexadecimal, and Standard literals. Let's dive into these formats with examples.

Decimal Floating Literals

Decimal floating literals are written as numbers with a decimal point. Here's an example:

float decimalLiteral = 123.45f;
double anotherDecimalLiteral = 6789.1234;
                

In the above example, 123.45f is a float literal, and 6789.1234 is a double literal.

Hexadecimal Floating Literals

Hexadecimal floating literals are a lesser-known way to represent floating-point numbers in Java. They start with 0x or 0X followed by a hexadecimal number and a p or P to indicate the exponent.

double hexLiteral = 0x1.0p3;
                

Here, 0x1.0p3 represents the decimal number 8.0. The p3 indicates multiplying the value by 23.

Standard Floating Literals

Standard floating literals are the most common and straightforward way to write floating-point numbers in Java. You simply write the number with or without a decimal point:

double standardLiteral1 = 10.0;
double standardLiteral2 = 5.0e2;  // 5.0e2 is equivalent to 500.0
                

In the example, 10.0 is a regular floating-point literal, while 5.0e2 is a scientific notation where e2 means "times 10 to the power of 2."

Java Program: Floating Literals (Decimal, Hexadecimal, Standard)

This program demonstrates the use of different types of floating literals in Java: decimal, hexadecimal, and standard scientific notation.

Code Example:

  
        
public class FloatingLiteralsExample {
    public static void main(String[] args) {
        // Decimal floating literal
        float decimalFloat = 123.45f;
        double decimalDouble = 6789.1234;

        // Hexadecimal floating literal
        double hexDouble = 0x1.0p3;  // Equivalent to 8.0 in decimal

        // Standard floating literal with scientific notation
        double standardDouble = 5.0e2;  // Equivalent to 500.0

        // Printing the values
        System.out.println("Decimal float value: " + decimalFloat);
        System.out.println("Decimal double value: " + decimalDouble);
        System.out.println("Hexadecimal double value: " + hexDouble);
        System.out.println("Standard double value (scientific notation): " + standardDouble);
    }
}
      
(code-box)

Explanation:

  • Decimal floating literal: 123.45f is a float, and 6789.1234 is a double.
  • Hexadecimal floating literal: 0x1.0p3 represents 8.0 in decimal. The p3 means multiplying the hexadecimal value by 2^3.
  • Standard floating literal: 5.0e2 is written in scientific notation and represents 500.0.

Output:

Decimal float value: 123.45
Decimal double value: 6789.1234
Hexadecimal double value: 8.0
Standard double value (scientific notation): 500.0
        

Key Points to Remember

  • Floating-point literals can be float or double. By default, they are double.
  • Use a suffix f or F for float literals.
  • Hexadecimal literals use 0x or 0X with p for the exponent.
  • Scientific notation uses e or E to denote the exponent.

Conclusion

Understanding floating-point literals in Java is essential for precise numerical computations. Practice using these different literals to get comfortable with their syntax and usage.

Call to Action

Experiment with different floating-point literals in your Java programs. Try converting between decimal and hexadecimal literals, and explore how scientific notation works in your code!

Proprietary Preparedness Utilities

Powerful Placement Tools Suite

Accelerate preparation with our proprietary algorithm-based interactive resources.

📝

ATS Resume Builder

Create ATS friendly resumes in minutes

🤖

Resume Analyzer

Get AI-powered resume review

🧮

Salary Calculator

Calculate in-hand salary instantly

🗣️

Interview Questions

Prepare for HR and Tech panels

🗺️

Career Roadmap

Step-by-step career path guidelines

India's First Free Realtime Mock Online Tests

Company Specific Test Simulators

Practice real company hiring assessments and boost your selection chances

View All Simulators
Direct Referral Pipeline

Latest Placement Opportunities

Verified off-campus drives, internships, and direct referral postings matching modern IT requirements.

View More Jobs →

5000+

Students Trained

50+

Certified Trainers

50+

Partner Colleges

95%+

Placement Rate

What Students Say
Student Rohit Sharma avatar review StudyEcart

"StudyEcart helped me from learning to getting placed in my dream company. The mock tests and company simulators are real game-changers!"

— Rohit Sharma

Placed at Infosys

Student Anjali Sen review StudyEcart

"The internship program was completely practical. Working on real-world projects helped me clear my technical coding interview with Accenture in one go!"

— Anjali Sen

Placed at Accenture

Student Vijay Verma review StudyEcart

"StudyEcart's company simulators are amazingly close to real assessment interfaces. The logic, format, and timer prepared me perfectly for the TCS NQT."

— Vijay Verma

Placed at TCS

Student Rajesh Reddy review StudyEcart

"I highly recommend StudyEcart's DevOps course. The live container deployment drills and CI/CD pipelines let me clear challenging interview panels."

— Rajesh Reddy

Placed at Wipro

Student Rahul Nair review StudyEcart

"From writing raw algorithms to building responsive applications, the mentorship at StudyEcart has completely reshaped my technical career foundations!"

— Rahul Nair

Placed at Capgemini

Success Stories

Placed Student avatar Placed Student avatar Placed Student avatar

5000+ Students

Placed in Top MNCs

StudyEcart Partner Hiring Hub Companies
Home Courses Tools Jobs