0% found this document useful (0 votes)
12 views4 pages

Understanding Variables and Data Types in Java

The document explains the concept of variables as containers for data, highlighting their ability to change values. It details data types, distinguishing between primitive and non-primitive types, and provides examples of variable declarations. Additionally, it covers the usage of the 'var' keyword and outlines various operators in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Understanding Variables and Data Types in Java

The document explains the concept of variables as containers for data, highlighting their ability to change values. It details data types, distinguishing between primitive and non-primitive types, and provides examples of variable declarations. Additionally, it covers the usage of the 'var' keyword and outlines various operators in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Variables

---------

* Variable is a container which can hold data.

* To represent data we need variables.

* Can change the value of variables at any time

data collect , data process or categories , data store , data retrive

customer name : priya

contact number : 5987235823

mail id : @[Link]

designation : MD

location : india

bank balance : 100000000

Eg:

--

x=100

age=20

name=java

// Invalid identifiers:

int 2ndNumber = 5; // Cannot start with a digit

int my var = 10; // Cannot contain spaces

int int = 20; // Cannot use reserved keywords

Data types

-----------

To represent the type of date it is used.

Eg:

---

String
integer

float

Double etc

Types of Data Types

--------------------

1 Primitive

------------

Declared using small letters

Holds single variable

Eg: byte, short, int(whole numbers)

long, float, double(decimal numbers)

char(single character written inside''

boolean(true/false)

2 Non-Primitive

----------------

Starts with capital letters

Multiple variables

Eg: String

ArrayList

HashMap etc

Declaration

-----------

datatype variable = assignment

Eg:

---

int x=100;

float price=225.50f;
String name="Welcome";

char grade='A';

boolean =true;

float f1 = 35e3f;

double d1 = 12E4d;

char myVar1 = 65

int a=100; //variables values can change any time

Difference between primitive and non-primitive datatype

------------------------------------------------------------

[Link] types always hold a value, whereas non-primitive types can be null.

[Link] types start with a lowercase letter (like int), while non-primitive types
typically starts with an uppercase letter (like String).

Usage of VAR keyword

-------------------------------

var myNum = 5; // int

var myDouble = 9.98; // double

var myChar = 'D'; // char

var myBoolean = true; // boolean

var myString = "Hello"; // String

Constant in Java

------------------------------------------

final int MINUTES_PER_HOUR = 60;

OPERATORS in JAVA

-------------------

Arithmetic operators (+,-,*,/,%,++,--)

Assignment operators (= , +=, -=, )


Comparison operators (>,<, !=, ==, <=,>=)

Logical operators (&&, || , !)

...........................

Task to learn order of operation

----------------------------------

You might also like