Question

In: Computer Science

Explain the differences between primitive and reference data types. Define the scope of a variable (hint:...

  1. Explain the differences between primitive and reference data types.
  2. Define the scope of a variable (hint: local and global variable)
  3. Why is initialization of variables required.
  4. Differentiate between static, instance and local variables.
  5. Differentiate between widening and narrowing casting in java.
  6. the following table shows data type, its size, default value and the range. Filling in the missing values.

TYPE

SIZE (IN BYTES)

DEFAULT

RANGE

boolean

1 bit

true, false

Char

2

‘\0000’ to ‘\ffff’

Byte

0

Short

0

-215 to +215-1

Int

4

Long

0L

-

Float

4

00.0f

Double

8

-1.8E+308 to +1.8E+308

  1. Define package as used in java programming
  2. Explain the importance of using Java packages

Solutions

Expert Solution

All the basics data types are available in JAVA are primitive types like int, boolean, char, short, etc.

and Reference types are used to point the object like String, File, Thread, etc.

main difference is that primitive types will always has a value while reference type is "NULL" , if int variabe is unintialized then it will have 0 value but if String variable is uninitialized then it will be "null".

-----------------------------------------------------------------

global variable are declared outside any function can be accessed into any function but local variables are declared within any function canbe accessed only in that function.

-----------------------------------------------------------------

initializing variables are useful for preventing bugs specifically for reference type initialization can be useful for preventing null reference errors.

-----------------------------------------------------------------

static variables are variables declared with static keyword outside of any method within class

instance variables are specific to instance of any class they are declared in class but outside of method and also called member variable

while local variable are only declared within any method and can be accessed by that method.

-----------------------------------------------------------------

in simple term widening mean conversion of value to data type that can handle any possible value of original data type , and also widening conversions preserve the source value but can change its representation like short to int.

narrowing mean conversion to data type that might not be able to handle the value of current data type like from float to int, or int to short.

--------------------------------------------------------------------

TYPE

SIZE (IN BYTES)

DEFAULT

RANGE

boolean

1 bit

false

true, false

Char

2 bytes

\0000

‘\0000’ to ‘\ffff’

Byte

1bytes

0

-128 to 127

Short

2bytes

0

-215 to +215-1

Int

4bytes

0

-2147483648 to 2147483647

Long

8bytes

0L

-9223372036854775808 to 9223372036854775807

Float

4bytes

00.0f

±1.4E-45 to ±3.4028235E+38

Double

8bytes

0.0

-1.8E+308 to +1.8E+308

------------------------------------------------------------------------

package is mechanism to grouping the classes, subpackages, and interfaces.

importance are: they are useful in preventing naming conflict, packages are useful for providing controlled access to classes and interfaces, packages are useful in data-hiding because they are actualy encapsulation of related classes and interfaces .


Related Solutions

What is the difference between primitive types and abstract datatypes?
What is the difference between primitive types and abstract data types?
Differentiate between types of table and the data stored in these tables (Master, Transaction, and Reference...
Differentiate between types of table and the data stored in these tables (Master, Transaction, and Reference tables)
With reference to relevant provisions of the Corporations Act 2001 (Cth), explain the differences between unfair...
With reference to relevant provisions of the Corporations Act 2001 (Cth), explain the differences between unfair preferences and uncommercial transactions.
With reference to relevant provisions of the Corporations Act 2001 (Cth), explain the differences between unfair...
With reference to relevant provisions of the Corporations Act 2001 (Cth), explain the differences between unfair preferences and uncommercial transactions.
Write a c statement to declare variables of primitive data types, and assign values to the...
Write a c statement to declare variables of primitive data types, and assign values to the variables. Use common control structure in c, such as if, switch, break, for, while statements. Write a c program that takes command line parameters, and perform some computation based on the command line input. Write c statements to generate random number within a certain range. Write a c statement to declare array variables of primitive data types, and assign values to the elements of...
Discuss the difference between validity and reliability. Define a group and explain the differences between primary...
Discuss the difference between validity and reliability. Define a group and explain the differences between primary and secondary groups.
Define price and value and explain the similarities and differences between the two What is the...
Define price and value and explain the similarities and differences between the two What is the law of demand and what are two reasons why it’s valid?
1.What are the 3 main types of business ownership. Please define the differences between the different...
1.What are the 3 main types of business ownership. Please define the differences between the different types of business ownership             2. If you were designing a financial management team. What attributes would you look for and or require?   
Please explain the differences between the 2 types of leases, capital and operating, and explain how...
Please explain the differences between the 2 types of leases, capital and operating, and explain how both the lessee and the lessor view these arrangements and provide a clear discussion of the process each uses to determine whether to enter into a leasing arrangement.
Define and explain the differences between: - Carve-Outs - Divestitures - Spinoffs - Split-Offs
Define and explain the differences between: - Carve-Outs - Divestitures - Spinoffs - Split-Offs
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT