Java Programming - Language Fundamentals - Discussion

Discussion :: Language Fundamentals - General Questions (Q.No.1)

1. 

Which four options describe the correct default values for array elements of the types indicated?

  1. int -> 0
  2. String -> "null"
  3. Dog -> null
  4. char -> '\u0000'
  5. float -> 0.0f
  6. boolean -> true

[A]. 1, 2, 3, 4
[B]. 1, 3, 4, 5
[C]. 2, 4, 5, 6
[D]. 3, 4, 5, 6

Answer: Option B

Explanation:

(1), (3), (4), (5) are the correct statements.

(2) is wrong because the default value for a String (and any other object reference) is null, with no quotes.

(6) is wrong because the default value for boolean elements is false.


Boopalan V said: (Jul 20, 2010)  
Is there any primitive data type named Dog?

Sijo.S said: (Sep 30, 2010)  
What is the use of data type 'Dog'. I didnt heard about that!

Sundar said: (Oct 1, 2010)  
Hi All,

Dog - There is no primitive datatype like 'Dog'. It is a User Defined type (a class created by User). By default it will hold null value.

For example:

public class Dog
{
//...
}

Dog myDog;

Here myDog will contain 'null' value by default.

Hope you understand. Have a nice day!

Garima S said: (Oct 13, 2010)  
Not able to undestand the given question.

Can anyone please explain it to me?

Hemangini Kulkarni said: (Nov 12, 2010)  
Dear Sir,

1) Default value for array element of type char is nothing , not even null
2) Default value for array element of type float is 0.0 not 0.0f

class hello
{
public static void main(String str[])
{
int i[] = new int[5];
float f[] = new float[5];
double d[] = new double[5];
String s[] = new String[5];
char c[] = new char[5];
boolean b[] = new boolean[5];

System.out.println("Hello World");
System.out.println("Integer "+i[0]);
System.out.println("Float "+ f[0]);
System.out.println("Double " + d[0]);
System.out.println("String " + s[0]);
System.out.println("Character " + c[0]);
System.out.println("Boolean " + b[0]);
}
}

Piyush Gadekar said: (Jan 31, 2011)  
What your are tryng to admit from this program?

Shaswati said: (Feb 25, 2011)  
How option 4 is correct? I could not understand. Please explain about the default data type of char.

Sundar said: (Mar 17, 2011)  
@Shaswati

It is nothing but a class created by a user.

Ex: Dog, Student, Car etc.

The question is 'what will be default value?'.


Student objStud1;

Here objStud1 will contain 'null' value by default.

Prathyusha said: (Mar 20, 2011)  
HI,
No where the "Dog" datatype is mentioned.
If Dog is integer , the default might be -0
If Dog is float , the default might be -0.0f
If Dog is object ,the default might be -null
.... No where it is mentioned whether Dog is wat datatype.
HELP ME IN THIS REGARD.....

Suganthan.M said: (Mar 22, 2011)  
Dog - There is no primitive datatype like 'Dog'. It is a User Defined type. By default it will hold null value.

Suresh said: (Jul 1, 2011)  
Nice answers

Kathirozhi said: (Sep 17, 2011)  
Plese correctly tell the char default value is nothing or not null or the answer in the question please help to understand.

Rehana said: (Oct 2, 2011)  
What is that \u declared in char?

Sivachandran said: (Jan 12, 2012)  
@Kathirozhi not null and nothing nice answers.

Amarjeetkaur said: (Jan 13, 2012)  
Please tell me anyone, what is the history of java ? In briefly words.

Gaurav said: (Feb 1, 2012)  
The most important feature of Java language is that it is Architecture Neutral. Earlier softwares were build for specific operating systems, Like softwares build for Windows They run only in windows not in other os like linux, unix, max etc. To resolve this A new language was introduced by Sunmicrosystems Known as Java and so many features were introduced in this language which makes it a powerful language.

Deepi said: (Feb 8, 2012)  
Char default value is a space only know then how?

Basha said: (Feb 13, 2012)  
Hi All,

default values are given as follows:
Int------>0
String---> null
Dog (Object)------->null
Char -------------->"\u0000". it is hexa decimal representation of asii code of the chars. I think "\u0000" represents "space".
boolean------------> false.

Done.

Ranjith said: (Feb 20, 2012)  
Hi , in the given programe the dog is a object ,
which may any data type
the below programe illistreates

class Dv
{
int x;
}

class DefaultValues
{
public static void main(String str[])
{
Dv dog=new Dv();

int a[] = new int[5];
float b[] = new float[5];
double c[] = new double[5];
String d[] = new String[5];
char e[] = new char[5];
boolean f[] = new boolean[5];
System.out.println("Hi ,The Default Values: ");
System.out.println("For Object :"+dog.x);// here dog is object
System.out.println("Integer "+a[0]);
System.out.println("Float "+ b[0]);
System.out.println("Double " + c[0]);
System.out.println("String " + d[0]);
System.out.println("Character " + e[0]);
System.out.println("Boolean " + f[0]);
}
}

Manasa said: (May 29, 2012)  
How can a char has a default value in terms of hexa-decimal?
Can any one clear?

Usha said: (Jun 5, 2012)  
That shows in hexa representation
java is same as c ,we can say this by this because java uses the syntax of c. for more advantages and comfortable they created java as platform independent

Asad said: (Nov 1, 2012)  
Integer 0.
Float 0. 0.
Double 0. 0.
String null.
Character has nothing as default value.

Nabbu said: (Nov 7, 2012)  
Is that Dog is a user define data type.
Or we can say that Dog is a object of a class.
class A
{
...
...
}
class B
{
A Dog=new A();
}

Laxman said: (Dec 5, 2012)  
How we know the meaning of hexadecimal representation by looking?

Nrj said: (Feb 24, 2013)  
Dog is not a primitive data type but you can define data types according to you in java. Here we are defining a class and its type is "Dog". I mean we have declare a Dog type class. Now when you create its object that is MyDog, it will contain "null" value.

Dilip Kumar said: (Apr 9, 2013)  
class A
{
...
...
}
class B
{
A Dog=new A();
}

Here class a is non premitive datatype and Dog is as object reference variable which holds the object referenced.

Dipen said: (Jun 22, 2013)  
How did you all came to know that '/u0000' is hex and what is exactly char default value null or space??

Muthamil.A said: (Nov 24, 2013)  
char default value "space" in java .
char default value \u0000 in c.
dog s a object so that default value null.

Dinesh Saini said: (Jan 3, 2014)  
why (3) is correct, as we don't know the data type of DOG so we can't say what will be the default that it may hold.

If DOG is any object then 'DOG -> null' will be ok but here we don't know anything about the word DOG so default value can't be assumed by words.

Manju said: (Jan 4, 2014)  
What are default value of char in C++?

What is \u0000? What does \u indicate?

Please explain.

Hema said: (Feb 23, 2014)  
Please can anyone explain hexadecimal representation?

Thiru said: (Jul 11, 2014)  
char in Java is an unsigned 16 bit numerical value representing a two-byte Unicode character.

Since you left it as default, your char is 0, or u\0000. This is the Unicode NULL value.

Mahi said: (Aug 6, 2014)  
Hello Character default value nothing here '\u0000' mention how correct options 4 please explain sir?

Dagg said: (Sep 7, 2014)  
Can someone describe: System.out.println();?

Pooja said: (Sep 28, 2014)  
System-is class of java.lang package.
Out-is static final method of System class. So it is called directly with class name.
(System.out).

And out is also reference of PrintStream class.
println-is method of PrintStream class in java.io package.

So it is called with reference of that class.
(System.out.println).

Bhavani said: (Nov 14, 2014)  
The default value for float is only 0.0 in the given question it is 0.0f.

How option B is correct?

Rajat said: (Jan 11, 2015)  
Can somebody explain me how dog variable is initialize to null? In netbeans compile is showing an error. As dog variable is not initialized.

Satya said: (Feb 5, 2015)  
Can any one explain double default value in Java?

Shrikrishn Sharma said: (Feb 9, 2015)  
Default value of char is "null space" it's Unicode is 32. If you want to print it using println function you get a white space over there.

Shrikrishn Sharma said: (Feb 9, 2015)  
Char's default value is not NULL nor 0 in Java.

Pradeep Yadav said: (May 22, 2015)  
Please explain me how can we get the value of class (Dog) object with array in main method from Dog?

Saikrishna said: (Jun 29, 2015)  
How Boolean is false only? Please explain.

Sunil said: (Aug 17, 2015)  
Int-0.
Float-0.0.
Char-space.
Boolean-false.
Byte-0.
Short-0.
Long-0.
Double-0.0.

Nancy said: (Sep 28, 2015)  
Every class in java is also a data type itself. Since Dog is a user defined class, it is a user defined data type also.

Prateek Kumar Baranwal said: (Dec 2, 2015)  
Dog data type is fully user define for class or data type.

Subhash said: (Dec 12, 2015)  
All other datatypes are predefined except Dog, which is meaningless in this question.

Subhash said: (Dec 12, 2015)  
Int-0.
Float-0.0f or 0.0F.
Char-'\u0000'.
Boolean-False.
Byte-0.
Short-0.
Long-0.
Double-0.0 or 0.0d or 0.0D.

Indu said: (Apr 24, 2016)  
Please explain the difference between the method overloading and method overriding?

Avinash said: (Jul 16, 2016)  
Int-0.
Byte-0.
Short-0.
Long-0.
Double-0.0 or 0.0d or 0.0D.
Float-0.0f or 0.0F. Here f means float type default value 0.0.
Char-'\u0000' or space.
Boolean-False.
String - null.

Anonymous said: (Jul 17, 2016)  
Dear Sundar.

It's a static String which not consist quotes. Dog.

Anonymous said: (Jul 17, 2016)  
Not a Reference data type.

Abhi said: (Jul 19, 2016)  
Why option 2 is wrong?

Senthil said: (Aug 10, 2016)  
The string default value is null.

So, why option 2 is wrong?

Sireesha said: (Sep 9, 2016)  
What is that \u declared in char?

Sireesha said: (Sep 14, 2016)  
What is that \u declared in char?

Jayesh said: (Sep 28, 2016)  
Is dog is which type of data type is it enumerated data type are users defined the data type?

Suraj said: (Oct 28, 2016)  
Any user-defined data type shows that null?

Kishor said: (Oct 12, 2018)  
Why String =null, is wrong? Please explain.

Amit Prajapat said: (Jan 15, 2020)  
@Sireesha.

\u - Unicode character.

Nani said: (Jun 7, 2020)  
Here, Dog is not a primitive data type. It is a user defined data type.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.