Skip to content

Files

Latest commit

 

History

History

4.Literals

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Java Tutorial: Literals in Java

Literals

  • A constant value that can be assigned to the variable is called a literal.
  • 101 – Integer literal
  • 10.1f – float literal
  • 10.1 – double literal (default type for decimals)
  • ‘A’ – character literal
  • true – Boolean literal
  • “Harry” – String literal

Keywords

  • Words that are reserved and used by the Java compiler. They cannot be used as an Identifier.
  • {You can visit docs.oracle.com for a comprehensive list}

Code as Described in the Video

package com.company;

public class CWH_04_literals {
    public static void main(String[] args) {
        byte age = 34;
        int age2 = 56;
        short age3 = 87;
        long ageDino = 5666666666666L;
        char ch = 'A';
        float f1 = 5.6f;
        double d1 = 4.66;
        boolean a = true;
        
        System.out.print(age);
        
        String str = "Harry";
        
        System.out.println(str);
    }
}

Handwritten Notes: Click To Download

Ultimate Java Cheatsheet: Click To Download