About Java literals

What is a literal?

The notation of a value is called a literal. It is a constant that directly describes a numerical value or a character string, assuming that it will not be changed. Literal is an English word that means "as it is, as the original meaning of the word".

There are 6 types of literals in all.

Character literal

The value enclosed in single quotes ('). It is used when the value is one character. In general, string literals are often used, and character literals are rarely used. However, use this character literal when using special symbols.

String literal

The value is enclosed in double quotes ("). The value can be one character.

Integer literal

Refers to a value without a decimal point. You can express 2,8,10, hexadecimal numbers.

Floating point literal

Refers to a value with a decimal point. It can represent decimal numbers and exponents.

Logical value literal

Refers to the value of a logical value.

True = true False = false

null literal

When referring to reference type data, it means that nothing is referenced.

Example

In the following example, the numeric value 6 is assigned to the int type variable n, and the character string moji is assigned to the String type variable name. The substituted "6" and "moji" are "numerical literal" and "string literal", respectively. Will be.

int n = 6; String name = moji;

Summary

I understand that literals have no special meaning, they just mean "the characters as they are written".

Recommended Posts

About Java literals
About Java interface
[Java] About Java 12 features
Something about java
Where about java
About Java features
About Java threads
[Java] About interface
About Java class
About Java arrays
About java inheritance
About interface, java interface
About List [Java]
About java var
About Java commands
Java, about 2D arrays
About class division (Java)
About [Java] [StreamAPI] allMatch ()
About Java StringBuilder class
[Java] About Singleton Class
About Java method binding
[Java] About anonymous classes
About method splitting (Java)
[Java Silver] About initialization
About Java Polymorphism super ()
About inheritance (Java Silver)
About Java String class
About Java access modifiers
About Java lambda expressions
About Java entry points
About Java 10 Docker support
Personal summary about Java
[Java] About enum type
All about Java programming
About java abstract class
About Java data types (especially primitive types) and literals
A note about Java GC
What I researched about Java 8
What I researched about Java 6
[Gradle] About Java plug-in tasks
About Java variable declaration statements
What I researched about Java 9
[Java] About try-catch exception handling
[Java Silver] About equals method
[Java] About String and StringBuilder
Java
What I researched about Java 7
About =
About Alibaba Java Coding Guidelines
About Java class variables class methods
About Java Packages and imports
About abstract classes in java
Java
[Android / Java] Learned about DataBinding
What I researched about Java 5
About Java static and non-static methods
How about TECH ACADEMY ?? [Java course]
About fastqc of Biocontainers and Java
About Lambda, Stream, LocalDate of Java8
[Introduction to Java] About Stream API
Learn about transaction savepoints (with Java)