Core Java Interview Questions
Questions Answers Views Company eMail

1.what is the exact difference between applet and frame? 2.Do we use main method in frames?

5 24474

diff between abstract methods and interfaces with programing (code) example?

2 4429

Is it compulsory to have atleast one abstract method in abstract class?

10 20838

public class Garbage { int a=0; public void add() { int c=10+20; System.out.println(c); System.out.println(a); } public static void main(String args[]) { Garbage obj=new Garbage(); System.gc(); System.out.println("Garbage Collected"); obj.add(); } } Above is a code in java used for garbage collection. object obj has been created for the class Garbage and system.gc method is called. Then using that object add method is called.System.gc method if called the obj should be garbage collected?

6 6471

Why cant we define System.out.println() inside a class directly?

5 9973

If all the methods in abstract class are declared as abstract then what is difference between abstract class and in interface?

Infosys, Synechron,

8 12756

why marker interfaces are there in java

Digital Group,

4 7383

How to validate the request (Eg:user name and password) in session(http session)? not in LDAP server ?

Saksoft,

1 5096

In C we use only compiler. Why java uses both compiler and interpreter? What is its significance?

5 16376

What are Advatages of Overloading and Overridding.

TCS, Wipro,

8 23444

Can we declare static variables in JSP page.

TCS,

3 22589

wHAT IS DEFAULT SPECIFIER IN JAVA wHAT IS DEFAULT CONSTRUCTOR IN JAVA wHAT IS DEFAULT METHOD IN JAVA

IBM,

12 15739

write java code to print second max number in the array

Huawei, IBAB,

12 20574

how to call One constructor from another;

Innodata Isogen,

10 14830

Write java code to print "Hello how are you" Thread1 should have "Hello" Thread2 should have "how are you" both the threads should start at the same time

Huawei,

4 8412


Post New Core Java Questions

Un-Answered Questions { Core Java }

What is difference between == equals () and compareto () method?

519


When do I need to use reflection feature in java?

619


Tell me the latest versions in java related areas?

574


In Java list the methods that can be overridden?

563


What is mean by exception?

539






What will happen if static modifier is removed from the signature of the main method?

517


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)

1817


What is the use of keywords in java?

545


What is function and method in java?

514


How many days will it take to learn java?

506


What is the common usage of serialization?

565


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example

2125


Why we use multi threading instead of multiprocessing?

567


What do you mean by stack?

626


Which is easier .net or java?

633