0% found this document useful (0 votes)
2 views

Class

Java is a platform-independent language that utilizes the Java Virtual Machine (JVM) for execution. It has 53 keywords, with 51 being used, and includes rules for identifiers and data types, such as primitive types and their ranges. The document also outlines how to compile and run Java programs, as well as flow control statements including conditional and iterative statements.

Uploaded by

NIRANJAN BEHERA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Class

Java is a platform-independent language that utilizes the Java Virtual Machine (JVM) for execution. It has 53 keywords, with 51 being used, and includes rules for identifiers and data types, such as primitive types and their ranges. The document also outlines how to compile and run Java programs, as well as flow control statements including conditional and iterative statements.

Uploaded by

NIRANJAN BEHERA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

20-05-2024:

Java is Platform independent Language --> JVM (Java Virtual Machine).

Once You write and Run anywhere.

Keywords:

1. How to use
2. Where to use
3. What is the purpose

In java, 53 keywords:

Unused Keywords (2): goto, const

Used Keywords (51):

Reserved Keywords (3): true, false, null (default value for object reference)

Keywords(48):

Identifiers:

 Any name in the programming language is an identifier.


 Class name, method name, variable name, package name, interface name etc.
 Identifier Rules:
 It contains lower case (a – z) and upper case (A – Z) alphabetic, digits (0 to 9), and underscore
and $.
 It does not start with digits.
 It should not be any keyword.
 It does not contain space.
 Ex:
 1) Abc  Y
 2) a234  Y
 3)_456  Y
 4) _abc_  Y
 5) 4xyz  N
 6) xyz abc  N
 7) xyz_abc  Y
 Note: Any predefined Java class name/interface name can be used as an identifier.

How to compile a Java Program: javac FileName.java

How to run a java program: java FileName

To display a message on the monitor: System.out.println(“Message”);


Data Types: ( 8)

 It indicates what type of data to be stored in a variable.


 Primitive data types:
 Numbers: ( Signed and Unsigned)
1) Integral Numbers: byte, short, int, long
2) Float point numbers: float, double
 Characters: (Unsigned) char
 Boolean : true and false.
 Note: The default data type of Boolean is double. If we want to define a float value then the
value must be a suffix with f/F.
Ex: float f1=3.27  Not valid, 3.27 is considered as double by default.
float f2=3.27f  Valid.
float f3=3.27F  Valid.

2 16  65536  (-32768 to 32767)  (-215 to 215 -1).


2 8  256  ( -128 to 127)  (-27 to 27 -1).

S.No Data Type Memory Range Default Wrapper Class


Value
1 byte 1B -128 to 127 0 Byte
2 short 2B (-215 to 215 -1) 0 Short
3 int 4B (-231 to 231 -1) 0 Integer
4 long 8B (-263 to 263 -1). 0 Long
5 float 4B -3.4e38 to 0.0 Float
3.4e38
6 double 8B -1.7e308 to 0.0 Double
1.7e308
7 char 2B 0 to 65535 0 (space Character
character)
8 boolean NA NA false Boolean

Literals:

Any value which is stored in a variable.

Ex: int i=10;  10 is integer literal, i is variable, int is a data type.

int i1 = 10; // Decimal and its range of digits( 0 to 9).

int i2 = 0123; // Octal, its value must be prefixed with 0 and its range of digits( 0 to 7).

int i3 = 0xABC // Hexadecimal value prefixed with 0x and its range of digits( 0 to 9 and a/A to f/F).

float f1=3.27  Not valid, 3.27 is considered as double by default.


float f2=3.27f  Valid.

float f3=3.27F  Valid.

double d1=3.27; // Valid

char c1 = ‘a’;

boolean b1 = true; //V

boolean b2 = false; //V

boolean b1 = True; // Not valid

boolean b2 = False; // Not valid

boolean b1 = “true”; // Not valid

boolean b2 = “false”; // Not valid

boolean b3 = 1; // Not valid

Flow Control:

1) Conditional Statements: if, if-else, else if ladder


2) Iterative Statements/Loops: do- while, while, and for
3) Transfer Statements: break, continue, and return.

if: To execute a block statement.

Syntax:

if(condition)

Block;

If-else: To execute one block out of 2 blocks.

Syntax:

if(condition)

Block-1;
}

else

Block-2;

else if ladder: To execute one block out of more than 2 blocks.

Syntax:

if(condition)

Block-1;

else if(con2)

Block-2;

else

Block-n

Do-while: To execute the block at least once.

Syntax:

Initialization;

do

{
// do the task

++/--

}while(Con);

while: To execute the block until the condition is satisfied.

Syntax:

Initialization;

while(Con)

// do the task

++/--

for: If we know the number of interactions in advance.

Syntax:

for (initialization; Con;++/--) Initialization; Initialization;


{ for ( ; Con;++/--) for ( ; Con ; )
//Do the task { {
} //Do the task //Do the task
} ++/--
}

break: To terminate the loop based on the condition.

continue: To skip the current iteration and continue with the next iteration.

EX: class Literal


int i=10; {
while(i<=100) public static void main(String a[])
{ {
if(i==50) int i=10;
break; while(i<100)
System.out.println(i); {
i=i+10; if(i==50)
} {
Output: i=i+10;
D:\Wipro-2021 Batch\Programs>java Literal continue;
10 }
20 System.out.println(i);
30 i=i+10;
40 }
}
}
Output:
D:\Wipro-2021 Batch\Programs>java Literal
10
20
30
40
60
70
80
90
Note:

1. In Java, the 1st letter of each word must be the capital letter for the class name.
Ex: StudentData, EmployeeDetails, etc.
2. In Java, the 1st letter from the 2nd word onwards must be the capital letter for the method name.
Ex: displayName(), sumOfNumbers() etc.
3. Every statement must end with a semicolon.
4.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy