Questions And Answers

More Tutorials

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.

    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;
            String str = "Harry";




    In this page (written and validated by ) you learned about Java Literals . What's Next? If you are interested in completing Java tutorial, your next topic will be learning about: Java Getting User Input.

    Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

    Share On:

    Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.