Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • LITERAL IN JAVA

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 236
    Comment on it

    LITERAL IN JAVA

    • A literal is a value that may be assigned to a primitive or string variable or passed as an argument to a method call.
    • Literals can be any thing like number, text or other information who represents a value.
    • Literals are used with addition to variables.

    Below are the different types of literals :-

    • Integer literals
    • Floating literals
    • Character literals
    • String literals
    • Boolean literals

    Integer literals

    We can present integer literal in decimal, octal or hexa-decimal. Out of these decimal is default one. To indicate octal, we prefix literal with 0 and for hexadecimal we prefix it with 0x.

    eg:- the value 38 can be expressed as following:-

    • 38 in decimal
    • 038 in octal
    • 0x38 in hexadecimal.

    Floating-point literals

    A floating point literal expressed a floating point numerical value. Floating point number is just as the real number of mathematics, double or float .

    The one which is default type while writing a floating point literal is doubel , but we can also specify it by simply putting D(or d) at the end of it.

    If we want to specify a literal as float we can simply put F(or f) as suffix in it.

    we can also use E for specifying floating point literal in scientific notation.

    eg:-

    • 3D in double floating point literal.
    • 0F in float floating point literal.

    Character literals

    We can expressed a character literal by simply putting it into a single quotes, like given below. eg:- char E='w'

    Boolean literals

    The only valid literals at boolean type are true and false. In java unlike c we cant thought that 1 is equal to true and 0 is equal to false. We have to use values true and false for doing this. eg:-

    • boolean is Big=true;
    • boolean is little=false;

    String literals

    string literal are always described by double quotes. eg:-

    • " " = empty string

    • "/ " = string containing

    • "Akhil" = string containing 5 character.

    • "Akhil" + "pandey" = combination of two string literals.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: