Introduction To Java Lecture 2
Introduction To Java Lecture 2
(INTRODUCTION)
BY: DR. AMAN TYAGI
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
A variable's data type determines
Primitive data types - includes byte, short, int, long, float, double,
boolean and char
Non-primitive data types - such as String, Arrays and Classes
Byte 0
Short 0
Int 0
Long 0L
Float 0.0f
Double 0.0d
Char '\u0000'
Boolean False
Non-Primitive Data Type or
Reference Data Types
The Reference Data Types will contain a memory address of variable values because the reference
types won’t store the variable value directly in memory. They are strings, objects, arrays, etc.
1. Strings
Strings are defined as an array of characters. The difference between a character array and a string in
Java is, that the string is designed to hold a sequence of characters in a single variable whereas, a
character is a collection of separate char-type entities.
2. Class
A class is a user-defined blueprint or prototype from which objects are created. It represents the set of
properties or methods that are common to all objects of one type.
3. Object
An Object is a basic unit of Object-Oriented Programming and represents real-life entities. A typical Java
program creates many objects, which as you know, interact by invoking methods.
4. Interface
Like a class, an interface can have methods and variables, but the methods declared in an interface are by
default abstract (only method signature, no body).
5. Array
An Array is a group of like-typed variables that are referred to by a common name.
Strings are discussed in c programing. Class, Object, array and Interface will be discussed in the class.
Variables
An array of 10 elements
Each item in an array is called an element, and each element is
accessed by its numerical index.
As shown in the preceding illustration, numbering begins with 0.
The 9th element, for example, would therefore be accessed at
index 8.
END