Set - 3

Question 36 :

What is the difference between Swing and AWT components?

Answer :

AWT components are heavy-weight, whereas Swing components are lightweight. Heavy weight components depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button.


Question 37 :

Why Java does not support pointers?

Answer :

Because pointers are unsafe. Java uses reference types to hide pointers and programmers feel easier to deal with reference types without pointers. This is why Java and C-sharp shine.


Question 38 :

Parsers? DOM vs SAX parser

Answer :

Parsers are fundamental xml components, a bridge between XML documents and applications that process that XML. The parser is responsible for handling xml syntax, checking the contents of the document against constraints established in a DTD or Schema.
DOM
1. Tree of nodes
2. Memory: Occupies more memory, preffered for small XML documents
3. Slower at runtime
4. Stored as objects
5. Programmatically easy
6. Ease of navigation
SAX
1. Sequence of events
2. Doesn't use any memory preferred for large documents
3. Faster at runtime
4. Objects are to be created
5. Need to write code for creating objects
6. Backward navigation is not possible as it sequentially processes the document


Question 39 :

Can you declare a class as private?

Answer :

Yes, we can declare a private class as an inner class. For example,

class MyPrivate {
 private static class MyKey {
  String key = "12345";
 }
 public static void main(String[] args) {
  System.out.println(new MyKey().key);//prints 12345
 }
}


Question 40 :

What is the difference between shallow copy and deep copy?

Answer :

Shallow copy shares the same reference with the original object like cloning, whereas the deep copy get a duplicate instance of the original object. If the shallow copy has been changed, the original object will be reflected and vice versa.