NEP 1 - JAVA ANSWERS
1. What is Java?
- Java is a high-level, platform-independent, object-oriented programming language.
2. What is JVM?
- JVM (Java Virtual Machine) runs Java bytecode on any machine. Example: JVM in
JDK.
3. Variable Rules with Example:
- Variable: int age = 20;
- Rules: Must start with letter, no spaces, no keywords.
4. Data Types:
- int, float, char, boolean. Example: float price = 55.5f;
5. Operators:
- Types: Arithmetic (+,-), Relational (==, !=), Logical (&&, ||), Assignment (=).
6. Control Statements:
- if, if-else, switch, break, continue.
7. Looping Statements:
- for, while, do-while. Example: for(int i=0;i<5;i++)
8. Method with Example:
- void display() { [Link]("Hello"); }
9. Method Overloading Advantages:
- Same name, multiple uses. Improves readability, code reuse, flexibility.
10. Characteristics of Object:
- State, Behavior, Identity, Real-world mapping, Encapsulation.
11. Characteristics of Class:
- Blueprint, Encapsulation, Abstraction, Reuse, Inheritance.
12. Arrays in Java:
- Single, Multi-dimensional.
Example: int[] arr = new int[5];
int[][] arr2D = new int[3][3];
13. String Types:
- String class, StringBuffer, StringBuilder.
14. Inheritance with Example:
- class A {}; class B extends A {};
15. Keywords:
- Reserved words. E.g., static, final.
16. Overriding:
- Same method in child class. Used for runtime polymorphism.
17. Packages:
- Types: Built-in ([Link]), User-defined.
Benefits: Organizes code, prevents naming conflicts.
18. Casting:
- Implicit, Explicit.
Example: int x = (int) 5.5;
19. Java Generics Types:
- Generic class, method, interface.
20. Events:
- User actions. Classified as KeyEvent, MouseEvent, ActionEvent.
21. Handling Key & Mouse Events:
- Use KeyListener, MouseListener.
22. Applet Lifecycle:
- init(), start(), stop(), destroy().
23. Advantages of Applet:
- Runs in browser.
Parameters: Passed via HTML <param>.
24. GUI:
- Building user interface with AWT, Swing.
25. GUI Components:
- Button, Label, TextField, Checkbox.
26. AWT Components:
- Frame, Panel, Button, Label.
27. Java Swing vs AWT:
- Swing: Lightweight, more features.
- AWT: Heavyweight, OS dependent.
28. Structure of Java Program:
- package, import, class, main method.
29. Input/Output Programming:
- Scanner, [Link]().
30. Binary I/O Diagram:
- Uses InputStream, OutputStream.
31. File I/O Stream:
- FileInputStream, FileOutputStream.