Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java


Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

Previous Home Next

Literals in Java are a sequence of characters (digits, letters, and other characters) that represent constant values to be stored in variables. In Java programming language there are some special type of literals that represent numbers, characters, strings and boolean values. A literal represent a constant value which we cant change . A literal is a value specified in the source code it is not determined at run time.

    Types of Literals

  1. Java integers are stored internally as binary numbers, but can appear in source programs as ordinary decimals. Java integer literals are by default constant of int type.
  2. 5,-5 , 0x5A, 012,5l, 5L are integer literals in which 5 ,-5 are decimal ,0x5A is a hexadecimal, 012 is a octal, l or L is for long.

    Java integer literals are by default constant of int type,

    Java integer literals can be sequences of decimal digits, optionally preceded by a minus sign for negative integers.

    Example :



    Java integer literals cannot contain any blanks or commas.

    Example :

    45 12 // error occurs no space between integers 
    45,12 // no comma between the numbers 

    There should be no blank space between the minus sign (-) and the number for negative integers.

    Example :

    - 1253 // error occurs no space between - sign and number
    class Num 
    	public static void main(String[] args)
    		int decimal = 100// 100 decimal.
    		int octal = 0144// decimal 100 represented in octal base.
    		int hex = 0x64// decimal 100 represented in hexadecimal base.
    		int bin = 0b1100100; // decimal 100 represented in binary base
    		System.out.println(decimal); // Prints '100'
    		System.out.println(octal); // Prints '100'
    		System.out.println(hex); // Prints '100'
    		System.out.println(bin); // Prints '100'
  3. 5.23, -5.23, 5.4f, 5.4F, 5.4d, 5.4D, 1.2E-03 are floating point literals where f or F is for single precision (float ), d or D is for double precision , 5.23 is a standard notation and 1.2E-03 is in exponent notation (scientific notation ) where 1.2 is mantissa and -03 is exponent.
  4. Example :

    class Flow
    	public static void main(String args[])
    		float a=0.000000000000000000123f;

    output :

  5. 'a', 'A', '\n', '\141', '\u0061' are character literals in which '\n' is an escape sequence.'\141' is octal code for character 'a' and '\u0061' is hexa-decimal code for character 'a'. Java characters are sixteen bit Unicode characters, ranging from 0 to 65535.
  6. Example :

    class A
    	public static void main(String args[])
    		char ch='a';
    		if(ch>=97 && ch<=122)

    output :

  7. "matrix " is a string literal. String is a group of characters. in java string there is no line continuation escape sequence as there in other language. So string must begin and end on the same line, in java string are of object type ."\" this is in quotes"\". In Java a string is not a basic data type, rather it is an object. There are few methods provided in Java to combine strings, We represent string literals as:
  8. String str = "How are you?";

    Example :

    char[] a = { 'h', 'e', 'l', 'l', 'o', '.'}; 
    String helloStr = new String(a); 
  9. true, false are boolean literal .true and false are not eqial to 1 or 0 in java. we can't convert a boolean value to integer and vice-versa.
  10. Example :

    public class A 
    	public static void main(String[] args) 
    		boolean Sign = true;
    Previous Home Next

    Tolal:0 Click:

    Show All Comments

    Did not find what you were looking for leave your name and message. We will revert within 24 hours
    Comment / Feedback: