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 STRING Literals, Null Literals & Underscore Use in Literals | S9

Wednesday, August 28, 2024

Test Your Knowledge

Take this quiz to reinforce your understanding of String, Null, and Underscore literals in Java.


Introduction:

Welcome to this session on understanding Java String literals, Null literals, and the use of underscores in numeric literals. These are fundamental concepts that will enhance your coding skills and make your programs more readable.

String Literals:

String literals are sequences of characters enclosed within double quotes. They are used to represent constant text values in your Java programs.

  • Example: String greeting = "Hello, World!";

In the example above, "Hello, World!" is a string literal assigned to the variable greeting.

Null Literals:

The null literal is used in Java to represent the absence of an object or value. It’s often used to signify that a variable has not been initialized.

  • Example: String name = null;

Here, the variable name is explicitly set to null, meaning it doesn't reference any object.

Underscore in Numeric Literals:

Starting with Java 7, you can use underscores in numeric literals to make them more readable. The underscore is ignored by the compiler and does not affect the value of the number.

  • Example: int largeNumber = 1_000_000;

This technique is especially useful for representing large numbers. The variable largeNumber still holds the value 1000000.

Java Program Example:

Here’s a simple Java program that demonstrates the use of String literals, Null literals, and underscores in numeric literals:

 

public class LiteralExamples {
    public static void main(String[] args) {
        // String literal
        String greeting = "Hello, World!";
        
        // Null literal
        String name = null;
        
        // Underscore in numeric literals
        int largeNumber = 1_000_000;

        // Output values
        System.out.println("Greeting: " + greeting);
        System.out.println("Name: " + name);
        System.out.println("Large Number: " + largeNumber);
    }
}
                (code-box)

Explaining the Program:

  • String Literal: greeting holds the text "Hello, World!".
  • Null Literal: name is set to null, indicating it has no value.
  • Underscore in Literals: largeNumber is easier to read, but it still represents the number 1000000.

Program for String Literals

This program demonstrates the use of String literals in Java.

 

public class StringLiteralExample {
    public static void main(String[] args) {
        // String literals
        String greeting = "Hello, World!";
        String farewell = "Goodbye, World!";
        
        // Output the string literals
        System.out.println("Greeting: " + greeting);
        System.out.println("Farewell: " + farewell);
    }
}
        (code-box)

Program for Null Literals

This program shows how to use null literals in Java.

 

public class NullLiteralExample {
    public static void main(String[] args) {
        // Null literal
        String name = null;
        
        // Checking if the variable is null
        if (name == null) {
            System.out.println("The name variable is null.");
        } else {
            System.out.println("Name: " + name);
        }
    }
}
        (code-box)

Program for Using Underscore in Numeric Literals

This program demonstrates how to use underscores in numeric literals in Java.

 

public class UnderscoreInLiteralsExample {
    public static void main(String[] args) {
        // Using underscores in numeric literals
        int largeNumber = 1_000_000;
        double decimalNumber = 123_456.78_90;
        
        // Output the numeric literals
        System.out.println("Large Number: " + largeNumber);
        System.out.println("Decimal Number: " + decimalNumber);
    }
}
        (code-box)

Key Points to Remember:

  • String literals: Used for text values in Java.
  • Null literals: Indicate the absence of a value or reference.
  • Underscore in literals: Improves the readability of large numbers.

Conclusion

Understanding how to use String literals, Null literals, and underscores in numeric literals will make your Java code more readable and efficient. Practice these concepts in your own code to get a solid grasp of their usage.

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