Skip to main content

Literals in Java

Literals are values found in the source code and are known at compile time.


[boolean literals]


Each boolean type can only hold a literal true or a literal false. Boolean types can not hold numbers unlike in C/C++.



true
false

[char literals]


A char literal can be represented by a single character enclosed in single quotes.



char netPacket = 'K';

Another valid representation is in the form of a Unicode.



char netPacket = '\uCAFE';

The following are also valid, these are special characters represented by using escape sequences.


new line



'\n'

tab



'\t'

backspace



'\b'

form feed



'\f'

carriage return



'\r'

single quote



'\''

double quote



'\"'

backslash



'\\'

[integral literals]


Integral literals can be represented in 3 ways, octal, decimal, hexadecimal. Octal representations are preceded by a 0. Decimal representations contain no prefixes / suffixes. Hexadecimal representations are prefixed with 0x.


decimal



814

octal



031

hexadecimal



0xCAFEBED

[floating-point literals]


Floating-point literals are represented by floating-point numbers. A floating-point number must have one of the following:


decimal point (.)



8888.8888

scientific notation (e / E)



8.88E+8

suffixes (d / D for double & f / F for float)



8F, 8.8D

Comments

Popular posts from this blog

Architecture Complexity

Here are the items to consider: Coding to an interface Service Oriented Architecture Automated Testing Domain Driven Design Custom Data Access Layer Layered architecture Complexity is relatively equal the number of lines of code. Note that complexity is not bad. It must be justified.

Importance of daily meetings

Why are daily meetings important? Yes I know what you are thinking, to check if the schedule is on target, to spot showstoppers, roadblocks and whatnots. But aside from those, there are things that make daily meetings rewarding. Let’s face it, some people (including me) find it hard oftentimes to achieve a certain level of focus at work especially when multitasking is inevitable. Meetings will remind us of our commitments infront of our peers. Since most of us will be ashamed of not making any progress, it will trigger ourselves to do something about it. In my opinion, having daily meetings typically before the shift starts will help a lot of peers suffering from bad habits - procrastination. It is one way of invigorating those who have not found their way out yet. “Keep each other in the zone, what are teammates for?”