What is the difference between Integer and int?

Answers were Sorted based on User's Feedback



What is the difference between Integer and int?..

Answer / janet

Integer is a class defined in the java.lang package,where
as int is a primitive data tyep defined in the java
language itself.Java doesn't automatically convert from one
to the other.
Integer can be used as an argument for a method that
requires an object,where as int can be used for
calculations.

Is This Answer Correct ?    59 Yes 9 No

What is the difference between Integer and int?..

Answer / k.santosh kumar

int is a primitive data type , where as Integer is a class
which encapsulates the primitive int data type and
represents in terms of object.

Is This Answer Correct ?    35 Yes 6 No

What is the difference between Integer and int?..

Answer / ravikiran(aptech mumbai)

Integer is a wrapper class object where as int is a
primitive datatype

Is This Answer Correct ?    31 Yes 4 No

What is the difference between Integer and int?..

Answer / devendra

An int is a primitive. It is not an Object.int variables
are mutable. Unless you mark them final, you can change
their value at any time.
An Integer, is a Object that contains a single int
field.Integers are immutable. If you want to affect the
value of a Integer variable, the only way is to create a
new Integer object and discard the old one.

Converting
// to int i from Integer ii
int i = ii.intValue();

// to Integer ii from int i
Integer ii = new Integer( i );

Is This Answer Correct ?    27 Yes 3 No

What is the difference between Integer and int?..

Answer / sumit

int is a premitive data type and integer is a class

Is This Answer Correct ?    14 Yes 7 No

What is the difference between Integer and int?..

Answer / duryodhan

int is a primitive data type & integer is a wapper class object which define in java.lang package.

Is This Answer Correct ?    4 Yes 1 No

What is the difference between Integer and int?..

Answer / abc

y = 10; is int i=new Integer(4); correct??

Is This Answer Correct ?    6 Yes 4 No

What is the difference between Integer and int?..

Answer / maninder sharma

Integer is a class defined in the java.lang package,where
as int is a primitive data type.

Is This Answer Correct ?    1 Yes 0 No

What is the difference between Integer and int?..

Answer / tapan kumar

int is a primitive type by the int we can set and read the
value but Integer is a wrapper class type u can use for
finding the length and for size .

Is This Answer Correct ?    4 Yes 4 No

What is the difference between Integer and int?..

Answer / krutika

y is int i=new Integer(4); correct??

Is This Answer Correct ?    3 Yes 14 No

Post New Answer

More Core Java Interview Questions

Can we sort list in java?

0 Answers  


Can we call thread start () twice?

0 Answers  


Compare java and python.

0 Answers  


Is java ee a framework?

0 Answers  


Question 5 [15] Consider the following classes, illustrating the Strategy design pattern: import java.awt.*; abstract class Text { protected TextApplet tA; protected Text(TextApplet tApplet) { tA = tApplet; } abstract public void draw(Graphics g); } class PlainText extends Text { protected PlainText(TextApplet tApplet) { super(tApplet); } public void draw(Graphics g) { g.setColor(tA.getColor()); g.setFont(new Font("Sans-serif", Font.PLAIN, 12)); g.drawString(tA.getText(), 20, 20); } } class CodeText extends Text { protected CodeText(TextApplet tApplet) { super(tApplet); } public void draw(Graphics g) { g.setColor(tA.getColor()); g.setFont(new Font("Monospaced", Font.PLAIN, 12)); g.drawString(tA.getText(), 20, 20); } } public class TextApplet extends java.applet.Applet { protected Text text; protected String textVal; protected Color color; public String getText() { return textVal; } public Color getColor() { return color; } public void init() { textVal = getParameter("text"); String textStyle = getParameter("style"); String textColor = getParameter("color"); if (textStyle == "code") text = new CodeText(this); else text = new PlainText(this); if (textColor == "red") color = Color.RED; else if (textColor == "blue") color = Color.BLUE; else color = Color.BLACK; } public void paint(Graphics g) { text.draw(g); 10 } } The Text class is more complicated than it should be (there is too much coupling between the Text and TextApplet classes). By getting rid of the reference to a TextApplet object in the Text class and setting the colour in the paint() method, one could turn the Text class into an interface and simplify the strategy classes considerably. 5.1 Rewrite the Text and PlainText classes to do what is described above. (6) 5.2 Explain the consequent changes that are necessary to the TextApplet class. (4) 5.3 Write an additional strategy class called FancyText (to go with your simplified strategy classes) to allow fancy text to be displayed for the value "fancy" provided for the style parameter. It should use the font Font ("Serif", Font.ITALIC, 12). (3) 5.4 Explain what changes are necessary to the TextApplet class for this. (2)

0 Answers   TCS,






What do you mean by data type?

0 Answers  


Explain what access modifiers can be used for variables?

0 Answers  


Can we sort hashmap in java?

0 Answers  


What is arraylist class in java?

0 Answers  


what is the default value of a variable char?(If not assigned)

4 Answers  


Does list allow duplicates in java?

0 Answers  


How to access arraylist elements in java?

0 Answers  


Categories