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

Repair Windows 7 System Files

8 out of 10 average PC users have their box’s system files altered by malwares, viruses, etc. We usually reinstall the OS if the antivirus and anti malware software did not perform their job well. Here’s one way to fix the corrupted system files without the need of restarting your Windows 7 box. 1. Run the Command Prompt as Administrator 2. Type the following command C:\Windows\system32\> sfc /scannow 3. After the verification phase, you will receive a message about your system files’ integrity Windows Resource Protection did not find any integrity violations.

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.

Android Studio:Unknown Host Error

After installing Android Studio, I got the following error: Unknown host 'services.gradle.org'. Please ensure the host name is correct. If you are behind an HTTP proxy, please configure the proxy settings either in Android Studio or Gradle. Consult IDE log for more details (Help | Show Log) Solution File --> Settings --> HTTP Proxy --> Auto-detect proxy settings