0% found this document useful (0 votes)
4 views22 pages

unit 1

The document provides an overview of Java programming concepts, including primitive data types like int, double, and boolean, as well as the use of comments and keywords. It explains the significance of variables and identifiers, detailing rules for naming them, and introduces operators for performing operations. Overall, it serves as an introductory guide to fundamental Java programming elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views22 pages

unit 1

The document provides an overview of Java programming concepts, including primitive data types like int, double, and boolean, as well as the use of comments and keywords. It explains the significance of variables and identifiers, detailing rules for naming them, and introduces operators for performing operations. Overall, it serves as an introductory guide to fundamental Java programming elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Unit 1

Primitive Types
Hello World

Java source Complier Run program


code
Hello World
Call System class methods to generate output to the console.

• System.out.print and System.out.println display information on the

computer monitor.

• System.out.println moves the cursor to a new line after the information

has been displayed, while System.out.print does not.


Comments
Comments
comments are the statements that are not executed by the compiler and interpreter. The
comments can be used to provide information or explanation about the variable, method, class
or any statement. It can also be used to hide program code.

//This is single line comment

/*
This
is
multi line
comment
*/
Keywords
Keywords
keywords are also known
as reserved words.
Keywords are particular
words which acts as a key to
a code. These are predefined
words by Java so it cannot be
used as a variable or object
name
Constant
Data Type
Data Types
Data Types
int

•Int data type is a 32-bit signed two's complement integer.

•Minimum value is - 2,147,483,648 (-2^31)

•Maximum value is 2,147,483,647(inclusive) (2^31 -1)

•Integer is generally used as the default data type for integral values

unless there is a concern about memory.

•The default value is 0


Data Types
double

• double data type is a double-precision 64-bit IEEE 754 floating point

• This data type is generally used as the default data type for decimal

values, generally the default choice

• Double data type should never be used for precise values such as

currency

• Default value is 0.0d


Data Types
boolean

• boolean data type represents one bit of information

• There are only two possible values: true and false

• This data type is used for simple flags that track true/false

conditions

• Default value is false


Variables

location

modify
5 4
Variables

location

5
Variables
• Variable is name of reserved area allocated in memory. In other
words, it is a name of memory location
• Based on the data type of a variable, the operating system allocates
memory and decides what can be stored in the reserved memory
• It is a combination of "vary + able" that means its value can be
changed
location variable

data type

5 value
Variables
Identifier
• Identifiers in Java are symbolic names used for identification.
They can be a class name, variable name, method name,
package name, constant name, and more.
• Key words can not be used as an identifier

1.HelloJava (Class name)


2.main (main method)
3.String (Predefined Class
name)
4.args (String variables)
5.System (Predefined class)
6.out (Variable name)
7.println (method)
Identifier
Following are some rules and conventions for declaring identifiers:
1. A valid identifier must have characters [A-Z] or [a-z] or numbers [0-
9], and underscore(_) or a dollar sign ($). for example, @javatpoint
is not a valid identifier because it contains a special character which
is @.
2. There should not be any space in an identifier. For example, java
tpoint is an invalid identifier.
3. An identifier should not contain a number at the starting. For
example, 123javatpoint is an invalid identifier.
4. An identifier should be of length 4-15 letters only. However, there is
no limit on its length. But, it is good to follow the standard
conventions.
5. We can't use the Java reserved keywords as an identifier such as int,
float, double, char, etc. For example, int double is an invalid
identifier in Java.
Identifier
•TestVariable •java_&_Tpoint
•Test Variable •Jtp123
•testvariable •a-javatpoint
•a •JavaTpoint
•i •java+tpoint
•Test_Variable •Javatpoint123
•_testvariable •123javatpoint
•$testvariable •Java'tpoint
•sum_of_array
•TESTVARIABLE
Operators
Operator in Java is a symbol which is used to perform
operations.
int x = 0; int x = 0;
int y = 1; int y = 1;
int z = 2; int z = 2;
x = y; x--;
y = y * 2; y++;
z = 3; z+=y;

A 0, 1, 2 A 1, -1, 4
B 1, 2, 3 B -1, 2, 3
C 2, 2, 3 C -1, 2, 2
D 0, 0, 3 D -1, 2, 2
E -1, 2, 4

You might also like