Wednesday, August 18, 2021

# 7. Data types continuation

 Character data types

To represent this character data type in java we have a data type called char data type

Char data type is used to represent alphabets

Ex: a-z, A - Z

If we want to convey as char it should enclose data within single quotes ' '

char ' h ' 

char range -------> 0 to 65535

char ' d ' -----> valid

By using char we can represent a single character

char 'ap' ------> invalid

Only one character should represent in char

char ' '  --------> invalid

char must and should have a single character


Boolean data type:

To represent logical values we have a data type called boolean data type

there are only two logical values

1. true

2. false

Ex: boolean true

both true and false should be small letters

boolean false ===> valid

boolean True ===> invalid


String:

To represent the words we have a data type called string data types.

Word is a collection of alphabets

String ===> S should be a capital letter otherwise we will get a compile-time error.

Ex: String "JAVA"

Compulsory this data must and should enclose the data in double quotes " ".

String " Practice"

String "Practice089"

String " "

String "d"

String "&"

String "435"

String "pracTicE"

All are valid, whatever we write inside double quotes is valid.


Example:

public class Data_Types{          // access specifier, class keyword, class name, start of a class

//  data is constant, access specifier, data type, variable name, data

// static

static public char cdata='d';

static public String sdata="divya";


// data is constant, access specifier is optional, data type, variable name, data in single & double quotes

// static

static char cdata='d';

static String sdata="divya";


// data is not constant, data type, variable name, data

// non static

public char cdata='d';

public String sdata="divya";


// data is not constant, access specifier is optional, data type, variable name, data

// non static

char cdata='d';

String sdata="divya";

        // end of a class


Variables:

If we want to define some data in java compulsory the data must be there in a container called a variable.

A variable is a container where we are going to define/maintain/keep some data.

A water bottle is a container where we are going to maintain some water

A house acts as a class. Our house contains all the things, in the same way, the class contains all the things needed.

34 ===> is a data

this 34 should be there inside a container called a variable.

Depends upon the data behavior we have 4 types of variables

1. Static variables (class level)

2. Non-static variable (instance variables)

3. Local variables (method level)

4. Reference type variables (object type)

        4.1. Static variables (class level)

        4.2. Non-static variable (instance variables)

        4.3. Local variables (method level)












No comments:

Post a Comment

# 16. control statements

 Control statements: In java, by using control statements we can tell the flow of execution. in which order the statements should execute. d...