SlideShare a Scribd company logo
1 of 15
Data Types, Variables, Arrays
and Operators
Theandroid-mania.com
What are Variables?
 Variables are the nouns of a programming language-that
is, they are the entities (values and data) that act or are
acted upon.
 A variable declaration always contains two components:
the type of the variable and its name. The location of the
variable declaration, that is, where the declaration
appears in relation to other code elements, determines its
scope.
Theandroid-mania.com
What are Data-Types
 All variables in the Java language must have a data type. A
variable's data type determines the values that the variable
can contain and the operations that can be performed on it.
For example, the declaration
int count
declares that count is an integer (int). Integers can contain
only integral values (both positive and negative), and you
can use the standard arithmetic operators (+, -, *, and/) on
integers to perform the standard arithmetic operations
(addition, subtraction, multiplication, and division,
respectively).
Theandroid-mania.com
Data-Types
 There are two major categories of data types in the Java
language: primitive and reference.
The following table lists, by keyword, all of the primitive
data types supported by Java, their sizes and formats, and
a brief description of each.
Theandroid-mania.com
Variables
 Instance Variables (Non-Static Fields) Technically speaking, objects store 
their individual states in "non-static fields", that is, fields declared without 
the static keyword. Non-static fields are also known as instance
variables because their values are unique to eachinstance of a class (to each 
object, in other words); the currentSpeed of one bicycle is independent from 
the currentSpeed of another.
 Class Variables (Static Fields) A class variable is any field declared with 
the static modifier; this tells the compiler that there is exactly one copy of 
this variable in existence, regardless of how many times the class has been 
instantiated. A field defining the number of gears for a particular kind of 
bicycle could be marked as static since conceptually the same number of 
gears will apply to all instances. The code static int numGears = 6; would 
create such a static field. Additionally, the keyword final could be added to 
indicate that the number of gears will never change.
Theandroid-mania.com
 Local Variables Similar to how an object stores its state in fields, a method 
will often store its temporary state in local variables. The syntax for declaring 
a local variable is similar to declaring a field (for example, int count = 0;). 
There is no special keyword designating a variable as local; that 
determination comes entirely from the location in which the variable is 
declared — which is between the opening and closing braces of a method. 
As such, local variables are only visible to the methods in which they are 
declared; they are not accessible from the rest of the class.
 Parameters You've already seen examples of parameters, both in 
the Bicycle class and in the main method of the "Hello World!" application. 
Recall that the signature for the main method is public static void 
main(String[] args). Here, the args variable is the parameter to this method. 
The important thing to remember is that parameters are always classified as 
"variables" not "fields". This applies to other parameter-accepting constructs 
as well (such as constructors and exception handlers) that you'll learn about 
later in the tutorial.
Theandroid-mania.com
Naming
 The rules and conventions for naming your variables can be 
summarized as follows:
Variable names are case-sensitive. A variable's name can be any legal 
identifier — an unlimited-length sequence of Unicode letters and digits, 
beginning with a letter, the dollar sign "$", or the underscore character "_". 
The convention, however, is to always begin your variable names with a 
letter, not "$" or "_". Additionally, the dollar sign character, by convention, is 
never used at all. You may find some situations where auto-generated 
names will contain the dollar sign, but your variable names should always 
avoid using it. A similar convention exists for the underscore character; while 
it's technically legal to begin your variable's name with "_", this practice is 
discouraged. White space is not permitted.
Theandroid-mania.com
 The Java programming language is statically-typed, which means that all 
variables must first be declared before they can be used. This involves 
stating the variable's type and name, as you've already seen:
int gear = 1;
Doing so tells your program that a field named "gear" exists, holds numerical 
data, and has an initial value of "1". A variable's data type determines the 
values it may contain, plus the operations that may be performed on it. In 
addition to int, the Java programming language supports seven 
other primitive data types. A primitive type is predefined by the language 
and is named by a reserved keyword. Primitive values do not share state 
with other primitive values. The eight primitive data types supported by the 
Java programming language are:
Theandroid-mania.com
 byte: The byte data type is an 8-bit signed two's complement integer. It has
a minimum value of -128 and a maximum value of 127 (inclusive).
The byte data type can be useful for saving memory in large arrays, where
the memory savings actually matters. They can also be used in place
of int where their limits help to clarify your code; the fact that a variable's
range is limited can serve as a form of documentation.
 short: The short data type is a 16-bit signed two's complement integer. It has
a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As
with byte, the same guidelines apply: you can use a short to save memory in
large arrays, in situations where the memory savings actually matters.
 int: The int data type is a 32-bit signed two's complement integer. It has a
minimum value of -2,147,483,648 and a maximum value of 2,147,483,647
(inclusive). For integral values, this data type is generally the default choice
unless there is a reason (like the above) to choose something else. This data
type will most likely be large enough for the numbers your program will use,
but if you need a wider range of values, use long instead.
Theandroid-mania.com
 Subsequent characters may be letters, digits, dollar signs, or underscore
characters. Conventions (and common sense) apply to this rule as well.
When choosing a name for your variables, use full words instead of cryptic
abbreviations. Doing so will make your code easier to read and understand.
In many cases it will also make your code self-documenting; fields
named cadence, speed, and gear, for example, are much more intuitive than
abbreviated versions, such as s, c, and g. Also keep in mind that the name
you choose must not be a keyword or reserved word.
 If the name you choose consists of only one word, spell that word in all
lowercase letters. If it consists of more than one word, capitalize the first
letter of each subsequent word. The names gearRatio and currentGear are
prime examples of this convention. If your variable stores a constant value,
such as static final int NUM_GEARS = 6, the convention changes slightly,
capitalizing every letter and separating subsequent words with the
underscore character. By convention, the underscore character is never used
elsewhere.
Theandroid-mania.com
 byte: The byte data type is an 8-bit signed two's complement integer. It has
a minimum value of -128 and a maximum value of 127 (inclusive).
The byte data type can be useful for saving memory in large arrays, where
the memory savings actually matters. They can also be used in place
of int where their limits help to clarify your code; the fact that a variable's
range is limited can serve as a form of documentation.
 short: The short data type is a 16-bit signed two's complement integer. It has
a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As
with byte, the same guidelines apply: you can use a short to save memory in
large arrays, in situations where the memory savings actually matters.
 int: The int data type is a 32-bit signed two's complement integer. It has a
minimum value of -2,147,483,648 and a maximum value of 2,147,483,647
(inclusive). For integral values, this data type is generally the default choice
unless there is a reason (like the above) to choose something else. This data
type will most likely be large enough for the numbers your program will use,
but if you need a wider range of values, use long instead.
Theandroid-mania.com
 long: The long data type is a 64-bit signed two's complement integer. It has a
minimum value of -9,223,372,036,854,775,808 and a maximum value of
9,223,372,036,854,775,807 (inclusive). Use this data type when you need a
range of values wider than those provided by int.
 float: The float data type is a single-precision 32-bit IEEE 754 floating point.
Its range of values is beyond the scope of this discussion, but is specified in
the Floating-Point Types, Formats, and Values section of the Java Language
Specification. As with the recommendations for byte and short, use
a float (instead of double) if you need to save memory in large arrays of
floating point numbers. This data type should never be used for precise
values, such as currency. For that, you will need to use
the java.math.BigDecimal class instead. Numbers and
Strings covers BigDecimal and other useful classes provided by the Java
platform.
Theandroid-mania.com
 double: The double data type is a double-precision 64-bit IEEE 754 floating
point. Its range of values is beyond the scope of this discussion, but is
specified in the Floating-Point Types, Formats, and Values section of the Java
Language Specification. For decimal values, this data type is generally the
default choice. As mentioned above, this data type should never be used for
precise values, such as currency.
 boolean: The boolean data type has only two possible values: true and false.
Use this data type for simple flags that track true/false conditions. This data
type represents one bit of information, but its "size" isn't something that's
precisely defined.
 char: The char data type is a single 16-bit Unicode character. It has a
minimum value of 'u0000' (or 0) and a maximum value of 'uffff'(or 65,535
inclusive).
Theandroid-mania.com
Arrays
 An array is a container object that holds a fixed number of values of a single
type. The length of an array is established when the array is created. After
creation, its length is fixed. You've seen an example of arrays already, in
the main method of the "Hello World!" application. This section discusses
arrays in greater detail.
Each item in an array is called an element, and each element is
accessed by its numerical index
for ex:
declares an array of integers
int[] anArray;
allocates memory for 10 integers
anArray = new int[10];
Theandroid-mania.com
initialize elements
anArray[index] = value;
Similarly, you can declare arrays of other types:
byte[] anArrayOfBytes;
short[] anArrayOfShorts;
long[] anArrayOfLongs;
float[] anArrayOfFloats;
double[] anArrayOfDoubles;
boolean[] anArrayOfBooleans;
char[] anArrayOfChars;
String[] anArrayOfStrings;
Theandroid-mania.com

More Related Content

What's hot

DATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.netDATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.netSireesh K
 
G04124041046
G04124041046G04124041046
G04124041046IOSR-JEN
 
NLP - Sentiment Analysis
NLP - Sentiment AnalysisNLP - Sentiment Analysis
NLP - Sentiment AnalysisRupak Roy
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Deepak Singh
 
Introduction to Text Mining
Introduction to Text Mining Introduction to Text Mining
Introduction to Text Mining Rupak Roy
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part iijyoti_lakhani
 
A Text Mining Research Based on LDA Topic Modelling
A Text Mining Research Based on LDA Topic ModellingA Text Mining Research Based on LDA Topic Modelling
A Text Mining Research Based on LDA Topic Modellingcsandit
 
Text Steganography Using Compression and Random Number Generators
Text Steganography Using Compression and Random Number GeneratorsText Steganography Using Compression and Random Number Generators
Text Steganography Using Compression and Random Number GeneratorsEditor IJCATR
 
Simulation and Performance Analysis of Long Term Evolution (LTE) Cellular Net...
Simulation and Performance Analysis of Long Term Evolution (LTE) Cellular Net...Simulation and Performance Analysis of Long Term Evolution (LTE) Cellular Net...
Simulation and Performance Analysis of Long Term Evolution (LTE) Cellular Net...ijsrd.com
 
SULTHAN's - Data Structures
SULTHAN's - Data StructuresSULTHAN's - Data Structures
SULTHAN's - Data StructuresSULTHAN BASHA
 
Sienna 12 huffman
Sienna 12 huffmanSienna 12 huffman
Sienna 12 huffmanchidabdu
 
Topic Modeling - NLP
Topic Modeling - NLPTopic Modeling - NLP
Topic Modeling - NLPRupak Roy
 
IJERD (www.ijerd.com) International Journal of Engineering Research and Devel...
IJERD (www.ijerd.com) International Journal of Engineering Research and Devel...IJERD (www.ijerd.com) International Journal of Engineering Research and Devel...
IJERD (www.ijerd.com) International Journal of Engineering Research and Devel...IJERD Editor
 
I- Extended Databases
I- Extended DatabasesI- Extended Databases
I- Extended DatabasesZakaria Zubi
 

What's hot (20)

DATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.netDATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.net
 
G04124041046
G04124041046G04124041046
G04124041046
 
NLP - Sentiment Analysis
NLP - Sentiment AnalysisNLP - Sentiment Analysis
NLP - Sentiment Analysis
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
 
Introduction to Text Mining
Introduction to Text Mining Introduction to Text Mining
Introduction to Text Mining
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
 
Python 3.x quick syntax guide
Python 3.x quick syntax guidePython 3.x quick syntax guide
Python 3.x quick syntax guide
 
A Text Mining Research Based on LDA Topic Modelling
A Text Mining Research Based on LDA Topic ModellingA Text Mining Research Based on LDA Topic Modelling
A Text Mining Research Based on LDA Topic Modelling
 
Text Steganography Using Compression and Random Number Generators
Text Steganography Using Compression and Random Number GeneratorsText Steganography Using Compression and Random Number Generators
Text Steganography Using Compression and Random Number Generators
 
Simulation and Performance Analysis of Long Term Evolution (LTE) Cellular Net...
Simulation and Performance Analysis of Long Term Evolution (LTE) Cellular Net...Simulation and Performance Analysis of Long Term Evolution (LTE) Cellular Net...
Simulation and Performance Analysis of Long Term Evolution (LTE) Cellular Net...
 
SULTHAN's - Data Structures
SULTHAN's - Data StructuresSULTHAN's - Data Structures
SULTHAN's - Data Structures
 
Sienna 12 huffman
Sienna 12 huffmanSienna 12 huffman
Sienna 12 huffman
 
Oo ps exam answer2
Oo ps exam answer2Oo ps exam answer2
Oo ps exam answer2
 
Ir 03
Ir   03Ir   03
Ir 03
 
Ir 02
Ir   02Ir   02
Ir 02
 
Topic Modeling - NLP
Topic Modeling - NLPTopic Modeling - NLP
Topic Modeling - NLP
 
Text Mining Analytics 101
Text Mining Analytics 101Text Mining Analytics 101
Text Mining Analytics 101
 
IJERD (www.ijerd.com) International Journal of Engineering Research and Devel...
IJERD (www.ijerd.com) International Journal of Engineering Research and Devel...IJERD (www.ijerd.com) International Journal of Engineering Research and Devel...
IJERD (www.ijerd.com) International Journal of Engineering Research and Devel...
 
I- Extended Databases
I- Extended DatabasesI- Extended Databases
I- Extended Databases
 
Binary Trees
Binary TreesBinary Trees
Binary Trees
 

Viewers also liked

Data Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsData Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsAbdullah Al-hazmy
 
Data array and frequency distribution
Data array and frequency distributionData array and frequency distribution
Data array and frequency distributionraboz
 
frequency distribution table
frequency distribution tablefrequency distribution table
frequency distribution tableMonie Ali
 
Frequency Distributions and Graphs
Frequency Distributions and GraphsFrequency Distributions and Graphs
Frequency Distributions and Graphsmonritche
 
Chapter 2: Frequency Distribution and Graphs
Chapter 2: Frequency Distribution and GraphsChapter 2: Frequency Distribution and Graphs
Chapter 2: Frequency Distribution and GraphsMong Mara
 

Viewers also liked (6)

Array,data type
Array,data typeArray,data type
Array,data type
 
Data Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithmsData Structures- Part3 arrays and searching algorithms
Data Structures- Part3 arrays and searching algorithms
 
Data array and frequency distribution
Data array and frequency distributionData array and frequency distribution
Data array and frequency distribution
 
frequency distribution table
frequency distribution tablefrequency distribution table
frequency distribution table
 
Frequency Distributions and Graphs
Frequency Distributions and GraphsFrequency Distributions and Graphs
Frequency Distributions and Graphs
 
Chapter 2: Frequency Distribution and Graphs
Chapter 2: Frequency Distribution and GraphsChapter 2: Frequency Distribution and Graphs
Chapter 2: Frequency Distribution and Graphs
 

Similar to Data types ,variables,array

About size_t and ptrdiff_t
About size_t and ptrdiff_tAbout size_t and ptrdiff_t
About size_t and ptrdiff_tPVS-Studio
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data typesManisha Keim
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsatifmugheesv
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiSowmyaJyothi3
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.pptAqeelAbbas94
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6REHAN IJAZ
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGEPRASANYA K
 
cprogrammingdatatype.ppt
cprogrammingdatatype.pptcprogrammingdatatype.ppt
cprogrammingdatatype.pptYRABHI
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfYRABHI
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programmingHarshita Yadav
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introductionnikshaikh786
 

Similar to Data types ,variables,array (20)

C++ data types
C++ data typesC++ data types
C++ data types
 
Data type
Data typeData type
Data type
 
About size_t and ptrdiff_t
About size_t and ptrdiff_tAbout size_t and ptrdiff_t
About size_t and ptrdiff_t
 
Computer programming 2 Lesson 5
Computer programming 2  Lesson 5Computer programming 2  Lesson 5
Computer programming 2 Lesson 5
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Variable
VariableVariable
Variable
 
Datatypes
DatatypesDatatypes
Datatypes
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4
 
cprogrammingdatatype.ppt
cprogrammingdatatype.pptcprogrammingdatatype.ppt
cprogrammingdatatype.ppt
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Data types in C
Data types in CData types in C
Data types in C
 

More from Gujarat Technological University (6)

Readme
ReadmeReadme
Readme
 
Ppt ppb module a
Ppt ppb   module aPpt ppb   module a
Ppt ppb module a
 
Object Oriented Programing and JAVA
Object Oriented Programing and JAVAObject Oriented Programing and JAVA
Object Oriented Programing and JAVA
 
XML - The Extensible Markup Language
XML - The Extensible Markup LanguageXML - The Extensible Markup Language
XML - The Extensible Markup Language
 
Creating classes and applications in java
Creating classes and applications in javaCreating classes and applications in java
Creating classes and applications in java
 
Collections
CollectionsCollections
Collections
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 

Data types ,variables,array

  • 1. Data Types, Variables, Arrays and Operators Theandroid-mania.com
  • 2. What are Variables?  Variables are the nouns of a programming language-that is, they are the entities (values and data) that act or are acted upon.  A variable declaration always contains two components: the type of the variable and its name. The location of the variable declaration, that is, where the declaration appears in relation to other code elements, determines its scope. Theandroid-mania.com
  • 3. What are Data-Types  All variables in the Java language must have a data type. A variable's data type determines the values that the variable can contain and the operations that can be performed on it. For example, the declaration int count declares that count is an integer (int). Integers can contain only integral values (both positive and negative), and you can use the standard arithmetic operators (+, -, *, and/) on integers to perform the standard arithmetic operations (addition, subtraction, multiplication, and division, respectively). Theandroid-mania.com
  • 4. Data-Types  There are two major categories of data types in the Java language: primitive and reference. The following table lists, by keyword, all of the primitive data types supported by Java, their sizes and formats, and a brief description of each. Theandroid-mania.com
  • 5. Variables  Instance Variables (Non-Static Fields) Technically speaking, objects store  their individual states in "non-static fields", that is, fields declared without  the static keyword. Non-static fields are also known as instance variables because their values are unique to eachinstance of a class (to each  object, in other words); the currentSpeed of one bicycle is independent from  the currentSpeed of another.  Class Variables (Static Fields) A class variable is any field declared with  the static modifier; this tells the compiler that there is exactly one copy of  this variable in existence, regardless of how many times the class has been  instantiated. A field defining the number of gears for a particular kind of  bicycle could be marked as static since conceptually the same number of  gears will apply to all instances. The code static int numGears = 6; would  create such a static field. Additionally, the keyword final could be added to  indicate that the number of gears will never change. Theandroid-mania.com
  • 6.  Local Variables Similar to how an object stores its state in fields, a method  will often store its temporary state in local variables. The syntax for declaring  a local variable is similar to declaring a field (for example, int count = 0;).  There is no special keyword designating a variable as local; that  determination comes entirely from the location in which the variable is  declared — which is between the opening and closing braces of a method.  As such, local variables are only visible to the methods in which they are  declared; they are not accessible from the rest of the class.  Parameters You've already seen examples of parameters, both in  the Bicycle class and in the main method of the "Hello World!" application.  Recall that the signature for the main method is public static void  main(String[] args). Here, the args variable is the parameter to this method.  The important thing to remember is that parameters are always classified as  "variables" not "fields". This applies to other parameter-accepting constructs  as well (such as constructors and exception handlers) that you'll learn about  later in the tutorial. Theandroid-mania.com
  • 7. Naming  The rules and conventions for naming your variables can be  summarized as follows: Variable names are case-sensitive. A variable's name can be any legal  identifier — an unlimited-length sequence of Unicode letters and digits,  beginning with a letter, the dollar sign "$", or the underscore character "_".  The convention, however, is to always begin your variable names with a  letter, not "$" or "_". Additionally, the dollar sign character, by convention, is  never used at all. You may find some situations where auto-generated  names will contain the dollar sign, but your variable names should always  avoid using it. A similar convention exists for the underscore character; while  it's technically legal to begin your variable's name with "_", this practice is  discouraged. White space is not permitted. Theandroid-mania.com
  • 8.  The Java programming language is statically-typed, which means that all  variables must first be declared before they can be used. This involves  stating the variable's type and name, as you've already seen: int gear = 1; Doing so tells your program that a field named "gear" exists, holds numerical  data, and has an initial value of "1". A variable's data type determines the  values it may contain, plus the operations that may be performed on it. In  addition to int, the Java programming language supports seven  other primitive data types. A primitive type is predefined by the language  and is named by a reserved keyword. Primitive values do not share state  with other primitive values. The eight primitive data types supported by the  Java programming language are: Theandroid-mania.com
  • 9.  byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.  short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.  int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long instead. Theandroid-mania.com
  • 10.  Subsequent characters may be letters, digits, dollar signs, or underscore characters. Conventions (and common sense) apply to this rule as well. When choosing a name for your variables, use full words instead of cryptic abbreviations. Doing so will make your code easier to read and understand. In many cases it will also make your code self-documenting; fields named cadence, speed, and gear, for example, are much more intuitive than abbreviated versions, such as s, c, and g. Also keep in mind that the name you choose must not be a keyword or reserved word.  If the name you choose consists of only one word, spell that word in all lowercase letters. If it consists of more than one word, capitalize the first letter of each subsequent word. The names gearRatio and currentGear are prime examples of this convention. If your variable stores a constant value, such as static final int NUM_GEARS = 6, the convention changes slightly, capitalizing every letter and separating subsequent words with the underscore character. By convention, the underscore character is never used elsewhere. Theandroid-mania.com
  • 11.  byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.  short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.  int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long instead. Theandroid-mania.com
  • 12.  long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int.  float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and other useful classes provided by the Java platform. Theandroid-mania.com
  • 13.  double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.  boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.  char: The char data type is a single 16-bit Unicode character. It has a minimum value of 'u0000' (or 0) and a maximum value of 'uffff'(or 65,535 inclusive). Theandroid-mania.com
  • 14. Arrays  An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. You've seen an example of arrays already, in the main method of the "Hello World!" application. This section discusses arrays in greater detail. Each item in an array is called an element, and each element is accessed by its numerical index for ex: declares an array of integers int[] anArray; allocates memory for 10 integers anArray = new int[10]; Theandroid-mania.com
  • 15. initialize elements anArray[index] = value; Similarly, you can declare arrays of other types: byte[] anArrayOfBytes; short[] anArrayOfShorts; long[] anArrayOfLongs; float[] anArrayOfFloats; double[] anArrayOfDoubles; boolean[] anArrayOfBooleans; char[] anArrayOfChars; String[] anArrayOfStrings; Theandroid-mania.com