Eg int i 12 long j12l byte int long and short can be

This preview shows page 20 - 26 out of 26 pages.

Eg: int i = 12; long j=12L ; byte, int, long, and short can be expressed in decimal (base 10), hexadecimal (base 16) or octal (base 8) number systems as well. Prefix 0 is used to indicate octal and prefix 0x indicates hexadecimal when using these number systems for literals. Ex : int decimal = 100; int octal = 0144; int hexa = 0x64;
Image of page 20

Subscribe to view the full document.

Floating-point Literals By default, the floating point literals are type double. To specify the float literals, append an F or f to the constant. Eg: float f = 89.0f; double d = 89.0;
Image of page 21
Character Literals Character literals are enclosed in single quotes . Eg: char charLit = ‘a’; char a = 'A';
Image of page 22

Subscribe to view the full document.

String literals String literals in Java are specified by e enclosing a sequence of characters between a pair of double quotes Eg: String strLit = "String Literal”; String strLit2="Hello World”; String strLit3 = "two\nlines" ; String strLit4="\"This is in quotes\"" ;
Image of page 23
Java language supports few special escape sequences for String and char literals as well. They are: Escape Sequence Meaning \' Single quote \" Double quote \\ Backslash \r Carriage return \n Newline \f Form feed \t Horizontal Tab \b Backspace \ddd Octal constant(Where ddd is an octal constant) \uxxxx Hexadecimal (where xxxx is a hexadecimal constant)
Image of page 24

Subscribe to view the full document.

Program { public static void main(String args[]) { System.out.println("First line\nSecond line"); System.out.println("A\tB\tC"); System.out.println("A\nB\nC"); } }
Image of page 25
Boolean literals boolean literals are only two logical values true or false. The values true and false. Eg: boolean bF = false; boolean bT = true;
Image of page 26
  • Fall '19

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes