• www.uptuexam.com
  • GBTU Results 2014
  • MTU Results 2014
  • UPTU Circulars
  • COP Result 2012,13,14
  • UPTU Previous Papers
  • GATE study material
  • Robotics Projects
Thank you for visiting www.UPTUexam.com " Free download Exam materials, previous year question papers, free ebooks & Providing Important Questions To Do their Exams Well and Totally a FREE SERVICE for all engineering streams (B.Tech)."

Question: What is datatype?


Question: What is datatype?

AnswerDatatype is a set of values that has an associated set of operations and a memory representation for its values.


S. NO.
DATA TYPE
SIGN IN BYTES
DEFAULT VALUES
1.
char
2
\0 (Null Character)
2.
byte
1
0
3.
short
2
0
4.
int
4
0
5.
long
8
0
6.
float
4
0
7.
double
8
0
8.
boolean
Not defined
false



  1. class Test1
  2. {
  3. public static void main(String args[])
  4. {
  5. int a;
  6. System.out.println("a = “ + a); // Compilation error
  7. }
  8. }


Output -





Explanation-


v  Concept of default value is not applied on local variables of method i.e. local variables of a method need to be explicitly assigned.

v  Default value will be applied in class variables.






Like for example the above program can be rewritten as-

  1. PROGRAM Test1.java
  2. class Test1
  3. {
  4. static int a, b;
  5. public static void main(String args[])
  6. {
  7. System.out.println("a & b is : " + a + " " + b); // No compilation error
  8. }
  9. }

OUTPUT –







  1. PROGRAM Test2.java
  2. class Test2
  3. {
  4. public static void main(String args[])
  5. {
  6. float f = 12.45;
  7. System.out.println("Value of f = " + f);
  8. }
  9. }


What will be the output –
A.     Value of f = 12.45
B.     Value of f = 12
C.     Value of f = 12.00000
D.     Compilation Error  (output)

Now let’s see the output of the above program.







Explanation –


In Java, floating point constants are of double type by default. The value of higher type cannot be directly assigned to a lower type. In such a case type conversion is required.









1 comment:

  1. Great Article
    IoT Projects for Students




    Deep Learning Projects for Final Year




    JavaScript Training in Chennai



    JavaScript Training in Chennai



    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete