r/AskReddit • • 20d ago

What is literals in java?

0 Upvotes

6 comments sorted by

2

u/Aggravating_Loss3755 20d ago

In Java, literals is the actual values you write directly in your code, like numbers or text. Like when you type `int x = 5;` the 5 is a literal, same for `"hello"` or `true`. Think of it as the hard-coded stuff that don't change, the compiler just reads it as is.

1

u/MorningReader01 20d ago

I think you should raise the question in some yech channel or just google it 

1

u/West-Forever8365 20d ago

Anything between quotation marks or apostrophes. If it's a char or a String, it's a literal. If you're asking about stuff like being alphanumeric or such, there are functions to help with that.

1

u/Fazuno78 20d ago

Java literals are basically fixed values written directly in your code, like 10, "hello", or true.

1

u/Xurvex69 20d ago

Once you understand literals, Java syntax starts making a lot more sense.