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 : Java Integer Literals Explained: Decimal, Binary, Octal & Hex | S7

Tuesday, August 27, 2024

Test Your Knowledge

Take this quiz to test your understanding of Java Integer Literals.


Introduction:

In Session 7, we dive into Java Integer Literals, exploring the various ways to represent integer values using Decimal, Binary, Octal, and Hexadecimal formats. Understanding these literals is crucial for dealing with different data representations in Java.

Decimal Literals

Decimal literals are the most common and use base 10. For example:

int decimal = 100;
int negativeDecimal = -50;

Here, 100 and -50 are decimal literals representing positive and negative integer values respectively.

Binary Literals

Binary literals use base 2 and are prefixed with 0b or 0B. For example:

int binary = 0b1100100;
int negativeBinary = -0b1100100;

The binary literal 0b1100100 equals 100 in decimal, and -0b1100100 represents a negative binary literal.

Octal Literals

Octal literals use base 8 and are prefixed with 0. For example:

int octal = 0144;
int negativeOctal = -0144;

The octal literal 0144 equals 100 in decimal, and -0144 is the negative equivalent.

Hexadecimal Literals

Hexadecimal literals use base 16 and are prefixed with 0x or 0X. For example:

int hex = 0x64;
int negativeHex = -0x64;

The hexadecimal literal 0x64 equals 100 in decimal, and -0x64 represents the negative hexadecimal literal.

Code Examples

Here are some additional examples to illustrate how different literals can be used in Java:

 




public class IntegerLiteralsExample {
    public static void main(String[] args) {
        // Decimal Literals
        int decimal1 = 123;
        int decimal2 = -456;

        // Binary Literals
        int binary1 = 0b101010;
        int binary2 = -0b110110;

        // Octal Literals
        int octal1 = 0754;
        int octal2 = -0342;

        // Hexadecimal Literals
        int hex1 = 0x1F;
        int hex2 = -0xA5;

        // Print all values
        System.out.println("Decimal 1: " + decimal1);
        System.out.println("Decimal 2: " + decimal2);
        System.out.println("Binary 1: " + binary1);
        System.out.println("Binary 2: " + binary2);
        System.out.println("Octal 1: " + octal1);
        System.out.println("Octal 2: " + octal2);
        System.out.println("Hexadecimal 1: " + hex1);
        System.out.println("Hexadecimal 2: " + hex2);
    }
}(code-box)

This code demonstrates how different types of integer literals are declared and printed in Java.

Conclusion

Understanding the different integer literals in Java is essential for working with various numeric systems. Whether you need to use decimal, binary, octal, or hexadecimal, Java provides straightforward syntax to represent these values.

Call to Action

Experiment with different integer literals in your code. Try converting between decimal, binary, octal, and hexadecimal to deepen your understanding!

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