Reason to add L to the number to be put in Java long type

at first

My junior asked me, "I was asked this question by a new graduate. By the way, why? " I tried to do it myself while saying that I should do it myself, so I summarized it.

answer

When dealing with numbers in Java, it is int type by default, so Because it is necessary to explicitly indicate that it is a long to treat it as a long type (The integer value of a numeric literal is treated as an int type)

Postscript

It was as expected. That's all there is to it, so I'll add something else that interests me.

What about other integer types?

For byte and short, only numerical values are OK However, if it exceeds the range, a compile error will occur as a matter of course.

I understand byte, but the reason why s is not attached to short is a mystery (I don't see the short itself so much ...)

What is the default for decimal types?

The default decimal type is double type.

What is the ending of the decimal type?

When dealing with float type, it is necessary to explicitly add F.

You can add D when dealing with double types (you don't have to, I've never seen it)

Other languages

Scala Same as java

Python Until 2.5, it was necessary to add l or L in the case of long type like Java, After that, it seems that it is no longer necessary to be integrated

C Add l or L when dealing with long types of signed integers Add ul or UL when dealing with long types of unsigned integers

C++ Add ll or LL when dealing with long types of signed integers Add ull or ULL when dealing with long types of unsigned integers

C# Add l or L when dealing with long types of signed integers Add ul or UL when dealing with long types of unsigned integers

Recommended Posts

Reason to add L to the number to be put in Java long type
Determine if the strings to be compared are the same in Java
Java reference to understand in the figure
How to get the date in java
Add footnotes to Word documents in Java
Add SameSite attribute to cookie in Java
How to find the total number of pages when paging in Java
The intersection type introduced in Java 10 is amazing (?)
CORBA seems to be removed in Java SE 11. .. ..
[Java] Be careful of the key type of Map
Summarize the life cycle of Java objects to be aware of in Android development
There seems to be no else-if in java
Organized memo in the head (Java --Data type)
Add classpath: to the path specified in spring.datasource.schema
[Java] char type can be cast to int type
Pass the condition to be used in the Java8 lambda expression filter () as a parameter
# 1_JAVA I want to get the index number by specifying one character in the character string.
[Java] How to omit the private constructor in Lombok
Source used to get the redirect source URL in Java
Java classes and instances to understand in the figure
[Java] Things to note about type inference extended in Java 10
I tried to implement the Euclidean algorithm in Java
How to put old Java (8 series) in macOS 10.15 Catalina
Type determination in Java
How to get the class name / method name running in Java
I want to set the conditions to be displayed in collection_check_boxes
[Introduction to MVEL] Aiming to be the best MVELer in the world
Refer to C ++ in the Android Studio module (Java / kotlin)
Command to check the number and status of Java threads
[Android, Java] Convenient method to calculate the difference in days
Create a method to return the tax rate in Java
[Java] To know the type information of type parameters at runtime
Things to be aware of when writing code in Java
How to add the same Indexes in a nested array
I tried to convert a string to a LocalDate type in Java
How to derive the last day of the month in Java
How to switch Java in the OpenJDK era on Mac
[Rails] Where to be careful in the description of validation
Be sure to compare the result of Java compareTo with 0
I want to simplify the conditional if-else statement in Java
About the method to convert a character string to an integer / decimal number (cast data) in Java
Try functional type in Java! ①
4 Add println to the interpreter
Input to the Java console
Method to add the number of years and get the end of the month
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
Add a time stamp to the JAR file name in Gradle
[Android / Java] Understand the description type in listener settings (button installation)
[Java] I want to perform distinct with the key in the object
Sample code to call the Yahoo! Local Search API in Java
How to solve the unknown error when using slf4j in Java
The operator that was born to be born, instanceof (Java) ~ How to use the instanceof operator ~
[Java] How to convert from String to Path type and get the path
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
I tried to solve the past 10 questions that should be solved after registering with AtCoder in Java
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java