"And, finally, a lesson from Rishi in the form of a lecture: a pile of useless information. That's what all lecturers love. Just take a glance at it, and that will be enough."
"I'm ready."
"Today I'll tell you about literals. Literals are all data written directly in Java code. Here are some examples:"
Code | Description |
---|---|
"Rain In Spain" |
This is a literal. Its type is String |
115 |
This is a literal. Its type is int |
0.256 |
This is a literal. Its type is double |
'\u1234' |
This is a literal. Its type is char |
"Actually, there are plenty of other kinds of literals. You can use literals to assign values of any known type:"
Literal | Type | Description |
---|---|---|
123676 | int | Integer |
22223333444433332222L | long | Long integer |
12.323232323f | float | Fractional number |
12.33333333333333333d | double | Long fractional number |
"Rain" "" "Rain\nIn\nSpain\u123" |
String | String |
'\u3232' 'T' '5' |
char | Character |
true, false | boolean | Logical type |
null | Object | Object reference |
"So, code consists of methods, classes, variables, etc., but literals are specific values written directly in the code. Did I get that right?"
"Yes, absolutely."
"Great. I'm finally starting to get this whole Java thing."
GO TO FULL VERSION
"Rain\nIn\nSpain\u123""Rain\nIn\nSpain\u1234"