Compare and contrast in your own words primitive types with reference types in Java. Illustrate your answer using the partial code fragment below. This

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Compare and contrast in your own words primitive types with reference types in
Java. Illustrate your answer using the partial code fragment below.
This code fragment is intended as an incomplete sketch of a situation that demonstrates
some differences between primitive types and reference types in Java. You
may interpret the /*...*/ comments as placeholders for any code you consider
appropriate for this purpose.
You are not required to dry run or explain every detail of this code. Use it to illustrate
points you make when comparing and contrasting primitive types with reference types.

 

Reword this essay below (java)

 

Primitive Types are the basic types of variables supported by Java (8 in number) i.e. byte, short, char, Boolean, int, long, float and double. 
Primitive types generally store the value of the variable they are as a concrete value while Reference types store a reference to the variable they are dealing with. Reference type store more than just the value of the variable.
Reference types can be created using a number of primitive or primitive custom types by the programmer. Java supports both primitive and custom types.
Differences.
1. Primitive types are immutable while reference types are mutable. Primitive types usually store the value of a variable directly hence cannot be mutated (changed) internally but can be used to store a new value. However, since reference types store references to the data of the variables that they reference, their internal structure is mutable.
2. Arithmetic operations can be performed on primitive types but cannot be performed on reference types. Since primitive types are generally numeric in java, arithmetic operations such as addition and subtraction can be performed on the data stored by the variables. This cannot be done on reference types since their internal state may reference different data types that are composite.
3. Data inside primitive types can be accessed directed using the variable name/identifier but for reference types, once needs to access internal fields on a reference types individually by first accessing the composite/reference type and then accessing its internal field/variable depending on its types.
Illustration form the code:
Primitive types:
The following are the java primitive types from the code given:
a) Int
Int is a java keyword to denote an integer primitive data types.
There are three instances of the use of the primitive data types such declaration int f inside the class MyRecord, int x inside the main method of the class Main and int y as a parameter to the procedure foo of the class Main.
Reference types:
The reference types are mainly obtained from the custom classes created inside the program. The following are the reference types in the program:
a) MyRecord
There are 2 declarations of reference variables to the class MyRecord. i.e. MyRecord r and MyRecord s. Both the variables r and s reference a variable of type MyRecord and thus cannot be used as primitive data types.
b) Main
Main is also another reference type inside the program. Its usage has however not been declared but a reference from the class can be declared such as Main m.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education