0% found this document useful (0 votes)
41 views

Difference Between Class and Primitive Types: Students 3K

p09okiujy likujyhtgrf kujyhtgrfds

Uploaded by

VIKRAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Difference Between Class and Primitive Types: Students 3K

p09okiujy likujyhtgrf kujyhtgrfds

Uploaded by

VIKRAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

STUDENTS 3K

HOME

STUDENTS+

FRESHERS

STUDY RESOURCES

MORE >>

You are here: Home / Interview / Difference Between Class and Primitive Types

Difference Between Class and Primitive Types


All the variables declared in Java are classied into certain type. The classication of variables will help us in treating
the variables according to its type. Variables in Java are classied as characters, several types of integers, oating
points and types to declare a statement true or false. All the above mentioned variable types are called as primitive
types.

Related: SQL & .NET Interview questions and Answers

Class Type Variables in Java


Class type variables are used to solve the object oriented problems. Separate types of variables are used to solve the
object oriented programs because they are more complex than simple integer and boolean functions. The variable
which names a certain object in a program is classied into class type variables.
Read: More Interview Questions

Difference between Class and Primitive types:


Every variable declared in a program is stored in the memory of the computer. The Storing method of class
type variables is different from primitive type. The class type variable stores only the memory address of the
variable but not its value. If a variable is declared in primitive it stores the value of the variable in the
particular memory location.
The primitive data type always has a value and never be declared as null. If no value is assigned for a primitive
data type, a default value of zero will be initialized.
When a value is assigned to a primitive data type, it will be copied but only the handle is copied in class data
type. The class data type will share the variables so change in one variable will affect the other.
When the equality (==) operator is used in primitive data types only its primitive values are compared. If
equality operator is used in class data type, the address which stored the data is compared. Ex: imagine that
we have two int variables namely a and b whose value is 10. If a is compared with b using equality operator, the

result will declared that the two integers are equal. If two strings namely USA and USA are compared using
equality operator the result will state that the strings are not same.
When primitive values are passed into a method, its values are copied. When class values are passed into
method only the handle of class types are copied.
HOME is returned
STUDENTS+
FRESHERS
STUDY RESOURCES
MORE >>
Primitive type returns its value while only the handle
in the case
of class type.
Primitive types are stored in stack while class type are stored as heap which is managed by garbage collector.
The memory space consumed by primitive data types is very less when compared to the memory type of class
type. Class type consumes more memory because it maintains metadata objects.
Primitive data types can be copied but class data types can be shared.
All primitive data types have an default value but uninitialized class data types will throw
NullPointerException.

STUDENTS 3K

Converting Primitive Types into Class Types Vice Versa


Casting is a process of converting a data type into another. All primitive and class types can be converted into
another using the casting process. In Java, the java.lang package is comprised of classes which correspond to all
primitive data types. The names of classes present in java.lang package are almost similar to the names of data
types. Utilizing the classes in java.lang package, it is possible to create a class type which can create two objects
with same value.
Converting a string into a primitive type is a common translation used in Java programming. The primitive data type
created by converting a string can be used anywhere in the program without altering its value. Consider the
following code as an example:
String Bollywood=1001;
int b= Integer.parseInt(Bollywood);
In the example code given above, the class Integer is used to convert the string Bollywood into 1001. Similarly
classes like Boolean, Float, Double, Void, Short and Long are also used.

Database Roles in SQL


Database role can be dened as the collection privileges assigned
one or several users. Each database role is given a name. Most
RDBMS platforms have set of predened roles assigned to a user.
Every user with CREATE ROLE privilege can create his/her own
database role. Roles in database allow a user to set up hierarchical
Continue reading
STUDENTS 3K

Autoboxing and unboxing


Autoboxing and unboxing are the process used to convert the one variable type into another automatically.

Autoboxing is used to convert the primitive type into class type while unboxing is used to convert class type into
primitive type. If a statement is written in primitive or class type, it is converted vice versa according to the
requirement of the compiler. Conversion using Autoboxing and unboxing works only if the type has a value. If
objects which are called using constructors are converted, it will result in a compiler error.

STUDENTS 3K

HOME

STUDENTS+

FRESHERS

STUDY RESOURCES

MORE >>

Generate
PDFs In Java
Highly Ef cient Java PDF
Library. Download Fully
Functional Eval!
dynamicpdf.com

Filed Under: Interview


Tagged With: class, Interview, SQL

Search this website

C PROGRAMMING GUIDE...

EDUCATIONAL LOAN GUIDE

CAREER GUIDANCE FOR ALL

RANDOM MATERIALS :
Data Mining and Data Warehousing
Difference Between Class and
Primitive Types
Database Roles in SQL
CASE Expression in SQL
Concurrent Update Problem

Adsby Google

STUDENTS 3K

JavaIntegerClass
Class10
HOME

STUDENTS+

FRESHERS

STUDY RESOURCES

MORE >>

FOLLOW US ON FACEBOOK

Adsby Google

DataClassC#
ClassBoxing

ADVERTISEMENT

PG Diploma in Data Science From Manipal University


Enhance Your Career With 11 Month Data Science Program.
Apply Now! Go to datascience.manipalglobal.com/

Login to Your Account


Speak English Fluently
-
TB
Start Free Download - Print Forms
Fortran To C Migration
Become a Domain Reseller
Start Download - Get PDF
Edelweiss Tokio Wealth Builder Plan for Big Moments in Life
MBA In Business Analytics - PartTime Executive Program

Adsby Google

STUDENTS 3K

UsedClassA
ProgramJava
HOME

STUDENTS+

FRESHERS

COMPANY PROFILE

CATEGORIES

About Students3k

Important Programs

Contact Us

Study Abroad

Earn Money Online

IT Companies

Website Archive Page

Career Guidance for Students

Privacy Policy

Teachers

Disclaimer

Verbal Analogies

STUDY RESOURCES

WE ARE SOCIAL
Facebook Fans
Twitter Follow
Google Plus
Pinterest Page

Copyright 2012 - 2016 Students3k.com All Rights Reserved Designed By Benets

MORE >>

You might also like