Constants, variables and data types in java

50 %
50 %
Information about Constants, variables and data types in java
Education

Published on April 26, 2014

Author: atulsehdev91

Source: slideshare.net

Description

Introduction, Constants, Integer constant, Real Constants, Character Constants, String constant, Backslash character constant, Data Types

CONSTANTS, VARIABLES AND DATA TYPES

Introduction • A programming language is designed to process certain kind of data consisting of numbers, characters and string and to provide useful output called information • The task of processing data is accomplished by executing a sequence of instruction known as program. • The instructions are formed using certain symbols and words according to some rigid rules known as syntax rule or grammar. • Like any other language java also have its own vocabulary and grammar. Know we will discuss concepts of constants and variable and their data type.

Constants

Integer constant An integer constant refers to a sequence of digits. There are three types of integers, namely, decimal integer, octal integer and hexadecimal integer • Decimal integer: - consist of a set of digit through 0 to 9, which may be proceeded by optional sign minus e.g. 7897,-64864, and 0 etc. • Octal integer: - consist of a set of digit through 0 to 7, with preceding 0. For example: - 037, 0 0465, etc. • Hexadecimal integer: - consist of a set of digit through 0 to 9 and A through F or a through f, with preceding 0x or 0X. For example: - 0x37, 0x, 0X465AF, 0xfcb23, etc.

Real Constants The quantities which are represented by numbers containing fraction parts are known as Real or Floating point constant. For example 0.0086, -0.75 etc • A real number can also be represented in scientific notation like 2.15e2 here e2 means 102. • The general syntax is Mantissa e exponent

Character Constants A single character constant contains a single character enclosed with in a pair of single quote mark. Example: - ‘a’,’A’,’12’

String constant A string constant is a sequence of character enclosed between double quote. Example: “hello”, ”java”

Backslash character constant Java Also Supports Backslash Constants those are used in output methods For Example n is used for new line Character. These are also called as escape Sequence or backslash character Constants. Backslash Code Description t tab character n new line or line feed character r carriage-return character f form-feed character a alert or bell character e escape character cx control character corresponding to x backslash character 0n character with octal value 0nn character with octal value 0mnn character with octal value xhh character with hexadecimal value uhhhh character with hexadecimal value

Data Types

INTEGER TYPES • An integer is a whole number — that is, a number with no fractional or decimal portion. Java has four integer types, which you can use to store numbers of varying sizes. Type Number of Bytes Range of Values byte 1 –128 to +127 short 2 –32,768 to +32,767 int 4 –2 billion to +2 billion long 8 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Floating point types • Floating-point numbers are numbers that have fractional parts (usually expressed with a decimal point). You use a floating-point type in Java programs whenever you need a number with a decimal, such as 19.95 or 3.1415. • Java has two primitive types for floating- point numbers: • float: Uses 4 bytes • double: Uses 8 bytes • In almost all cases, you should use the double type whenever you need numbers with fractional values.

Character type • char data type is a single 16-bit Unicode character. • Minimum value is 'u0000' (or 0). • Maximum value is 'uffff' (or 65,535 inclusive). • Char data type is used to store any character. • Example . char letterA ='A'

Boolean Type • 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. Example : boolean one = true

Add a comment

Related presentations

Related pages

Java Constants, Variables, and Datatypes - DePaul University

Java Constants, Variables, and Datatypes Java Constants A constant is a value that cannot be changed. ... A string in Java is not a primitive data type.
Read more

Variables, Constants, and Data Types

Variables, Constants, and Data Types ... • There are eight primitive data types in Java ... data type variable name. 6
Read more

Java: Primitive Data Types, Variables and Constants ...

primitive data types, variables and constants ... Primitive Data Types, Variables and Constants ... Java, primitive data types are used to define ...
Read more

Java Variables and Constants - W3processing.com

Explains the difference between variables and constants in java. Shows java examples and how to run these. How do we define an array and other data types ...
Read more

Java Programming: Constants, Variables, Data Types

Floating data types. The Floating data types contains whole numbers and also Decimal Values Those are also Called as trhe3 Real Constants or Fractional ...
Read more

Variable and Data Type in Java - Javatpoint

... JRE and JVM Internal Details of JVM Variable and Data Type Unicode System ... we will learn about the variable and java data types. Variable is a ...
Read more

Java - Variable Types - Tutorialspoint

Java Variable Types - Learning Java in simple ... data type variable ... than being declared as constants. Constants are variables that are ...
Read more

Java Syntax - Declaring and Using Constants in Java

Throughout the lifetime of a variable its value might change many times. But what if you know the value will never change? Or more importantly you want to ...
Read more

Primitive Data Types (The Java™ Tutorials > Learning the ...

This involves stating the variable's type and ... In addition to the eight primitive data types listed above, the Java programming language also provides ...
Read more