0% found this document useful (0 votes)
28 views3 pages

2-Comments, Escape Sequence, Keywords, Scanner, Identifier, Variables-26-07-2022 (26-Jul-2022) Material - I - 26-07-2022 - 26.07.2022

This document discusses key concepts in Java programming including comments, escape sequences, keywords, getting user input, identifiers, and variables. Single-line and block comments are explained along with common escape sequences like \n and \t. The 60 Java keywords are listed. Getting user input via the Scanner class is demonstrated. Rules for identifiers and variables are outlined such as their composition, declaration, and initialization.

Uploaded by

suyash agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

2-Comments, Escape Sequence, Keywords, Scanner, Identifier, Variables-26-07-2022 (26-Jul-2022) Material - I - 26-07-2022 - 26.07.2022

This document discusses key concepts in Java programming including comments, escape sequences, keywords, getting user input, identifiers, and variables. Single-line and block comments are explained along with common escape sequences like \n and \t. The 60 Java keywords are listed. Getting user input via the Scanner class is demonstrated. Rules for identifiers and variables are outlined such as their composition, declaration, and initialization.

Uploaded by

suyash agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSE1007 – JAVA PROGRAMMING

26.07.2022

Comment Statements

• Single line comments

• // This is a comment

• Block comments (or) Multiline comments

• /* This is a block comment */

• /* This is a

block comment */

Escape Sequence

• \n - New line

• \t - Horizontal tab

• \r - Carriage return – returns the cursor to the beginning of current line

• \\ - Print backslash

• \” - Print Double quotation

Keywords

1. abstract 16. enum 31. module

2. assert 17. exports 32. native

3. Boolean 18. extends 33. new

4. break 19. final 34. open

5. byte 20. finally 35. opens

6. case 21. float 36. package

7. catch 22. for 37. private

8. char 23. goto 38. protected

9. class 24. if 39. provides

10. const 25. implements 40. public

11. continue 26. import 41. requires

12. default 27. instanceof 42. return

13. do 28. int 43. short

14. double 29. interface 44. static

15. else 30. long 45. strictfp


46. super 51. throws 56. uses

47. switch 52. to 57. void

48. synchronized 53. transient 58. volatile

49. this 54. transitive 59. while

50. throw 55. try 60. with

Get Input from user

• Input from console is not directly supported by Java

• Import package:

• Specific import

• import java.util.Scanner;

• Wildcard import

• import java.util.*;

• Scanner name = new Scanner(System.in);

• Example: GetInput.java

import java.util.Scanner;
public class GetInput
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter a radius:");
double radius = input.nextDouble();
double area = radius * radius * 3.14;
System.out.println("Radius: "+radius+"Area:"+area);
}
}

Identifier

• Used to identify classes, methods and variables

• Sequence of characters

• letters a-z, A-Z

• digits 0-9

• underscores _

• dollar sign $
• Starts with

• letter

• dollar sign

• underscore

• Cannot start with digit

• Cannot be a reserved word

• Cannot be true, false or null

• Can be of any length

Variables

• Names to represent values that may be changed in a program

• Syntax for declaration:

• datatype varName;

• datatype var1, var2, var3;

• Variable must be declared before assigning values

• Variables must be assigned values before usage

• Initialization:

• Static: int a = 3;

• Dynamic:

• double a = 0.3, b = 0.3;

• double c = Math.sqrt(a*a+b*b);

You might also like