The document provides an overview of Java programming concepts, including definitions of Java, exceptions, inheritance types, access specifiers, and key features like AWT and Swing for GUI development. It also discusses important programming principles such as encapsulation, polymorphism, and the use of keywords like static and throw. Additionally, it covers Java program structure, data types, and the role of collections and interfaces in Java development.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views
java.2mraks
The document provides an overview of Java programming concepts, including definitions of Java, exceptions, inheritance types, access specifiers, and key features like AWT and Swing for GUI development. It also discusses important programming principles such as encapsulation, polymorphism, and the use of keywords like static and throw. Additionally, it covers Java program structure, data types, and the role of collections and interfaces in Java development.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
2 marks compatible JVM, allowing programs to be written once
1.What is Java? and run anywhere.
Java is a high-level, object-oriented programming 12. What is access specifiers? List them. language developed by Sun Microsystems (now owned Ans: Access specifiers define the visibility and by Oracle). It is platform-independent, secure, and accessibility of classes, methods, and variables. They supports multithreading and distributed computing. are: o public o private o protected o default (no 2. What is an Exception? keyword) Ans: An exception in Java is an event that disrupts the 13. Define Keyword-Static. normal flow of a program's execution. It typically occurs Ans: The static keyword in Java is used to define class- during runtime and can be handled using try-catch level methods or variables that are shared among all blocks to prevent program crashes instances of the class. Static members belong to the 3. Enlist types of Inheritance. class itself rather than any specific object. Single Inheritance Multilevel Inheritance 14. Why we set environment variable in Java? Hierarchical Inheritance Multiple Inheritance (via Ans: Environment variables such as JAVA_HOME and interfaces) Hybrid Inheritance (combination of CLASSPATH are set to configure the Java Development multiple types) Kit (JDK) and to specify the path where Java programs 4. What is AWT? and libraries can be found by the operating system. AWT (Abstract Window Toolkit) is a Java library used for 15. Write advantages of Inheritance. creating graphical user interfaces (GUI). It contains Ans: Advantages of Inheritance: Code Reusability: various classes like Button, Label, and TextField for Subclasses reuse code from the parent class. Method developing windows-based applications Overriding: Allows for dynamic polymorphism. 5. State the purpose of throw keyword Extensibility: New functionalities can be added to an Ans: The throw keyword is used in Java to explicitly existing class. throw an exception. For example: throw new 16. Define class and object with one example ArithmeticException("Error message"); . Ans: A class is a blueprint for creating objects 6. What is Abstract class (instances). An object is an instance of a class. Example: Ans: An abstract class in Java is a class that cannot be class Car { String model; void start() instantiated and may contain abstract methods { System.out.println("Car started"); } } Car myCar = new (methods without implementation) that subclasses Car(); // myCar is an object of the class Car. must override. It can also contain concrete methods. 17. What is Swing? 7. What is an event? Ans: Swing is a part of Java’s Foundation Classes (JFC) Ans: An event in Java refers to any action or occurrence used to create lightweight GUI applications. It provides recognized by software, button clicks or mouse more powerful and flexible components than AWT, such movements, which can trigger a specific response as buttons, panels, and text fields. within a program. 18. When buffered reader is used? 8. What is Method Overloading? Ans: BufferedReader is used to read text from a Ans: Method overloading occurs when multiple character-based input stream efficiently. It buffers input, methods in the same class have the same name but minimizing the number of I/O operations by reading differ in the number or type of their parameters. chunks of data. 9. Why Java is a architectural neutral language? 19. What is main difference between exception and Ans: Java is considered architectural-neutral because error? compiled Java code (bytecode) can run on any system Ans: Main difference between Exception and Error: that has a Java Virtual Machine (JVM), regardless of the Exception: Recoverable issue that can be handled by the underlying hardware or operating system. program (e.g., IOException, NullPointerException). 10. Define Encapsulation. Error: Serious problem that is generally beyond the Ans: Encapsulation is the concept of bundling data control of the program (e.g., OutOfMemoryError). (variables) and methods that operate on the data within 20. What is Panel? a single unit, typically a class, and restricting access to Ans: Panel is a container in AWT that can hold multiple some of the object’s components using access components (like buttons and text fields) and group specifiers. them together. It is often used for layout purposes in 11. Why Java is a platform neutral language? GUI applications. Ans: Java is platform-neutral because its compiled bytecode can be executed on any platform that has a 21. Define variable in Java? What are the naming rules 33. What is the use of layout manager? of variable? Ans: A layout manager is used to arrange components Ans: A variable is a container that holds data that can be in a container in a specific layout, such as flow, grid, or changed during the execution of a program. Naming border layouts. rules: Must start with a letter, $, or _ Subsequent 34. What is difference between paint ( ) and repaint ( ). characters can be letters, digits, $, or _ Case-sensitive Ans: paint(): Directly used to draw the component. Cannot be a keyword repaint(): Calls the update() method, which in turn calls . 22. What is recursion? paint(), used to refresh the UI. Ans: Recursion is a programming technique where a 35. Explain Access modifiers used in Java. method calls itself to solve a problem. Ans: Access modifiers control the visibility of class 23. Define Inheritance? members. They include: Public: Accessible from Ans: Inheritance is a mechanism where a new class everywhere. Private: Accessible only within the class. (subclass) inherits the properties and behavior of an Protected: Accessible within the same package and existing class (superclass), promoting code reuse and subclasses. Default: Accessible only within the same hierarchical relationships. package. 24. What is difference between Anay and Array List? 36. Define polymorphism. Ans: Polymorphism is the Ans: Difference between Array and ArrayList: Array: ability of an object to take many forms, mainly through Fixed size, can store both primitive data types and method overriding (runtime polymorphism) and objects. ArrayList: Dynamic size, can only store objects method overloading (compile-time polymorphism) (wrapper classes for primitives). 37. What is a java program structure? 25. What is error? List types of error? Ans: A typical Java program structure includes: Ans: An error is a serious problem that occurs during the Package declaration (optional) Import statements execution of a program, usually related to system Class definition Methods Main method (entry point) resources or environment. Types include: Compile- 38. Define this Keyword. Ans: this is a reference variable time errors Runtime errors Logical errors that points to the current object within a method or 26. List any two restrictions for applet. constructor. Ans: Applets cannot access local file systems. Applets 39. Explain in detail the data types in java? Ans: Data cannot communicate with other servers except the one types in Java are categorized into: Primitive types: from which they were loaded. byte, short, int, long, float, double, boolean, char 28. What is Container? Reference types: Arrays, Classes, Interfaces Ans: A container is a component that can hold other 40. Which method is used to specify containers layout components, such as panels or frames, in GUI with syntax applications. . Ans: The setLayout(LayoutManager layout) method is 29. What is JDK? How to build and run java program? used to specify a container's layout. Example: Ans: JDK (Java Development Kit) is a software container.setLayout(new FlowLayout()); development kit required to develop Java applications. 41. What is the default layout for Frame and Panel? To build and run a Java program: Write the source Ans: The default layout for a Frame is BorderLayout, and code. Compile using javac command. Run the for a Panel, it is FlowLayout. compiled bytecode using the java command. 42. List and explain any 2 in-built exceptions. 30. What is use of classpath? Ans: NullPointerException: Thrown when attempting to Ans: The classpath is an environment variable that tells use null where an object is required. the Java Virtual Machine (JVM) where to look for user- ArrayIndexOutOfBoundsException: Thrown when defined classes and packages when running Java accessing an array with an invalid index. applications. 43. Explain the purpose of getContentPane(). 31. What is collection? Explain collection frame work Ans: In Swing, getContentPane() is used to retrieve the in details. Ans: A collection is an object that groups content pane of a JFrame, where you can add multiple elements into a single unit. Java’s Collection components like buttons or text fields. Framework provides classes like List, Set, and Map for 44. What is an Interface? storing and manipulating data. Ans: An interface in Java is a reference type that can 32. What is the use of Reader and Writer class? contain only abstract methods (before Java 8) or default Ans: Reader and Writer classes are used for handling methods (Java 8 and later). Classes implement character-based input/output streams in Java. Reader interfaces to provide specific behaviors. reads characters, while Writer writes characters.