Literals

Literals are constant values written directly in the code. They represent fixed values assigned to variables.

Example:

int a = 10;
int b = 20;
int c = scan.nextInt();
System.out.println("Hello, World!");

Explanation:

In the above example:

  • 10 and 20 are integer literals
  • "Hello, World!" is a string literal
  • scan.nextInt() is not a literal — it's a method call.

Note:

From Java 7 onwards, the underscore (_) is allowed in numeric literals (except at the beginning or end of the number or next to a decimal point) to improve readability

❌ Invalid:
int salary = 95,000;   // Comma is not allowed in numeric literals

✅ Valid:
int salary = 95_000;   // Underscore used for readability

You can use underscores in:

  • Integer literals
  • Floating-point literals
  • Binary, Hex, and Octal numbers

Summary:

  • Literals are constant fixed values in Java code.
  • They can be of types like int, float, char, string, boolean, etc.
  • Underscores can be used in numeric literals to improve readability (since Java 7).
  • Do not confuse method calls or variable names with literals.

Welcome to ShikshaSanchar!

ShikshaSanchar is a simple and helpful learning platform made for students who feel stressed by exams, assignments, or confusing topics. Here, you can study with clarity and confidence.

Here, learning is made simple. Notes are written in easy English, filled with clear theory, code examples, outputs, and real-life explanations — designed especially for students like you who want to understand, not just memorize.

Whether you’re from school, college, or someone learning out of curiosity — this site is for you. We’re here to help you in your exams, daily studies, and even to build a strong base for your future.

Each note on this platform is carefully prepared to suit all levels — beginner to advanced. You’ll find topics explained step by step, just like a good teacher would do in class. And the best part? You can study at your pace, anytime, anywhere.

Happy Learning! – Team ShikshaSanchar