Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Hello, Vannakam, How are you? This is Surendra Uppari again and I’m here today with a new lesson about Data Types in Java Programming. Let’s quick start this tutorial with what all the data types you know. In this tutorial, we will also learn what are Keywords and Identifiers in JAVA, naming format of Keywords and identifiers. Before that, first, let us know about Data type definition, what is it? how can we get to know them?

Data Types in JAVA Programming:

Definition:

Data types hold the type of data which we need to assign a variable to withhold. Understood nothing? Let us talk about it in a practical way. I want to assign a number ‘4‘ to variable sum. Since 4 is an integer type I will assign it as “int sum=4;”

Dictionary definition: a particular kind of data item defined by the values it can take and store it.

data types in java programming

There are two types of data types:

  1. Primitive data types
  2. Derived data types

1. Primitive data types:

These are the predefined data types which are built in JDK.

2. Derived data types:

These derived data types are created by programmers to handle a group of characters we use i.e a string data types.

 

Examples: int a=5;

double marks=5.60;

string name=”InStories”;

char swag=’G’;

boolean a=true;

Note: 1) We write String data types in “___” (Double quotes)

2) We write char data types in ‘_____’ (Single quotes)

3) Double holds the decimal values whereas int just holds only the non-decimal values.

data types in java
The storage size of Data Types

Example programs will be explained below so that you can know the output of what they come up with.

Examples of Data Types in JAVA:

Before that Also Read: What is the need for Python Programming?

Example of Integer Data Type in JAVA

public class IntExample 
{
  public static void main(String[] args) 
  {
    int a=45;
    int b=15;
    int c;
    c=a+b;
    System.out.println("Sum of a+b = "+c); //here we have used "Sum of a+b = " as a process of concatenation, you'll learn about it in another lesson. 
  }
}

Output: Sum of a+b = 60

 

Example of Double Data Type in JAVA

public class DoubleExample 
{
  public static void main(String[] args) 
  {
    double a=45.36;
    double b=15.15;
    double c;
    c=a+b;
    System.out.println("Sum of a+b = "+c); //here we have used "Sum of a+b = " as a process of concatenation, you'll learn about it in another lesson.
  }
}

Output: Sum of a+b = 60.51

 

Example of String Data Type in JAVA

public class StringExample 
{
  public static void main(String[] args) 
  {
    String boy="Ram";
    String girl="Sita";
    System.out.println(boy);
    System.out.println(girl);
  }
}

Output: Ram

Sita

 

Example of char Data Type in JAVA

public class CharExample 
{
  public static void main(String[] args) 
  {
    char boy='a';
    System.out.println(boy);
  }
}

Output: a


Topic -2

Keywords and Identifiers in JAVA:

The main use of Keywords and Identifiers are we can use them to write our programming codes in a simple way without using our own logic.

Keywords: These are predefined words with a special meaning. All keywords must be written in lower case.

Example: class, static, void, etc

keywords and identifiers in JAVA

Identifiers: These are the words should be given by the programmer

Example: class name, Variable name, method name, package name, project name.

Naming format of Identifiers

Rules of writing Identifiers:

  • We can use the combination of Alphabets of A-Z, a-z, 0-9, $ (Dollar symbol), & (ampersand) and _(Underscore)

Example: demo, DeMo, Deom7, Deom_7

  • Identifiers should not start with number

Example: Sample7, _sample, $ample (Valid)

7Sample,7_sample (Invalid)

Identifiers Standard Naming Practise:

Class Naming Format:

Every word first letter should be capitalized. If it has two or more combining words like “SampleProgram” first word the first alphabet should be capital, as in this case they are ‘S’ & ‘P’.

Syntax: class Run

{

Your code goes here…

}

Variable Naming Format:

  • The first word should be in lower case and from the second word, the first letter should be capitalized.

Syntax 1: int age;

Syntax 2: int studentMarks; (the First word should be in lower case and second word first letter should be in Uppercase)

Why practise Identifiers Naming Format?

I know you got this doubt, remember it’s your program and you can write on your own. But following Naming format will improve your program’s readability and helps others to understand it very easily.

Tags: keywords and identifiers, use of keywords and identifiers, the syntax of keywords and identifiers in java, keywords and identifiers naming format.

Data types in JAVA, Keywords and identifiers in JAVA programming

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Tagged on:                 

One thought on “Data types in JAVA, Keywords and identifiers in JAVA programming

  • July 5, 2018 at 1:00 am
    Permalink

    What’s Taking place i am new to this, I stumbled upon this I’ve discovered It positively useful and it has aided me out loads. I’m hoping to give a contribution & aid other users like its helped me. Good job.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar