Class 12 Informatics Practices Practice Assignments: CBSE Class 12 Informatics Practices Worksheet All Chapters
Review targeted academic assignments with the CBSE Class 12 Informatics Practices Worksheet All Chapters. Built according to official CBSE standards for the 2026-27 term, these downloadable Class 12 Informatics Practices worksheets support effective daily practice for All topics.
Download All topics Assignment PDF with Solutions
Navigate directly to the solved Informatics Practices assignments using the digital viewer below. Each practice set includes detailed step-by-step solutions, allowing students to instantly cross-check their work and identify areas requiring further revision.
Chapter 1
Question 1. What is MAC Address?
Answer: MAC (Media Access Control) Address is a unique physical address assigned to a network interface card (NIC) by the manufacturer. It operates at the Data Link Layer of the OSI model and is used for hardware-level identification in network communications.
In simple words: A MAC address is a permanent, unique hardware ID for network devices.
Exam Tip: Mention that MAC addresses are 48-bit addresses usually represented in hexadecimal format.
Question 2. Write two advantages of networks.
Answer: 1. Resource Sharing: Hardware devices like printers and scanners can be shared among multiple users.
2. Data Sharing and Communication: Users can easily transfer files and communicate via email or messaging.
In simple words: Networks allow users to share devices and files easily.
Exam Tip: Keep the points distinct and concise for full marks.
Question 3. Write two disadvantages of networks.
Answer: 1. Security Risks: Networks are vulnerable to hackers, malware, and unauthorized access.
2. Dependency on Central Server: If a main file server fails, the entire network operations can halt.
In simple words: Networks can have security threats and depend heavily on central servers.
Exam Tip: Focus on security and single points of failure.
Question 4. What is communication channel? Name the basic types of communication channels available.
Answer: A communication channel is a medium used to transmit data signals from a sender to a receiver. The basic types are:
1. Guided (Wired) media (e.g., Twisted pair, Coaxial cable, Fiber optic cable)
2. Unguided (Wireless) media (e.g., Radio waves, Microwaves, Infrared)
In simple words: A communication channel is the path through which data travels, either via cables or wireless signals.
Question 5. What is IP address?
Answer: An IP (Internet Protocol) address is a unique logical numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. It helps in routing packets across networks.
In simple words: An IP address is a logical address that identifies a device on a network.
Exam Tip: Differentiate IP address (logical, changeable) from MAC address (physical, permanent).
Question 6. What is domain name? How is it alternatively known?
Answer: A domain name is a human-readable text-based address used to identify one or more IP addresses on the Internet (e.g., www.example.com). It is alternatively known as a Web Address or URL component.
In simple words: A domain name is an easy-to-remember name for a website instead of a numeric IP address.
Exam Tip: Mention that it simplifies accessing websites by replacing numeric IP addresses.
Question 7. What are the various types of networks?
Answer: The primary types of computer networks based on geographical scope are:
1. PAN (Personal Area Network)
2. LAN (Local Area Network)
3. MAN (Metropolitan Area Network)
4. WAN (Wide Area Network)
In simple words: Networks are classified by size, ranging from personal rooms to global connections.
Exam Tip: List them in increasing order of geographical coverage for clarity.
Question 8. What is the difference between MAN and WAN?
Answer:
- MAN (Metropolitan Area Network) covers an entire city or town, connecting multiple LANs within that region.
- WAN (Wide Area Network) spans a large geographical area, such as a country, continent, or the entire globe (e.g., the Internet).
In simple words: MAN connects a city, while WAN connects across countries and the world.
Exam Tip: Emphasize the geographical scale and ownership differences.
Question 9. What is meant by Topology? Name some popular topologies.
Answer: Network topology refers to the physical or logical arrangement of devices and links in a computer network. Popular topologies include:
1. Bus Topology
2. Star Topology
3. Ring Topology
4. Tree Topology
5. Mesh Topology
In simple words: Topology is the layout or structure of how computers are connected in a network.
Exam Tip: Distinguish between physical and logical topology when applicable.
Question 10. Define a network.
Answer: A computer network is a collection of two or more autonomous computing devices connected together via communication media and protocols to share resources, data, and information.
In simple words: A network is a group of connected computers that can talk to each other and share resources.
Exam Tip: Include hardware, connection media, and resource sharing in your definition.
Question 11. What are the similarities and differences between bus and tree topologies?
Answer:
- Similarity: Both topologies use a central backbone cable to transmit data across the network.
- Differences: Bus topology consists of a single continuous cable with devices attached linearly. Tree topology is a combination of star and bus topologies structured in a hierarchical parent-child format.
In simple words: Both use a backbone cable, but tree topology branches out hierarchically like a family tree.
Exam Tip: Mention the hierarchical structure of tree topology.
Question 12. What are the limitations of star topology?
Answer:
1. If the central hub or switch fails, the entire network goes down.
2. It requires more cable length compared to bus topology.
3. Performance and node capacity are limited by the capacity of the central device.
In simple words: Star topology depends entirely on the central hub; if it fails, everything stops.
Exam Tip: Highlight the single point of failure (central hub/switch).
Question 13. What are the goals of network?
Answer:
1. Resource sharing (hardware and software)
2. High reliability through alternative data paths
3. Cost reduction by sharing expensive peripherals
4. Fast and efficient communication
In simple words: The main goals are sharing resources, saving costs, and improving communication.
Exam Tip: Resource sharing and high reliability are core keywords.
Question 14. Write the applications of network?
Answer:
1. E-commerce and online banking
2. Video conferencing and VoIP communication
3. Cloud computing and data sharing
4. Accessing centralized databases over the internet
In simple words: Networks are used for online shopping, banking, video calls, and cloud storage.
Exam Tip: Provide real-world examples like banking or e-commerce.
Question 15. What do you understand by domain name resolution?
Answer: Domain Name Resolution is the process of translating a human-readable domain name (e.g., www.example.com) into its corresponding numerical IP address (e.g., 192.0.2.1) using the Domain Name System (DNS).
In simple words: Domain name resolution is translating a website name into an IP address that computers understand.
Exam Tip: Mention DNS (Domain Name System) as the service responsible for this process.
Question 16. What are communication channels? Discuss various channels available for networks?
Answer: Communication channels are pathways through which data is transmitted between devices. They are categorized into:
1. Guided Media: Twisted-pair cables, Coaxial cables, and Fiber-optic cables.
2. Unguided Media: Radio waves, Microwaves, and Infrared signals.
In simple words: Communication channels are wired or wireless paths used to send data.
Exam Tip: Group your explanation clearly into wired and wireless categories.
Question 17. Advantages and disadvantages of the followings : i. optic fiber ii. coaxial cables iii. twisted pair cables iv. radio waves v. microwaves vi. Satellites
Answer:
i. Optic fiber: Advantage - Extremely high bandwidth and fast speed over long distances; Disadvantage - Expensive and fragile.
ii. Coaxial cables: Advantage - Higher bandwidth than twisted-pair and good noise immunity; Disadvantage - Bulky and difficult to install.
iii. Twisted pair cables: Advantage - Cheap and easy to install; Disadvantage - Susceptible to electromagnetic interference and limited distance.
iv. Radio waves: Advantage - Omni-directional and supports mobility; Disadvantage - Prone to interference and security issues.
v. Microwaves: Advantage - High capacity point-to-point transmission; Disadvantage - Line-of-sight required and affected by weather.
vi. Satellites: Advantage - Covers large global areas; Disadvantage - High propagation delay and expensive setup.
In simple words: Each medium has trade-offs between speed, cost, range, and installation ease.
Exam Tip: Structure your answer clearly using bullet points for each medium.
Question 18. Discuss and compare various types of networks?
Answer:
- PAN: Covers personal space (within 10 meters), e.g., Bluetooth devices.
- LAN: Covers a single room, building, or office, offering high speed and low error rates.
- MAN: Covers a city, connecting multiple LANs.
- WAN: Covers countries or the globe, utilizing telecommunication links and satellites.
In simple words: Networks are compared by their physical size and transmission speeds.
Exam Tip: Use a comparative approach highlighting coverage area and speed.
Question 19. Explain mostly used topologies.
Answer:
1. Bus Topology: Devices connect to a single central cable (backbone). Easy to set up, but failure of the backbone disrupts the network.
2. Star Topology: All devices connect to a central hub/switch. Easy to troubleshoot, but hub failure brings down the network.
3. Ring Topology: Devices form a closed loop where data travels in one direction. Token passing is used, but a break in the ring fails the network.
In simple words: Bus uses a single backbone, Star uses a central hub, and Ring connects devices in a circular loop.
Exam Tip: Highlight the structure, advantages, and disadvantages of each.
Question 20. What are hubs? What are its types?
Answer: A hub is a hardware device used to connect multiple devices in a local network. It broadcasts incoming data packets to all ports regardless of the intended recipient. Types include:
1. Active Hub: Amplifies and regenerates the signal.
2. Passive Hub: Acts merely as a physical connector without amplifying signals.
In simple words: A hub connects network devices and broadcasts data to all ports.
Exam Tip: Note that modern switches have mostly replaced hubs due to efficiency.
Question 21. What is the role of a switch in a network?
Answer: A switch is an intelligent networking device that connects devices in a LAN and uses MAC addresses to forward data packets directly to the intended destination port instead of broadcasting them to all ports.
In simple words: A switch delivers network data directly to the specific device that requested it.
Exam Tip: Contrast switches with hubs by emphasizing intelligent packet forwarding.
Question 22. Discuss repeater.
Answer: A repeater is an electronic device that receives a network signal, cleans and amplifies it, and retransmits it over long distances to prevent signal attenuation and degradation.
In simple words: A repeater boosts weakened signals so they can travel further.
Exam Tip: Mention that repeaters operate at the Physical Layer of the OSI model.
Question 23. What are common threats to network security?
Answer:
1. Malware (Viruses, Worms, Trojans)
2. Phishing and Social Engineering
3. Denial of Service (DoS) attacks
4. Unauthorized access and packet sniffing
In simple words: Common threats include viruses, hackers, phishing, and DoS attacks.
Exam Tip: List standard cybersecurity threats clearly.
Question 24. What are denial of services attacks?
Answer: A Denial of Service (DoS) attack is a cyber-attack in which the attacker floods a target system, server, or network with overwhelming traffic, rendering it unavailable to legitimate users.
In simple words: A DoS attack overwhelms a server with fake traffic so legitimate users cannot access it.
Exam Tip: Emphasize that it disrupts service availability.
Question 25. How can you prevent/ counter threats of network security?
Answer:
1. Using firewalls and intrusion detection systems
2. Installing updated antivirus and anti-malware software
3. Implementing strong passwords and multi-factor authentication
4. Encrypting data transmissions
In simple words: Protect networks using firewalls, antivirus, encryption, and strong passwords.
Exam Tip: Focus on preventive measures like firewalls and encryption.
Question 26. When do you think, ring topology becomes the best choice for a network?
Answer: Ring topology is suitable when data needs to be transmitted in an orderly fashion without a central controller, particularly in environments where each device has equal access privileges and deterministic data transmission times are required.
In simple words: Ring topology works well when equal access and predictable transmission are needed.
Exam Tip: Mention token passing and lack of a central controller.
Question 27. Write the two advantages and two disadvantages of star topology in network.
Answer:
Advantages:
1. Easy to add or remove devices without disrupting the network.
2. Failure of one cable only affects that specific device, not the whole network.
Disadvantages:
1. Dependency on the central hub/switch.
2. Requires more cable than bus topology.
In simple words: Star is easy to expand and maintain, but relies entirely on the central hub.
Exam Tip: Clearly separate advantages and disadvantages.
Question 28. Write the disadvantages if twisted pair cables.
Answer:
1. High susceptibility to electromagnetic interference (EMI) and noise.
2. Limited transmission distance before signal attenuation occurs.
3. Lower bandwidth compared to coaxial and fiber optic cables.
In simple words: Twisted pair cables have limited range and are easily affected by electrical interference.
Exam Tip: Mention interference and distance limitations.
Question 29. Define Hub.
Answer: A hub is a physical layer networking device that connects multiple computers in a LAN and broadcasts incoming data packets to all connected ports indiscriminately.
In simple words: A hub connects devices and broadcasts all incoming data to every port.
Exam Tip: Emphasize the broadcast nature of a hub.
Question 30. Define switch.
Answer: A switch is a data link layer device that connects network segments and intelligently forwards data packets to specific destination devices based on their MAC addresses.
In simple words: A switch is an intelligent hub that sends data directly to the correct recipient.
Exam Tip: Highlight MAC-address-based routing.
Chapter 2
Question 1. What is OSS?
Answer: OSS stands for Open Source Software. It refers to software whose source code is made publicly available for viewing, modification, distribution, and enhancement by anyone.
In simple words: OSS is software with publicly available source code that anyone can inspect and modify.
Exam Tip: Mention that source code accessibility is the defining characteristic.
Question 2. Expand the terms: OSI, FLOSS, FSF, GNU, W3C, and PHP.
Answer:
- OSI: Open Systems Interconnection / Open Source Initiative
- FLOSS: Free/Libre and Open Source Software
- FSF: Free Software Foundation
- GNU: GNU is Not Unix
- W3C: World Wide Web Consortium
- PHP: PHP: Hypertext Preprocessor
In simple words: These are standard acronyms used in networking, open source, and web development.
Exam Tip: Memorize exact expansions as they frequently appear in exams.
Question 3. What is free software?
Answer: Free software refers to software that grants users the freedom to run, copy, distribute, study, change, and improve the software. It emphasizes freedom of use rather than price (free as in freedom, not necessarily free of cost).
In simple words: Free software gives users the freedom to use, study, and modify the code.
Exam Tip: Mention Richard Stallman's distinction of "free as in free speech, not free beer".
Question 4. Define freeware and shareware.
Answer:
- Freeware: Software that is available for use at no financial cost, but its source code is not open or modifiable.
- Shareware: Software distributed free of charge on a trial basis, with the expectation that users will pay for it after a trial period or for full features.
In simple words: Freeware is free to use but closed source; shareware is free for a trial period before payment is required.
Exam Tip: Clearly differentiate between cost and source code availability.
Question 5. What is openoffice.org?
Answer: OpenOffice.org is an open-source office productivity software suite that includes tools for word processing, spreadsheets, presentations, graphics, and databases as an alternative to proprietary suites.
In simple words: OpenOffice.org is a free, open-source office suite for documents and spreadsheets.
Exam Tip: Mention components like Writer, Calc, and Impress.
Question 6. What is font? What is OTF?
Answer:
- Font: A complete set of characters of a specific typeface, style, and size.
- OTF (OpenType Font): A scalable computer font format developed jointly by Microsoft and Adobe, supporting multi-platform use and advanced typographic features.
In simple words: A font is a text style, and OTF is an advanced, scalable font format.
Exam Tip: Mention the creators (Microsoft and Adobe) of OTF.
Question 7. What are different font categories?
Answer:
1. Serif (e.g., Times New Roman)
2. Sans-Serif (e.g., Arial, Helvetica)
3. Monospace (e.g., Courier New)
4. Cursive / Script
5. Decorative / Display
In simple words: Fonts are categorized into serif, sans-serif, monospace, cursive, and decorative styles.
Exam Tip: Give examples for serif and sans-serif.
Question 8. Define ODF.
Answer: ODF stands for Open Document Format. It is an XML-based open file format for office applications (spreadsheets, charts, presentations, and word processing documents) standardized by OASIS.
In simple words: ODF is an open, standard file format for saving office documents.
Exam Tip: Mention OASIS and XML-based format.
Question 9. What is key map based text entry?
Answer: Key map based text entry is a method of typing in regional or Indian scripts where specific keyboard keys are mapped to corresponding characters or phonetic equivalents in the target script.
In simple words: Key mapping assigns specific keyboard keys to generate characters in regional languages.
Exam Tip: Connect it with Indian language computing and keyboard layouts like InScript.
Question 10. What is Unicode?
Answer: Unicode is a universal international character encoding standard designed to support the worldwide interchange, processing, and display of text in all modern and historic writing systems.
In simple words: Unicode is a universal standard that represents characters from all world languages digitally.
Exam Tip: Emphasize that it provides a unique number for every character regardless of platform or language.
Question 11. What is ISCII?
Answer: ISCII stands for Indian Script Code for Information Interchange. It is an 8-bit encoding scheme designed for representing various Indian scripts (such as Devanagari, Bengali, Tamil, etc.).
In simple words: ISCII is an 8-bit encoding system for Indian languages.
Exam Tip: Mention that Unicode has largely succeeded ISCII.
Question 12. What is Indian Script key map known as?
Answer: The standard Indian script keyboard layout is commonly known as InScript (Indian Script).
In simple words: Indian script key maps are known as InScript keyboards.
Exam Tip: InScript is standardized by the Department of Electronics (DoE), Government of India.
Question 13. What is open source software?
Answer: Open source software is software whose source code is available to customers and developers, allowing them to inspect, modify, and improve the software freely.
In simple words: Open source software allows anyone to view and modify its code.
Exam Tip: Focus on community collaboration and source code accessibility.
Question 14. Compare Free software and open source software.
Answer:
- Free Software focuses primarily on user freedoms (run, copy, distribute, modify) as championed by FSF.
- Open Source Software focuses on the practical development methodology and sharing of source code for peer review.
In simple words: Free software emphasizes ethical user freedoms, while open source emphasizes collaborative development.
Exam Tip: Note that while their licenses overlap heavily, their underlying philosophies differ.
Question 15. Compare OSS and floss.
Answer: OSS stands for Open Source Software, while FLOSS stands for Free/Libre and Open Source Software. FLOSS is an inclusive term that encompasses both Free Software (FSF perspective) and Open Source Software (Open Source Initiative perspective).
In simple words: FLOSS combines both "free software" and "open source software" terms.
Exam Tip: FLOSS is a broader umbrella term.
Question 16. Compare Proprietary software and free software.
Answer:
- Proprietary Software has restricted source code, and users cannot modify or redistribute it without permission.
- Free Software provides full user freedom to view, modify, and redistribute the source code.
In simple words: Proprietary software is restricted and controlled, whereas free software is open and user-controlled.
Exam Tip: Highlight restrictions on source code modification and redistribution.
Question 17. Compare Free ware and shareware.
Answer:
- Freeware is completely free to use indefinitely, but closed-source.
- Shareware is free for a limited evaluation trial period, after which payment is required for continued use.
In simple words: Freeware is permanently free without source access; shareware requires payment after a trial.
Exam Tip: Focus on the trial period and payment condition in shareware.
Question 18. Compare Freeware and free software
Answer:
- Freeware is software available at zero cost, but its source code is closed and modification is prohibited.
- Free Software provides users with the freedom to modify, study, and redistribute the source code, regardless of price.
In simple words: Freeware is free in price; free software is free in terms of user rights and source code.
Exam Tip: Reiterate the price vs. freedom distinction.
Question 19. Write Short notes on GNU.
Answer: GNU (GNU's Not Unix) is a mass collaborative free software project launched by Richard Stallman in 1983 to develop a free operating system compatible with Unix. It provides foundational free software tools and compilers (like GCC).
In simple words: GNU is a project that provides a free Unix-like operating system and software tools.
Exam Tip: Mention Richard Stallman and the recursive acronym.
Question 20. Write short notes on LINUX.
Answer: Linux is a popular, open-source Unix-like operating system kernel originally created by Linus Torvalds in 1991. Combined with GNU utilities, it forms the GNU/Linux operating system used widely in servers, desktops, and mobile devices.
In simple words: Linux is a widely used open-source operating system kernel created by Linus Torvalds.
Exam Tip: Mention Linus Torvalds and open-source kernel.
Question 21. Write Short notes on MOZILLA.
Answer: Mozilla is a free software community best known for developing the Firefox web browser and Thunderbird email client. It promotes open standards and user privacy on the web.
In simple words: Mozilla is an open-source community famous for creating the Firefox browser.
Exam Tip: Mention Firefox and open web standards.
Question 22. Write short notes on APACHE.
Answer: Apache HTTP Server is a widely used open-source web server software developed by the Apache Software Foundation. It plays a critical role in serving web pages on the internet securely and reliably.
In simple words: Apache is a popular open-source web server software used to host websites.
Exam Tip: Mention the Apache Software Foundation.
Question 23. Write short notes on POSTGRE SQL.
Answer: PostgreSQL is a powerful, open-source object-relational database management system (ORDBMS) known for its reliability, feature robustness, and support for complex SQL queries.
In simple words: PostgreSQL is a robust, open-source relational database management system.
Exam Tip: Highlight object-relational capabilities and open-source nature.
Question 24. Write short notes on PHP.
Answer: PHP (PHP: Hypertext Preprocessor) is a popular open-source server-side scripting language designed primarily for web development and creating dynamic web pages.
In simple words: PHP is a popular scripting language used for creating dynamic web pages.
Exam Tip: Specify that it is server-side scripting.
Question 25. Write short notes on Open Office.
Answer: Apache OpenOffice is an open-source office suite containing applications for word processing, spreadsheets, presentations, and drawing, serving as a free alternative to commercial office suites.
In simple words: OpenOffice is a free, open-source suite of office productivity tools.
Exam Tip: Mention applications like Writer, Calc, and Impress.
Question 26. What are technological standard and its various categories?
Answer: Technological standards are established specifications, rules, or guidelines for hardware, software, and protocols to ensure interoperability. Categories include:
1. Open Standards
2. Proprietary (Closed) Standards
In simple words: Standards are technical specifications ensuring devices and software work together.
Exam Tip: Emphasize interoperability and open vs. proprietary categories.
Question 27. Mention some advantages of open standards.
Answer:
1. Ensures interoperability between different hardware and software systems.
2. Prevents vendor lock-in.
3. Encourages innovation and community collaboration.
4. Reduces cost and promotes accessibility.
In simple words: Open standards prevent vendor lock-in and ensure different systems work together smoothly.
Exam Tip: Highlight "interoperability" and "no vendor lock-in".
Question 28. What is the significance of Unicode in terms of Indian Language Computing?
Answer: Unicode provides a universal encoding standard that allocates unique code points for characters of all Indian scripts (Hindi, Bengali, Tamil, Telugu, etc.), enabling seamless text processing, storage, search, and exchange across platforms without font dependency.
In simple words: Unicode allows Indian languages to be displayed and shared universally across all devices and software.
Exam Tip: Mention elimination of font dependency and universal support.
Question 29. How phonetic text entry is different from key map based text entry?
Answer:
- Phonetic text entry allows users to type regional language words using English phonetic sounds (e.g., typing 'namaste'), which are automatically transliterated into the target script.
- Key map based text entry maps specific keys of a standard keyboard directly to specific characters of the regional script (e.g., InScript layout).
In simple words: Phonetic typing uses sound-based transliteration, while key mapping directly assigns keys to script letters.
Exam Tip: Use examples like transliteration vs. direct keyboard layout mapping.
Question 30. What is Ogg Vorbis? Why?
Answer: Ogg Vorbis is a free, open-source audio compression format designed for audio streaming and storage without patent restrictions, offering high-quality sound at efficient bitrates.
In simple words: Ogg Vorbis is a free, high-quality audio compression format.
Exam Tip: Highlight that it is open-source and patent-free.
Question 31. How to represent character in Memory?
Answer: Characters are represented in computer memory using standardized numeric character encoding schemes such as ASCII, ISCII, or Unicode, where each character corresponds to a unique binary integer value.
In simple words: Characters are stored in memory as unique binary numbers using encoding standards like ASCII or Unicode.
Exam Tip: Mention binary representation and encoding standards like ASCII or Unicode.
Question 32. What is font and its types?
Answer: A font is a graphical representation of text characters of a specific typeface, weight, and size. Types include:
1. Serif fonts
2. Sans-Serif fonts
3. Monospace fonts
4. Script/Cursive fonts
In simple words: A font is a text style, categorized into serif, sans-serif, monospace, and script.
Exam Tip: List the primary typeface categories clearly.
Chapter 3
Question 1. Name any two Object Oriented Programming languages?
Answer: 1. Java
2. C++
In simple words: Two popular OOP languages are Java and C++.
Exam Tip: Keep examples standard and straightforward.
Question 2. Why is java called a platform independent language?
Answer: Java is platform-independent because Java source code is compiled into an intermediate bytecode (class file), which can be executed on any operating system equipped with a Java Virtual Machine (JVM).
In simple words: Java compiles code into bytecode that runs on any machine with a JVM.
Exam Tip: Always mention bytecode and JVM for full marks.
Question 3. Elaborate the java Compilation process.
Answer:
1. The programmer writes Java source code in a .java file.
2. The Java compiler (javac) compiles the source code into platform-neutral bytecode saved in a .class file.
3. The Java Virtual Machine (JVM) interprets or compiles the bytecode into machine-specific native code for execution.
In simple words: Java source code is compiled into bytecode, which the JVM runs on any system.
Exam Tip: Use a step-by-step format: Source code -> Compiler -> Bytecode -> JVM -> Machine code.
Question 4. Why do we write a comment in a program? What are the two ways of writing comment in a java Program?
Answer: Comments are written in a program to improve readability, explain code logic, and assist in documentation. The two ways to write comments in Java are:
1. Single-line comment: // Comment text
2. Multi-line comment: /* Comment text */ (also documentation comments /** ... */)
In simple words: Comments explain code to humans and are ignored by the compiler.
Exam Tip: Show proper syntax for both single-line and multi-line comments.
Question 5. What is a syntax error in context of a program? Give an example.
Answer: A syntax error occurs when code violates the grammatical and structural rules of the programming language. The compiler catches these errors and prevents compilation.
Example: Omitting a semicolon at the end of a statement.
int x = 10 (Missing semicolon causes a syntax error)
In simple words: A syntax error is a violation of programming grammar, like forgetting a semicolon.
Exam Tip: Mention that syntax errors are detected at compile-time.
Question 6. What is RAD programming? Why is program development in java using Netbeans IDE is RAD?
Answer: RAD (Rapid Application Development) is a software development approach that prioritizes fast prototyping and quick feedback over strict planning. NetBeans IDE supports RAD because it provides drag-and-drop GUI components, automatic code generation, and visual builders that speed up development.
In simple words: RAD allows fast software development using visual drag-and-drop tools like NetBeans.
Exam Tip: Mention visual design tools and rapid prototyping.
Question 7. What is IDE? Name two IDE for Programming in java.
Answer: An IDE (Integrated Development Environment) is a software application that provides comprehensive facilities for software development, including a source code editor, compiler/interpreter, and debugger. Two IDEs for Java are:
1. NetBeans
2. Eclipse
In simple words: An IDE is an all-in-one software tool for writing and debugging code.
Exam Tip: NetBeans and Eclipse are industry standards for Java.
Question 8. Name any two type of Tokens available in Java
Answer: 1. Keywords (e.g., int, class)
2. Identifiers (e.g., variable names like totalScore)
In simple words: Tokens are the smallest individual units of a program, such as keywords and identifiers.
Exam Tip: Other tokens include literals, operators, and separators.
Question 9. What are primitive data types? Name the various primitive data type available in Java.
Answer: Primitive data types are built-in data types predefined by the programming language that hold simple values. Java has 8 primitive data types:
1. byte
2. short
3. int
4. long
5. float
6. double
7. char
8. boolean
In simple words: Primitive types are fundamental data types built directly into Java.
Exam Tip: List all 8 types for full marks.
Question 10. What are Reference data types?
Answer: Reference data types (or non-primitive data types) store memory addresses (references) to objects rather than the actual data values themselves. Examples include Strings, Arrays, and user-defined classes.
In simple words: Reference types point to the memory location of objects rather than holding the raw value.
Exam Tip: Mention that reference types store memory addresses of objects.
Question 11. What is type casting?
Answer: Type casting is the process of converting a variable from one data type to another. It can be implicit (widening conversion done automatically by Java) or explicit (narrowing conversion done manually using casting operators).
In simple words: Type casting converts one data type into another.
Exam Tip: Differentiate between implicit (widening) and explicit (narrowing) casting.
Question 12. Name and explain the usage of any two data types used in Java to store numbers with decimals.
Answer:
1. float: A single-precision 32-bit floating-point data type, used for fractional numbers when memory is constrained (e.g., float price = 19.99f;).
2. double: A double-precision 64-bit floating-point data type, used for high-precision decimal numbers (e.g., double pi = 3.1415926535;).
In simple words: float and double store decimal numbers, with double offering higher precision.
Exam Tip: Note that double is the default data type for decimal literals in Java.
Question 13. What are Keywords? Give two examples of keywords available in Java.
Answer: Keywords are reserved words that have predefined special meanings to the Java compiler and cannot be used as identifiers (variable or method names).
Examples: public, class, int, void
In simple words: Keywords are reserved words with special meaning in Java.
Exam Tip: Mention that keywords are written entirely in lowercase.
Question 14. Name and explain the usage of any one relational and one logical operator in Java.
Answer:
- Relational Operator (>): Greater-than operator compares two values and returns true if the left operand is strictly greater than the right operand.
- Logical Operator (&&): Logical AND operator evaluates two boolean expressions and returns true only if both operands are true.
In simple words: Relational operators compare values, and logical operators combine conditions.
Exam Tip: Give brief code examples like x > y and a && b.
Question 15. What is the difference between = and == operator in java?
Answer:
- = is the assignment operator used to assign a value to a variable (e.g., int x = 5;).
- == is the relational equality operator used to compare two values for equality (e.g., if (x == 5)).
In simple words: = assigns values, while == compares values for equality.
Exam Tip: A classic exam question—be sure to state assignment vs. comparison clearly.
Question 16. Name the two type of selection statement available in Java.
Answer: 1. if statement (including if-else and nested if)
2. switch statement
In simple words: Selection statements in Java are if-else and switch.
Exam Tip: These are branching or decision-making constructs.
Question 17. Write the purpose of Switch Statement with the help of an example. Which Java Statement can be used in place of switch statement? In the switch statement, what happens if every case fails and there is no default option?
Answer:
- Purpose: A switch statement allows multi-way branching based on the value of a variable.
Example:
switch(day) { case 1: System.out.println("Monday"); break; default: System.out.println("Invalid"); }
- Alternative: An if-else-if ladder can be used in place of a switch statement.
- No default case: If all cases fail and there is no default label, the switch statement simply terminates without executing any code.
In simple words: Switch handles multiple choices cleanly; if no case matches and there is no default, nothing happens.
Exam Tip: Mention the if-else ladder as the equivalent construct.
Question 18. What is the purpose of ‘break’ statement in java?
Answer: The break statement is used to prematurely exit from a loop (for, while, do-while) or terminate a branch in a switch statement.
In simple words: The break statement immediately exits a loop or switch case.
Exam Tip: Prevents fall-through in switch statements and stops loops early.
Question 19. What is the purpose of ‘break’ statement in java?
Answer: (Repeated question)
The break statement terminates loops or switch blocks immediately when encountered.
In simple words: Used to exit loops or switch cases early.
Exam Tip: Keep answer consistent with Question 18.
Question 20. Find the output of the following code snippet written in java public static void main(String [ ]args) { long a=78345,s1=0,s2=0,r; while(a>0) { r=a%10; if (r%4==0) s1+= r; else s2+=r; a/=10; } System.out.println("S1 ="+ s1); System.out.println("S2 ="+ s2); }
Answer:
Initial values: a = 78345, s1 = 0, s2 = 0
- Iteration 1: r = 5. 5 % 4 != 0 -> s2 = 0 + 5 = 5, a = 7834
- Iteration 2: r = 4. 4 % 4 == 0 -> s1 = 0 + 4 = 4, a = 783
- Iteration 3: r = 3. 3 % 4 != 0 -> s2 = 5 + 3 = 8, a = 78
- Iteration 4: r = 8. 8 % 4 == 0 -> s1 = 4 + 8 = 12, a = 7
- Iteration 5: r = 7. 7 % 4 != 0 -> s2 = 8 + 7 = 15, a = 0
Output:
S1 =12
S2 =15
In simple words: The code separates digits of 78345, sums multiples of 4 into S1 and others into S2.
Exam Tip: Trace loop iterations step-by-step on your scratchpad to avoid arithmetic errors.
Question 21. Correct the errors in the following program segment written in JAVA. You are just required to write the corrected code, underlying the corrections made. public Static Void Main (String [] args) { Integer Nos = 100; while (Nos => 45) { If (Nos % 5 = 0); Nos+=10; otherwise Nos + = 20; } }
Answer:
Corrected Code:
public static void main (String [] args) {
int Nos = 100;
while (Nos >= 45) {
if (Nos % 5 == 0) {
Nos += 10;
}
else {
Nos += 20;
}
}
}
In simple words: Fixed capitalization, operator symbols (>=, ==), removed erroneous semicolons, and replaced "otherwise" with else.
Exam Tip: Watch out for case sensitivity in Java keywords like static, void, and if.
Question 22. What will be output of the following code: byte b; double d= 417.35; b= (byte) d; system.out.println(b)
Answer:
Explicit casting of double 417.35 to byte truncates the decimal part (417) and takes the value modulo 256 due to byte overflow (417 % 256 = 161, and with signed byte representation in Java, it wraps around to -95).
In simple words: Casting a large double to a byte causes numeric overflow and truncation.
Exam Tip: Be careful with explicit narrowing casting when values exceed byte range (-128 to 127).
Question 23. Given the value of a variable, write a statement, without using if construct, which will produce the absolute value of a variable.
Answer:
Using ternary operator or Math class:
int absVal = (x < 0) ? -x : x;
Or: int absVal = Math.abs(x);
In simple words: Use the ternary operator or Math.abs() to find absolute value without an if statement.
Exam Tip: The ternary operator (condition) ? true_val : false_val is ideal here.
Question 24. What is wrong with the following code fragment? Switch (x) { case 1: n1= 10; n2= 20; case 2: n3=30; break; n4= 40; }
Answer:
1. Switch should be lowercase (switch).
2. The statement n4 = 40; is placed outside any case block, making it unreachable code.
In simple words: The keyword Switch has incorrect capitalization and n4=40 is placed outside any case.
Exam Tip: Java is strictly case-sensitive; check keyword spellings.
Question 25. What will be the output of the following program code? int m = 100; int n = 300; while(++m < --n); System.out.println(m+” “+ n);
Answer:
- Initially: m = 100, n = 300
- The while loop increments m and decrements n until ++m < --n becomes false.
- When m = 199 and n = 201, ++m becomes 200 and --n becomes 200 (200 < 200 is false).
Output:
200 200
In simple words: The loop runs until m and n meet at 200.
Exam Tip: Notice the semicolon at the end of the while loop, making it a delay/null loop.
Question 26. What does the following fragment display String s = “Six:” + 3+ 3; System.out.println(s);
Answer:
Output:
Six:33
In simple words: String concatenation causes numbers to be appended rather than added arithmetically.
Exam Tip: Once a string concatenation starts from left to right, subsequent numbers are treated as strings.
Question 27. What will be the output of the following code snippet? int x= 10; int y = 20; if ((x<y)||(x=5) > 10) System.out.println(x); else System.out.println(y);
Answer:
Since x < y (10 < 20) is true, due to short-circuit evaluation in the logical OR (||) operator, the right-hand side (x=5) > 10 is not evaluated.
Therefore, x remains 10.
Output:
10
In simple words: Short-circuit evaluation skips the second condition because the first condition is already true.
Exam Tip: Remember short-circuit behavior for && and ||.
Question 28. State the output of the following program: public static void main(String args[ ]) { int x = 10; int y = 15; System.out.println((x>y)? 3.14: 3); }
Answer:
Since x > y (10 > 15) is false, the ternary operator selects the false branch (3, which is promoted to double 3.0 due to type promotion with 3.14).
Output:
3.0
In simple words: The condition is false, so it prints 3 promoted to 3.0.
Exam Tip: Ternary operator branches promote numeric types to maintain common data type.
Question 29. State the output of the following program: public static void main(String args[ ]) { int x = 10; float y = 10.0; System.out.println((x>y)? true: false); }
Answer:
Note: This code has a compilation error because floating-point literal 10.0 defaults to double and cannot be implicitly assigned to float y = 10.0; without an f suffix (10.0f). Assuming correct float declaration (float y = 10.0f;), 10 > 10.0 is false.
Output (if compiled):
false
In simple words: 10 > 10.0 evaluates to false.
Exam Tip: Watch out for decimal literal type defaults in Java (double vs float).
Question 30. Given a package named EDU.student, how would you import a class named Test contained in this package? Write one line statement.
Answer:
import EDU.student.Test;
In simple words: Use the import statement followed by the full package and class path.
Exam Tip: Package names are case-sensitive.
Question 31. Consider the following class definition: Class Student { abstract double result( ) } This code will not compile since a keyword is missing in the first line. What is the keyword?
Answer: The missing keyword is abstract before the class name (abstract class Student). Any class containing an abstract method must be declared abstract.
In simple words: A class containing an abstract method must itself be declared abstract.
Question 32. Can an abstract method be declared final? Yes or No
Answer: No
In simple words: Abstract methods cannot be final because they must be overridden by subclasses.
Exam Tip: final prevents overriding, whereas abstract requires overriding.
Chapter 4
Question 1. What does getPassword() on a password field return? (a) a string (b) an integer (c) a character array.
Answer: (c) a character array
In simple words: getPassword() returns a character array for enhanced security.
Exam Tip: Character arrays can be cleared from memory explicitly, unlike immutable Strings.
Question 2. Which of the following component is the best suited to accept the country of the user? A. List B. Combo box C. Radio button D. Check box
Answer: B. Combo box
In simple words: A combo box is best for selecting one option from a dropdown list of many countries.
Exam Tip: Combo boxes save screen space when there are many choices.
Question 3. What command do you need to write in actionPerformed() event handler of a button, in order to make it exit button? a. System.out.println(); b. System.exit(0); c. System.out.print()
Answer: b. System.exit(0);
In simple words: System.exit(0) terminates and exits the running application.
Exam Tip: Standard command to close a Java application.
Question 4. What method would you use, in order to simulate a button’s (namely Okbtn) click event, without any mouse activity from user’s side? a. Okbtn.setText() b. Okbtn.getText() c. Okbtn.doClick()
Answer: c. Okbtn.doClick()
In simple words: doClick() programmatically simulates clicking a button.
Question 5. What would be the name of the event handler method in the ListSelection listener interface for a list namely CheckList to handle its item selections? a. CheckListValueChanged() b. getSelectedValue() c. clearSelection()
Answer: a. CheckListValueChanged()
In simple words: valueChanged() is the event handler method for list selections.
Exam Tip: List selection listener uses valueChanged(ListSelectionEvent e).
Question 6. Which control displays text that the user cannot directly change or edit? a. TextField b. Checkbox c. Combobox d. Label
Answer: d. Label
In simple words: A label displays static text that users cannot edit.
Exam Tip: Labels are used for descriptive text on forms.
Question 7. Which control provides basic text editing facility? a. TextField b. Checkbox c. Combobox d. Label
Answer: a. TextField
In simple words: A text field allows users to type and edit text.
Exam Tip: Used for single-line user input.
Question 8. Occurrence of an activity is called: a. Function b. Class c. Object d. Event
Answer: d. Event
In simple words: An action or occurrence like a button click is called an event.
Exam Tip: GUI programming is event-driven.
Question 9. Which property is used to set the text of the Label? a. font b. text c. name d. icon
Answer: b. text
In simple words: The text property sets the text displayed on a label.
Exam Tip: Used across buttons, labels, and text fields.
Question 10. The object containing the data to be exhibited by the combo box by which property. a. editable b. model c. selectedIndex d. selectedItem
Answer: b. model
In simple words: The model property holds the items displayed in a combo box.
Exam Tip: Combos and lists use models to manage items.
Question 11. What is GUI programming?
Answer: Graphical User Interface (GUI) programming involves creating applications with visual elements such as windows, buttons, text fields, and menus that allow users to interact with the program graphically using a mouse and keyboard.
In simple words: GUI programming creates visual interfaces with buttons and windows for user interaction.
Exam Tip: Mention visual components and user interaction.
Question 12. How is swing related to GUI programming?
Answer: Swing is a lightweight GUI widget toolkit for Java that provides a rich set of components (such as JButton, JFrame, JTextField) used to build graphical user interfaces in Java applications.
In simple words: Swing is Java's toolkit for building graphical user interfaces.
Exam Tip: Swing components are part of the javax.swing package and start with 'J'.
Question 13. What is an event? What is event handler?
Answer:
- Event: An action or occurrence recognized by software (e.g., button click, mouse movement).
- Event Handler: A block of code or method that executes in response to a specific event.
In simple words: An event is an action like a click, and an event handler is the code that responds to it.
Exam Tip: Core concept in event-driven programming.
Question 14. What is the default name of action event handler of a button namely TestBtn?
Answer: TestBtn_actionPerformed
In simple words: NetBeans automatically names button event handlers using component name plus action performed.
Question 15. What property would you set to assign access key to a button?
Answer: The mnemonic property.
In simple words: The mnemonic property sets a keyboard shortcut (access key) for a button.
Exam Tip: Allows users to trigger buttons using Alt + key.
Question 16. Which method can programmatically performs the click action of a push button?
Answer: doClick()
In simple words: doClick() simulates clicking a button via code.
Exam Tip: Useful for automation and testing.
Question 17. Which property would you set the setting the password character as ‘$’?
Answer: The echoChar property.
In simple words: The echoChar property sets the masking character for password fields.
Exam Tip: Default echo character is typically an asterisk (*).
Question 18. Which method returns the password entered in a password field?
Answer: getPassword()
In simple words: getPassword() returns the entered password as a character array.
Exam Tip: Returns char[], not String.
Question 19. Which list property do you set for specifying the items for the list.
Answer: The model property.
In simple words: The model property defines the list items.
Exam Tip: Can be populated using DefaultListModel.
Question 20. Which method would you use to determine the index of selected item in a list?
Answer: getSelectedIndex()
In simple words: getSelectedIndex() returns the numeric index of the selected list item.
Exam Tip: Returns -1 if no item is selected.
Question 21. Which method would you use to insert an item at specified index, in the list?
Answer: addElement() or add(index, element) on the list's DefaultListModel.
In simple words: Use the list model's insert method to add items at specific positions.
Exam Tip: Managed through the list model object.
Question 22. How you can determine whether 5th item in a list is selected or not?
Answer: Using jList1.isSelectedIndex(4) (since indices are 0-based).
In simple words: Use isSelectedIndex(4) to check if the 5th item is selected.
Exam Tip: Remember that array and list indices start at 0.
Question 23. Which method you would use to insert ‘Hello’ at 10th position in the Text Area control.
Answer: jTextArea1.insert("Hello", offset);
In simple words: Use the insert() method with the text and character position offset.
Question 24. Which method you would like to use to insert an Icon (picture) on a Push Button.
Answer: setIcon()
In simple words: setIcon() sets an image icon on a button.
Exam Tip: Pass an ImageIcon object as the parameter.
Question 25. Which property would you like to set to make a Combo box editable?
Answer: The editable property (set to true).
In simple words: Setting editable to true allows users to type new entries into a combo box.
Exam Tip: Enables text entry alongside selection.
Question 26. What is Layout Manager? Name the layout manager s offered by NetBeans?
Answer: A Layout Manager is an automatic mechanism in Java Swing that governs the size and positioning of components within a container. Layout managers offered by NetBeans include:
1. FlowLayout
2. BorderLayout
3. GridLayout
4. BoxLayout
5. Absolute Layout (null layout)
In simple words: Layout managers automatically arrange GUI components inside containers.
Exam Tip: NetBeans defaults to Free Design / Absolute layout in GUI builder.
Question 27. Name three commonly used properties and methods of the following controls. (a) text field (b) text area (c) Check Box
Answer:
(a) Text Field: Properties (text, editable, columns), Methods (getText(), setText(), setEditable())
(b) Text Area: Properties (text, lineWrap, rows), Methods (getText(), setText(), append())
(c) Check Box: Properties (text, selected, font), Methods (isSelected(), setSelected(), getText())
In simple words: Each control has specific properties and methods to manage text and selection state.
Exam Tip: Memorize standard getter and setter methods for GUI components.
Question 28. What is dispose() used for?
Answer: The dispose() method is used to release all screen resources used by a window or frame, closing it and freeing up memory.
In simple words: dispose() closes a window and frees its system resources.
Question 29. What is the difference between- (a) Text field & Text area (b) Text field & password field (c) Radio Button & Check Box
Answer:
(a) Text Field accepts single-line input; Text Area accepts multi-line input.
(b) Text Field displays typed characters openly; Password Field masks characters with echo characters.
(c) Radio Button allows only one selection in a group; Check Box allows multiple independent selections.
In simple words: These controls differ in input lines, masking, and selection exclusivity.
Exam Tip: Highlight single vs multi-line, visible vs masked, and exclusive vs multiple selections.
Question 30. What is the significance of following properties of a text area ? (a) lineWrap (b) wrapStyleword
Answer:
(a) lineWrap: Automatically wraps long lines of text to the next line when they reach the edge of the text area.
(b) wrapStyleWord: Ensures that line wrapping occurs at word boundaries rather than breaking words mid-way.
In simple words: lineWrap wraps long lines, and wrapStyleWord keeps whole words together when wrapping.
Question 31. What is the significance of a button group? How do you create a button group?क्की
Answer: A button group logically binds multiple radio buttons together so that selecting one automatically deselects all others in the group.
Creation:
ButtonGroup bg = new ButtonGroup();
bg.add(jRadioButton1);
bg.add(jRadioButton2);
In simple words: Button groups ensure only one radio button can be selected at a time.
Exam Tip: Radio buttons require a ButtonGroup to function mutually exclusively.
Question 32. What do you understand by focus?
Answer: Focus refers to the active state of a GUI component indicating that it is currently selected to receive keyboard input from the user.
In simple words: Focus is the active component waiting for user input.
Exam Tip: Controlled using methods like requestFocus().
Question 33. What is meant by scope of a variable?
Answer: The scope of a variable defines the region of a program within which the variable is accessible and can be referenced.
In simple words: Scope determines where a variable can be accessed in your code.
Exam Tip: Variables can have local, instance, or class (static) scope.
Question 34. Create a Java Desktop Application to find the incentive (%) of Sales for a Sales Person on the basis of following feedbacks...
Answer:
double sales = Double.parseDouble(txtSales.getText());
double incentivePercent = 0;
if (chkMaxSales.isSelected()) incentivePercent += 10;
if (chkExcellentFB.isSelected()) incentivePercent += 8;
if (chkMaxCount.isSelected()) incentivePercent += 5;
double totalIncentive = sales * (incentivePercent / 100);
txtIncentive.setText("" + totalIncentive);
In simple words: Check selected checkboxes, sum their incentive percentages, and calculate total incentive against sales.
Exam Tip: Always parse text field input to numeric types before calculation.
Question 35. Assume the following interface built using Netbeans used for bill calculation of a ice-cream parlor... Write Java code for the following: a. On the click event of the button ‘Calculate’... b. On the Click event of the clear button... c. On the click event of the close button...
Answer:
a. Calculate Button Code:
double total = 0;
double vRate = 30, sRate = 35, cRate = 50;
if(chkVanilla.isSelected()){
txtVRate.setText("30");
total += vRate * Double.parseDouble(txtVQty.getText());
} else { txtVRate.setText("0"); }
if(chkStrawberry.isSelected()){
txtSRate.setText("35");
total += sRate * Double.parseDouble(txtSQty.getText());
} else { txtSRate.setText("0"); }
if(chkChocolate.isSelected()){
txtCRate.setText("50");
total += cRate * Double.parseDouble(txtCQty.getText());
} else { txtCRate.setText("0"); }
txtTotal.setText("" + total);
b. Clear Button Code:
txtVRate.setText(""); txtVQty.setText(""); txtSRate.setText(""); txtSQty.setText("");
txtCRate.setText(""); txtCQty.setText(""); txtTotal.setText("");
chkVanilla.setSelected(false); chkStrawberry.setSelected(false); chkChocolate.setSelected(false);
c. Close Button Code:
System.exit(0);
In simple words: Calculate totals based on selected checkboxes and quantities, clear fields when requested, and exit on close.
Exam Tip: Verify checkbox selection before reading quantity text fields to avoid NumberFormatExceptions.
Question 36. Read the following case study and answer the questions that follow... (a) Write the code to calculate the Basic salary, deductions, gross salary and net salary... (b) Write the code to exit the application. (c) Write the code to disable textfields for gross salary, deductions and netsalary.
Answer:
a. Calculation Code:
double basic = 0, da = 0, hra = 0, ded = 0, gross = 0, net = 0;
if(rbNonTeaching.isSelected()) { basic = 12500; da = basic * 0.31; hra = basic * 0.30; ded = basic * 0.12; }
else if(rbPGT.isSelected()) { basic = 14500; da = basic * 0.30; hra = basic * 0.30; ded = basic * 0.12; }
else if(rbTGT.isSelected()) { basic = 12500; da = basic * 0.21; hra = basic * 0.30; ded = basic * 0.12; }
else if(rbPRT.isSelected()) { basic = 11500; da = basic * 0.20; hra = basic * 0.25; ded = basic * 0.12; }
gross = basic + da + hra;
net = gross - ded;
if(chkMoreThan10.isSelected()) { net += 3000; }
txtBasic.setText("" + basic); txtGross.setText("" + gross); txtNet.setText("" + net);
b. Exit Code: System.exit(0);
c. Disable TextFields: txtGross.setEditable(false); txtDeductions.setEditable(false); txtNetSalary.setEditable(false);
In simple words: Determine salary components based on employee category, add bonus if applicable, and calculate gross and net salary.
Exam Tip: Use radio button selection checks to fetch corresponding table values.
Question 37. ABC School uses the following interface built in java to check the eligibility of a student... Write Java Code for the following: a. On Action event of the button ‘Calc Percentage’... b. On Action event of the button ‘Result’... c. On the Click event of the clear button... d. On the click event of the close button...
Answer:
a. Calc Percentage Code:
double actual = Double.parseDouble(txtPercentage.getText());
double netPer = actual;
if(chkNCC.isSelected()) { netPer += 5; }
txtNetPercentage.setText("" + netPer);
b. Result Code:
double net = Double.parseDouble(txtNetPercentage.getText());
String result = "Not Eligible";
if(rbScience.isSelected() && net >= 70) result = "Eligible for Science";
else if(rbCommerce.isSelected() && net >= 60) result = "Eligible for Commerce";
else if(rbHumanities.isSelected() && net >= 40) result = "Eligible for Humanities";
txtResult.setText(result);
c. Clear Code: txtName.setText(""); txtPercentage.setText(""); txtNetPercentage.setText(""); txtResult.setText(""); chkNCC.setSelected(false);
d. Close Code: System.exit(0);
In simple words: Add NCC bonus if selected, check eligibility against stream cutoffs, and display the result.
Exam Tip: Validate stream radio buttons and percentage thresholds carefully.
Question 38. Describe the relationship between properties, methods and events.
Answer: Properties define the state and appearance of a component, methods define the actions it can perform, and events are occurrences (like user interactions) that trigger methods to update properties or perform tasks.
In simple words: Properties store data, methods perform actions, and events trigger methods when user actions occur.
Exam Tip: Properties = attributes, Methods = functions, Events = triggers.
Question 39. What is container tag?
Answer: A container tag in GUI programming is a component (such as JFrame or JPanel) capable of holding and organizing other GUI components.
In simple words: A container tag holds and groups other components inside a window.
Question 40. What does a getPassword() method of a password field returns?
Answer: It returns a character array (char[]) containing the characters entered in the password field.
In simple words: getPassword() returns the password as a character array.
Exam Tip: Important security feature in Java Swing.
Question 41. What will be the contents of jTextArea1 after executing the following statement: jTextArea1.setText("Object\nOriented\tProgramming");
Answer:
Object
Oriented Programming
In simple words: \n creates a new line and \t inserts a tab space.
Exam Tip: Recognize escape sequences like newline (\n) and tab (\t).
Question 42. What is difference between jRadioButton and jCheckBox?
Answer: jRadioButton is mutually exclusive within a ButtonGroup (only one can be selected), whereas jCheckBox allows multiple independent selections.
In simple words: Radio buttons allow single selection from a group, while checkboxes allow multiple selections.
Exam Tip: Classic GUI component comparison question.
Question 43. What does a JList fire when a user selects an item?
Answer: It fires a ListSelectionEvent handled by a ListSelectionListener.
In simple words: Selecting an item in a JList fires a list selection event.
Exam Tip: Triggered via valueChanged() method.
Question 44. What is Layout Manager? Discuss briefly about layout managers offered by NetBeans?
Answer: A Layout Manager automatically manages the positioning and sizing of components within a container. Key layouts include FlowLayout (left to right), BorderLayout (five regions: North, South, East, West, Center), and GridLayout (tabular grid).
In simple words: Layout managers automatically arrange window components according to specific rules.
Exam Tip: Mention Flow, Border, and Grid layouts.
Question 47. Name three commonly used properties and methods of the following controls. (a) text field (b) text area (c) label (d) Check Box (e) button.
Answer:
(a) Text Field: Properties (text, editable, font), Methods (getText(), setText(), setEditable())
(b) Text Area: Properties (text, lineWrap, rows), Methods (getText(), setText(), append())
(c) Label: Properties (text, icon, font), Methods (getText(), setText(), setIcon())
(d) Check Box: Properties (text, selected, mnemonic), Methods (isSelected(), setSelected(), getText())
(e) Button: Properties (text, icon, enabled), Methods (getText(), setText(), doClick())
In simple words: Each GUI component has standard properties and methods for configuration and data retrieval.
Exam Tip: Group your answer clearly by component name.
Question 48. What is dispose() used for?
Answer: The dispose() method is used to close a window and free up all memory and system resources associated with it.
In simple words: dispose() closes windows and frees system memory.
Exam Tip: Essential for proper resource management in GUI applications.
Question 50. What is the difference between- (a) Text field & Text area (b) List & Combo (c) Radio Button & Check Box
Answer:
(a) Text Field is single-line; Text Area is multi-line.
(b) List displays multiple visible items allowing single/multiple selection; Combo Box is a drop-down control showing one item at a time.
(c) Radio Button allows only one selection in a group; Check Box allows multiple independent selections.
In simple words: These controls differ in input capacity, display style, and selection rules.
Exam Tip: Be concise and precise in structural comparisons.
Question 51. What is the significance of following properties of a text area ? (a) lineWrap (b) wrapStyleword
Answer:
(a) lineWrap: Automatically wraps text to the next line when it exceeds the width of the text area.
(b) wrapStyleWord: Ensures line wrapping breaks at word boundaries rather than in the middle of words.
In simple words: lineWrap wraps long lines, and wrapStyleWord keeps words intact during wrapping.
Exam Tip: Both properties improve text readability in text areas.
Question 52. What is the significance of a button group ? How do you create a button group ?
Answer: A button group ensures mutual exclusivity among radio buttons.
Creation:
ButtonGroup bg = new ButtonGroup();
bg.add(jRadioButton1);
In simple words: Button groups ensure only one radio button can be selected at a time.
Exam Tip: Always add radio buttons to a ButtonGroup instance.
Question 53. Discuss about some commonly used properties of lists and a combo boxes.
Answer:
- model: Manages the collection of items displayed in the list or combo box.
- selectedIndex: Stores the numeric index of the currently selected item.
- selectedItem: Stores the value of the currently selected item.
- editable (Combo Box only): Allows users to type custom values.
In simple words: Properties like model and selectedIndex manage list and combo box data.
Exam Tip: Mention the model property as the primary data container.
Question 54. What methods obtains the current selection of a combo box ? Give a code example.
Answer: getSelectedItem() or getSelectedIndex()
Example:
String selectedCountry = (String) jComboBox1.getSelectedItem();
In simple words: Use getSelectedItem() to retrieve the currently selected option.
Exam Tip: Type casting may be required when retrieving items from standard combo boxes.
Question 55. The FOR U SHOP has computerized its billing... a. Write the code for the CmdClear Button... b) Write the code for the CmdCalc Button to display the Discount Amount and Net Price...
Answer:
a. Clear Button Code:
txtShopping.setText(""); txtDisc.setText(""); txtNet.setText("");
bgPayment.clearSelection();
b. Calculate Button Code:
double shopping = Double.parseDouble(txtShopping.getText());
double discPercent = 0;
if(rbCash.isSelected()) {
if(shopping >= 10000) discPercent = 25;
else discPercent = 20;
} else if(rbCheque.isSelected()) {
if(shopping >= 15000) discPercent = 15;
else discPercent = 10;
} else if(rbCreditCard.isSelected()) {
if(shopping >= 10000) discPercent = 12;
else discPercent = 10;
}
double discAmount = shopping * (discPercent / 100);
double netPrice = shopping - discAmount;
txtDisc.setText("" + discAmount);
txtNet.setText("" + netPrice);
In simple words: Determine discount percentage based on payment mode and shopping amount, then calculate discount and net price.
Exam Tip: Use nested if-else statements to handle payment mode and amount range conditions.
Chapter 5
Question 1. In java, methods reside in __________. (a) Function (b) Library (c) Classes (d) Object
Answer: (c) Classes
In simple words: In Java, all methods must reside inside classes.
Exam Tip: Java is a purely object-oriented language where code exists within classes.
Question 2. The number and type of arguments of a method are known as _____________. (a) Parameter list (b) Calling (c) Definition (d) None to these.
Answer: (a) Parameter list
In simple words: The arguments accepted by a method form its parameter list.
Exam Tip: Also part of the method signature.
Question 3. The first line of method definition that tells about the type of return value along with number and type of arguments is called_____________. (a) Class (b) Object (c) Prototype (d) Datatype
Answer: (c) Prototype
In simple words: The method prototype declares its return type, name, and parameters.
Exam Tip: Also referred to as method header or signature.
Question 4. A member method having the same name as that of its class is called______method. (a) Destructor (b) Constructor (c) Object (d) Variable
Answer: (b) Constructor
In simple words: A constructor shares the exact same name as its class.
Exam Tip: Used for initializing new objects.
Question 5. A constructor method has__________return type. (a) float (b) void (c) no (d) int
Answer: (c) no
In simple words: Constructors do not have any return type, not even void.
Exam Tip: A crucial characteristic distinguishing constructors from regular methods.
Question 6. A_________constructor takes no arguments. (a) Copy constructor (b) Non-Parameterized constructor (c) Parameterized constructor
Answer: (b) Non-Parameterized constructor
In simple words: A constructor with no parameters is a non-parameterized (or default) constructor.
Question 7. A_________constructor creates objects through values passed to it. (a) Copy constructor (b) Default constructor (c) Parameterized constructor
Answer: (c) Parameterized constructor
In simple words: Parameterized constructors accept arguments to initialize object attributes with custom values.
Exam Tip: Allows customized object initialization upon creation.
Question 8. The keyword_________refers to current object. (a) void (b) goto (c) this (d) null
Answer: (c) this
In simple words: The this keyword is a reference to the current object.
Exam Tip: Commonly used to resolve naming conflicts between instance variables and parameters.
Question 9. Define a method. What is method prototype and signature?
Answer:
- Method: A block of code enclosed in a class that performs a specific task.
- Method Prototype / Signature: The declaration of a method that includes its name, return type, and parameter list.
In simple words: A method is a reusable block of code, and its signature defines its name and parameters.
Exam Tip: Method signature uniquely identifies a method within a class.
Question 10. How are following passed in Java: (i) primitive types (ii) reference types?
Answer: In Java, all variables are passed strictly by value.
(i) Primitive types: Passed by value (a copy of the actual value is passed).
(ii) Reference types: Passed by value of the reference (a copy of the memory address pointing to the object is passed).
In simple words: Java passes everything by value, including object references.
Exam Tip: A frequent conceptual trick question—Java is ALWAYS pass-by-value.
Question 11. The String objects being reference types are passed by reference but changes, if any, are not reflected back to them. Why?
Answer: String objects in Java are immutable (their internal state cannot be changed after creation). When modified inside a method, a new String object is created in memory, leaving the original reference pointing to the unchanged string.
In simple words: Strings are immutable, so modifications create new string objects rather than altering the original.
Exam Tip: Emphasize string immutability.
Question 12. At what time is the constructor method automatically invoked?
Answer: A constructor is invoked automatically when an object of the class is created using the new keyword.
In simple words: Constructors run automatically the moment an object is created.
Exam Tip: Cannot be called explicitly like normal methods.
Question 13. What are Composite and user defined data types?
Answer: Composite and user-defined data types are complex data structures created by programmers using primitive types or classes, such as arrays, classes, interfaces, and structures.
In simple words: User-defined types are custom data structures created using classes and arrays.
Exam Tip: Contrast with built-in primitive data types.
Question 14. Can you refer to a class as a composite type/ user-defined type?
Answer: Yes, a class is considered a user-defined composite data type because it bundles multiple variables and methods of different types into a single unit.
In simple words: Yes, classes group multiple variables together, acting as user-defined composite types.
Exam Tip: Classes serve as blueprints for composite objects.
Question 15. How is a constructor invoked?
Answer: A constructor is invoked automatically when an object is instantiated using the new operator.
In simple words: Constructors are invoked automatically via the new keyword during object creation.
Question 16. Which method of a class is invoked just once for an object? When?
Answer: The constructor method is invoked just once for an object, exactly at the time of object creation.
In simple words: The constructor runs exactly once when an object is created.
Exam Tip: Highlight the "once per object" rule.
Question 17. Passing the address means call by value or call by reference?
Answer: Passing the address (reference) in Java is still considered pass-by-value because a copy of the reference address is passed into the method.
In simple words: Passing object references is still pass-by-value because a copy of the address is passed.
Question 18. What’s wrong with the following constructor definition for the class PlayInfo? public void PlayInfo( int sticks) { nsticks = sticks; }
Answer: A constructor cannot have a return type (void). Removing void corrects the definition.
In simple words: The void keyword should be removed because constructors have no return type.
Exam Tip: Including void turns a constructor into a regular method with the same name as the class.
Question 19. How many values can be returned from a method?
Answer: A Java method can return at most one value directly using the return statement (though multiple values can be returned indirectly by returning an array or an object).
In simple words: A method can return only one value directly.
Exam Tip: Mention arrays or objects as workarounds to return multiple values.
Question 20. What do you understand by Class and Object?
Answer:
- Class: A blueprint or template that defines variables and methods common to all objects of a certain kind.
- Object: An instance of a class that has state (attributes), behavior (methods), and identity.
In simple words: A class is a blueprint, and an object is an instance built from that blueprint.
Exam Tip: Use the blueprint-house analogy.
Question 21. How to declare a class in Java?
Answer:
class ClassName {
// fields and methods
}
In simple words: Classes are declared using the class keyword followed by the class name and curly braces.
Exam Tip: Follow standard Java naming conventions (PascalCase).
Question 22. What is the difference between instance and static variable?
Answer:
- Instance variable: Has a separate copy for every instance (object) of the class.
- Static variable: Shared among all instances of a class, with only a single copy created in memory.
In simple words: Instance variables belong to specific objects, while static variables are shared across all objects.
Exam Tip: Mention the static keyword.
Question 23. What do you understand by constructor in OOP?
Answer: A constructor is a special member method of a class executed automatically when an object is created, primarily used to initialize instance variables.
In simple words: A constructor is a special method used to initialize new objects.
Exam Tip: Bears the exact same name as the class and has no return type.
Question 24. What are the properties of Constructor?
Answer:
1. Has the same name as the class.
2. Has no return type (not even void).
3. Invoked automatically upon object instantiation.
4. Can be overloaded.
In simple words: Constructors share the class name, have no return type, and run automatically.
Exam Tip: Memorize these core constructor rules.
Question 25. What do you understand by methods? What are the advantages of methods?
Answer:
- Method: A modular block of code that performs a specific task.
- Advantages: Code reusability, improved readability, easier maintenance, and reduction of code redundancy.
In simple words: Methods are reusable code blocks that make programs organized and modular.
Exam Tip: Highlight code reusability and modularity.
Question 26. How to define a method?
Answer:
accessModifier returnType methodName(parameters) {
// method body
}
In simple words: Methods are defined with a return type, name, parameters, and a body.
Exam Tip: Include return type and parameter list in your syntax description.
Question 27. What are the way to pass values to methods in Java?
Answer: Values are passed to methods via parameters (arguments) using Java's pass-by-value mechanism.
In simple words: Values are passed to methods as arguments through parameters.
Exam Tip: Reiterate that Java is strictly pass-by-value.
Question 28. Differentiate between constructor and method.
Answer:
- Constructor initializes an object; Method performs tasks and operations.
- Constructor has the same name as the class; Method can have any valid identifier name.
- Constructor has no return type; Method must specify a return type (or void).
- Constructor is called automatically via new; Method is called explicitly.
In simple words: Constructors initialize objects automatically, while methods are called explicitly to perform tasks.
Exam Tip: Use a comparative list for clarity.
Question 29. What is “this” keyword?
Answer: The this keyword is a reference variable that refers to the current object invoking the method or constructor.
In simple words: this refers to the current object instance.
Exam Tip: Used to distinguish instance variables from local parameters.
Question 30. How can we use a class as a composite data type?
Answer: By grouping multiple member variables of different data types inside a single class definition and creating objects of that class.
In simple words: A class bundles multiple variables together to form a custom composite data type.
Exam Tip: Mention encapsulation of attributes.
Question 31. How are parameterized constructors different from non-parameterized constructors?
Answer: Parameterized constructors accept arguments to initialize objects with custom values, whereas non-parameterized (default) constructors take no arguments and assign standard default values.
In simple words: Parameterized constructors take arguments for custom initialization; non-parameterized constructors do not.
Exam Tip: Highlight the presence or absence of parameters.
Question 32. List some of the special properties of the constructor methods.
Answer:
1. Same name as the class.
2. No return type.
3. Called automatically upon instantiation.
4. Can be overloaded.
In simple words: Constructors share the class name, have no return type, and execute automatically.
Exam Tip: Summarize core constructor rules.
Question 33. Differentiate between Instance member and static members of a class.
Answer:
- Instance members belong to a specific object instance; a separate copy exists for each object.
- Static members belong to the class as a whole; a single copy is shared across all objects.
In simple words: Instance members belong to individual objects, while static members are shared across all objects.
Exam Tip: Mention the static keyword.
Question 34. What do you mean by actual and formal parameters of a method? Explain with an example.
Answer:
- Formal parameters: Parameters declared in the method signature.
- Actual parameters (Arguments): Values passed to the method during a method call.
Example: int sum = add(5, 10); (5 and 10 are actual parameters, while int a, int b in int add(int a, int b) are formal parameters).
In simple words: Formal parameters are in the method definition; actual parameters are the values passed when calling it.
Exam Tip: Use a clear code example to demonstrate both.
Question 35. Identify the errors in the method skeletons given below: (1) float average (a, b) { } (2) float mult (int x, y) { } (3) float doer (int, float = 3.14) { }
Answer:
(1) Missing data types for parameters a and b.
(2) Missing data type for parameter y (each parameter needs an explicit data type).
(3) Java does not support default argument values like float = 3.14 in method declarations.
In simple words: Parameter data types are missing in (1) and (2), and default parameter values are invalid in (3).
Exam Tip: Every parameter in Java must have its own explicit data type.
Question 36. Given the method below write an ActionPerformed event method that includes everything necessary to call this method. int thrice (int x) { return (a * 3) ; }
Answer:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int val = Integer.parseInt(jTextField1.getText());
int result = thrice(val);
jTextField2.setText("" + result);
}
In simple words: Read input from text field, call the thrice() method, and display the result.
Exam Tip: Handle text-to-integer conversion and UI display properly.
Chapter 6
Question 1. Which keyword can protect a class in a package from accessibility by the classes outside the package?
Answer: Default (package-private) access modifier (i.e., omitting public).
In simple words: Omitting the public keyword restricts class access to within the same package.
Exam Tip: Package-private restricts visibility to the defining package.
Question 2. We would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?
Answer: protected
In simple words: The protected keyword makes members accessible in subclasses across packages.
Question 3. Which of the following keywords are used to control access to a class member? (a) default (b) abstract (c) protected (d) interface (e) public.
Answer: (a) default, (c) protected, (e) public (also private)
In simple words: Access modifiers like public, protected, and private control class member access.
Exam Tip: Abstract and interface are structural keywords, not access modifiers.
Question 4. The public members of objects are accessed through which operator. (a) arrow (b) dot (c) this (d) none of these
Answer: (b) dot (.)
In simple words: The dot operator accesses object members.
Exam Tip: Example: object.method()
Question 5. The private members are accessible only inside their _______class. (a) own (b) sub (c) super (d) none of these
Answer: (a) own
In simple words: Private members are accessible only within their own class.
Exam Tip: Strict encapsulation principle.
Question 6. Which command is used to import packages and their classes? (a) include (b) import (c) public (d) inline
Answer: (b) import
In simple words: The import command is used to bring external packages into your code.
Exam Tip: Placed at the top of a Java source file.
Question 7. Which statement is used to create a package in Java? (a) Class (b) super (c) this (d) package
Answer: (d) package
In simple words: The package statement creates a package.
Exam Tip: Must be the first statement in a Java source file (excluding comments).
Question 8. In Java, all strings are objects? (a) True (b) False (c) don’t say
Answer: (a) True
In simple words: In Java, strings are instances of the String class, making them objects.
Question 9. What do you understand by Package in Java?
Answer: A package is a grouping mechanism used to bundle related classes, interfaces, and sub-packages together, providing namespace management and access protection.
In simple words: A package is a folder structure that groups related Java classes together.
Exam Tip: Helps avoid naming conflicts and organizes code.
Question 10. Given a package named EDU.Student, how would you import a class named Test contained in this package? Write one line statement.
Answer:
import EDU.Student.Test;
In simple words: Use the import statement with the package path and class name.
Exam Tip: Ensure correct capitalization matching package names.
Question 11. What will be the output of the following code StringBuffer city = new StringBuffer(“Madras”); StringBuffer string = new StringBuffer(); string.append(new String(city)); string.insert(0,”Central”); string.out.println(string);
Answer:
Note: string.out.println() contains a syntax error (string is a StringBuffer instance, not System). Assuming corrected to System.out.println(string);:
Output:
CentralMadras
In simple words: Appends "Madras" and inserts "Central" at index 0, resulting in "CentralMadras".
Exam Tip: Watch out for typos in print statements like string.out vs System.out.
Question 12. Give the output of the following program: class MainString { public static void main( String agrs[]) { StringBuffer s = new StringBuffer(“String”); if(s.length() > 5) && (s.append(“Buffer”).equals(“x”); System.out.println(s); } }
Answer:
The code has multiple syntax errors (unbalanced parentheses in if condition and missing closing parenthesis). If corrected, compilation fails or throws syntax errors due to invalid boolean expressions involving StringBuffer appends.
In simple words: The code contains syntax errors and fails to compile.
Exam Tip: Check for syntax errors and mismatched parentheses in conditional statements.
Question 13. What is the output of the following code fragment if “abc” is passed as argument to the func()? Public static void func(string s1) { String s = s1 + “xyz”; System.out.println(“s1=” + s1); System.out.println(“s = “ +s); }
Answer:
Note: string must be capitalized as String in Java. Assuming correct capitalization:
Output:
s1=abc
s = abcxyz
In simple words: The method prints the original string s1 and the concatenated string s.
Exam Tip: Java class names are case-sensitive (String not string).
Question 14. What are the access specifiers in Java? Expalin.
Answer:
1. public: Accessible from anywhere.
2. private: Accessible only within the defining class.
3. protected: Accessible within the same package and subclasses.
4. Default (package-private): Accessible only within the same package.
In simple words: Access specifiers control where classes, methods, and variables can be accessed.
Exam Tip: Memorize the four access levels and their visibility scope.
Question 15. What do you meant by private, public, protected, package(friendly) access specifiers?
Answer:
- Private: Most restrictive; accessible only within the class.
- Public: Least restrictive; accessible globally.
- Protected: Accessible within package and subclasses.
- Package (friendly): Accessible within the same package only.
In simple words: These keywords determine visibility levels across classes and packages.
Exam Tip: Friendly is another name for default access.
Question 16. What do you understand by Library in Java?
Answer: A Java library is a collection of pre-written classes, packages, and methods (such as java.lang, java.util) provided by Java to help developers perform standard programming tasks without writing code from scratch.
In simple words: A library is a collection of pre-built code and classes provided by Java.
Exam Tip: Promotes code reuse and saves development time.
Question 17. What are the different types of access specifier supported by java?
Answer: public, private, protected, and default (package-private).
In simple words: Java supports public, private, protected, and default access specifiers.
Question 18. Which is the default package of java?
Answer: java.lang
In simple words: java.lang is automatically imported into every Java program.
Exam Tip: Contains foundational classes like String, Math, and System.
Question 19. What is friendly access of class member?
Answer: Friendly access (also known as default or package-private access) means the member is accessible by all classes residing within the same package.
In simple words: Friendly access allows members to be accessed by any class in the same package.
Exam Tip: Occurs when no explicit access modifier is written.
Question 20. How does a class enforce information hiding?
Answer: A class enforces information hiding by declaring its instance variables as private and providing public getter and setter methods to access or modify them.
In simple words: Information hiding is enforced by making variables private and using getter/setter methods.
Exam Tip: Core principle of encapsulation in OOP.
Question 21. Define an abstract class and abstract methods.
Answer:
- Abstract Class: A class declared with the abstract keyword that cannot be instantiated directly and may contain abstract methods.
- Abstract Method: A method declared without a body (abstract void display();), which must be implemented by subclasses.
In simple words: Abstract classes cannot be instantiated, and abstract methods have no body and must be overridden.
Question 22. What is an interface? What is the use of Interface.
Answer:
- Interface: A reference type in Java similar to a class that contains only constants and abstract methods.
- Use: Interfaces are used to achieve 100% abstraction and implement multiple inheritance in Java.
In simple words: An interface defines a contract of methods that implementing classes must provide.
Exam Tip: Essential for achieving multiple inheritance in Java.
Chapter 7
Question 1. What is inheritance?
Answer: Inheritance is an object-oriented programming mechanism where one class (subclass/child class) inherits the properties and methods of another class (superclass/parent class).
In simple words: Inheritance allows a child class to inherit features from a parent class.
Exam Tip: Uses the extends keyword in Java.
Question 2. What is the primary purpose of inheritance?
Answer: The primary purpose of inheritance is code reusability and establishing a hierarchical relationship between classes.
In simple words: The main goal is code reusability and creating class hierarchies.
Exam Tip: Promotes writing DRY (Don't Repeat Yourself) code.
Question 3. Name three basic concepts in Java which are used in Object oriented programming.
Answer: 1. Encapsulation
2. Inheritance
3. Polymorphism
In simple words: Three core OOP pillars are encapsulation, inheritance, and polymorphism.
Exam Tip: Can also include abstraction.
Question 4. Which constructor is called first: subclass or superclass?
Answer: The superclass constructor is always called first, followed by the subclass constructor.
In simple words: Superclass constructors execute before subclass constructors during object creation.
Exam Tip: Java automatically invokes the parent constructor using super().
Question 5. What is abstract class?
Answer: An abstract class is a restricted class that cannot be used to create objects directly and serves as a base for subclasses to inherit from.
In simple words: An abstract class acts as a template and cannot be instantiated directly.
Exam Tip: Declared using the abstract keyword.
Question 6. What is method overriding in Java?
Answer: Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its superclass, sharing the exact same method signature.
In simple words: Overriding happens when a child class redefines a method inherited from its parent class.
Exam Tip: Must have identical method name, return type, and parameters.
Question 7. What is an Interface in Java?
Answer: An interface is a blueprint of a class that contains abstract methods and constant variables, implemented by classes using the implements keyword.
In simple words: An interface is a contract specifying methods that a class must implement.
Exam Tip: Supports multiple inheritance in Java.
Question 8. What is the significance of abstract class in Java program?
Answer: Abstract classes provide a common template and shared code for a group of related subclasses while enforcing a specific method implementation structure.
In simple words: Abstract classes provide shared code and enforce structural consistency across subclasses.
Exam Tip: Useful for partial code sharing in hierarchies.
Question 9. What types of inheritance does Java have?
Answer: Java supports single inheritance (class to class), multilevel inheritance, and hierarchical inheritance. Multiple inheritance for classes is not supported directly (handled via interfaces).
In simple words: Java supports single, multilevel, and hierarchical inheritance.
Exam Tip: Remember Java does not support multiple inheritance with classes to avoid the diamond problem.
Question 10. State True and False a. A subclass inherits both member variables and member methods of superclass. b. A class created with keyword abstract can have at the most one object. c. Overloading and Overriding are similar concepts in Java. d. Java supports single inheritance only at multiple levels of inheritance. e. Interfaces are used for multiple inheritance.
Answer:
a. True
b. False (An abstract class cannot have any objects instantiated directly)
c. False (Overloading happens within the same class with different parameters; overriding happens across parent-child classes with identical signatures)
d. True (Single inheritance at multiple levels = multilevel inheritance)
e. True
In simple words: True/False analysis of core OOP inheritance principles.
Exam Tip: Review each statement carefully against core Java principles.
Question 11. Declare and explain the basic syntax of inheritance.
Answer:
class Subclass extends Superclass {
// additional fields and methods
}
Explanation: The extends keyword signals that the subclass inherits all accessible fields and methods of the superclass.
In simple words: Use the extends keyword to inherit a parent class into a child class.
Exam Tip: Always place extends between the child class name and parent class name.
Question 12. How does inheritance support software reuse?
Answer: Inheritance allows new classes to adopt existing code, fields, and methods from parent classes without rewriting them, reducing redundancy and saving development effort.
In simple words: Inheritance lets new classes reuse existing parent code without duplication.
Exam Tip: Highlights the core DRY (Don't Repeat Yourself) principle.
Question 13. Differentiate between method overloading and method overriding.
Answer:
- Overloading occurs within the same class with different parameter lists.
- Overriding occurs across parent and child classes with identical signatures.
- Overloading is compile-time polymorphism; overriding is run-time polymorphism.
In simple words: Overloading changes method parameters in the same class; overriding redefines parent methods in child classes.
Exam Tip: A classic exam question—memorize the compile-time vs run-time distinction.
Question 14. Write a program to find the area of triangle and rectangle through abstract class and abstract class method... a) Write the code to declare an abstract class Figure... b) Write the code to declare two classes called Rectangle and Triangle... c) Write the code for Calculate button... d) Write the code for cmdExit to exit the application.
Answer:
a. Abstract Class Declaration:
abstract class Figure {
double dim1, dim2;
Figure(double a, double b) { dim1 = a; dim2 = b; }
abstract double area();
}
b. Rectangle and Triangle Classes:
class Rectangle extends Figure {
Rectangle(double a, double b) { super(a, b); }
double area() { return dim1 * dim2; }
}
class Triangle extends Figure {
Triangle(double a, double b) { super(a, b); }
double area() { return 0.5 * dim1 * dim2; }
}
c. Calculate Button Code:
double l = Double.parseDouble(txtL.getText());
double b = Double.parseDouble(txtB.getText());
Figure f;
f = new Rectangle(l, b);
txtAreaRect.setText("" + f.area());
f = new Triangle(l, b);
txtAreaTri.setText("" + f.area());
d. Exit Code: System.exit(0);
In simple words: Use an abstract Figure class with an abstract area() method, implemented by Rectangle and Triangle subclasses.
Exam Tip: Subclasses must implement all abstract methods of the parent class.
Question 15. Write a program to demonstrate constant in an interface to find the area of circle... a) Write the code to declare an interface for constant with implementation class method area(). b) Write the code for FindArea button... c) Write the code for cmdExit to exit the application.
Answer:
a. Interface and Implementation:
interface valuePie { double PIE = 3.14; }
class Circle implements valuePie {
double radius;
Circle(double r) { radius = r; }
double area() { return PIE * radius * radius; }
}
b. FindArea Button Code:
double r = Double.parseDouble(txtR.getText());
Circle c = new Circle(r);
txtArea.setText("" + c.area());
c. Exit Code: System.exit(0);
In simple words: Declare PIE constant in an interface, implement it in a Circle class, and calculate area on button click.
Exam Tip: Interface variables are automatically public static final.
Question 17. What members of a class out of private, protected and public are inheritable?
Answer: Public and protected members are inheritable. Private members are not directly inheritable.
In simple words: Public and protected members are inherited by subclasses, while private members are not.
Exam Tip: Private members remain restricted to their defining class.
Question 18. When do we declare a method or class ‘final’?
Answer: We declare a class final to prevent it from being inherited, and a method final to prevent it from being overridden by subclasses.
In simple words: The final keyword prevents classes from being extended and methods from being overridden.
Exam Tip: final stops inheritance and overriding.
Question 18. What is an abstract class?
Answer: An abstract class is a class declared with the abstract keyword that cannot be instantiated and serves as a template for subclasses.
In simple words: An abstract class acts as a base template and cannot be instantiated directly.
Exam Tip: Must be subclassed to use its methods.
Question 19. When do we declare a method or class abstract?
Answer: We declare a class or method abstract when we want to define a common interface and behavior for subclasses while forcing subclasses to provide their own specific implementations.
In simple words: Use abstract when defining templates that subclasses must implement.
Exam Tip: Enforces mandatory method implementation in subclasses.
Question 20. What is the difference between an abstract class and an interface?
Answer:
- Abstract class can have both abstract and non-abstract methods, constructors, and instance variables; Interface can only have constants and abstract methods.
- A class can extend only one abstract class, but it can implement multiple interfaces.
In simple words: Abstract classes can have method bodies and constructors, whereas interfaces only define method signatures and constants.
Exam Tip: Single inheritance for classes vs. multiple inheritance for interfaces.
Chapter 8
Question 1. What is dialog in Java?
Answer: A dialog is a secondary popup window used to display messages to the user or prompt the user for input or confirmation.
In simple words: A dialog is a popup window used for alerts, messages, or user prompts.
Exam Tip: Dialog boxes can be modal (blocking input to parent) or non-modal.
Question 2. Write the import statement required for using JOptionPane class.
Answer:
import javax.swing.JOptionPane;
In simple words: Import javax.swing.JOptionPane to use popup dialog boxes.
Exam Tip: Essential for standard dialog methods like showMessageDialog.
Question 3. What is showConfirmDialog ( ) method of JOptionPane class do ?
Answer: The showConfirmDialog() method displays a dialog box asking a question with options like Yes, No, or Cancel, and returns an integer representing the user's choice.
In simple words: showConfirmDialog() prompts the user with Yes/No/Cancel options.
Exam Tip: Returns integer constants like JOptionPane.YES_OPTION.
Question 4. What is showInputDialog ( ) method of JOptionPane class do ?
Answer: The showInputDialog() method displays a popup dialog prompting the user to enter text or input, and returns the entered string.
In simple words: showInputDialog() prompts the user to type and input text.
Exam Tip: Useful for quick user input without designing custom text field forms.
Question 5. What is the difference between a dialog created with JDialog and a dialog created with JOptionPane?
Answer:
- JOptionPane provides pre-built standard dialog boxes (messages, confirmations, inputs) with minimal code.
- JDialog is a general-purpose custom dialog window that allows developers to design custom UI layouts with buttons and components.
In simple words: JOptionPane offers ready-made popup dialogs, while JDialog lets you build custom popup windows.
Exam Tip: Use JOptionPane for standard alerts and JDialog for custom forms.
Question 6. What are the various type of dialog options supported by JOptionPane?
Answer:
1. Message Dialog (showMessageDialog)
2. Confirm Dialog (showConfirmDialog)
3. Input Dialog (showInputDialog)
4. Option Dialog (showOptionDialog)
In simple words: JOptionPane supports message, confirm, input, and custom option dialogs.
Exam Tip: Memorize the four primary JOptionPane methods.
Question 7. Name four methods associated with JOption dialog.
Answer:
1. showMessageDialog()
2. showConfirmDialog()
3. showInputDialog()
4. showOptionDialog()
In simple words: Four main methods are showMessageDialog, showConfirmDialog, showInputDialog, and showOptionDialog.
Exam Tip: Always prefix with JOptionPane.
Question 8. Explain the various possible value for Option type property of JOptionPane dialog.
Answer:
- DEFAULT_OPTION
- YES_NO_OPTION
- YES_NO_CANCEL_OPTION
- OK_CANCEL_OPTION
In simple words: Option type properties determine which buttons appear in confirmation dialogs.
Exam Tip: Controls button sets in confirmation dialogs.
Chapter 9
Question 1. What is the importance of java.sql.*; in java jdbc connection?
Answer: The java.sql.* package provides all necessary classes and interfaces (such as Connection, Statement, ResultSet, and DriverManager) required for establishing database connectivity and executing SQL queries in Java.
In simple words: java.sql.* contains all classes needed to connect to databases and run SQL queries.
Exam Tip: Essential import statement for JDBC database programming.
Question 2. What is DriverManager?
Answer: DriverManager is a JDBC management class that loads database drivers and establishes a connection between a Java application and a database.
In simple words: DriverManager manages database drivers and establishes database connections.
Exam Tip: Used via DriverManager.getConnection().
Question 3. What is the purpose of connection.close() method?
Answer: The connection.close() method terminates the active database connection and releases database and network resources allocated to it.
In simple words: connection.close() closes the database connection and frees system resources.
Exam Tip: Always close database connections to prevent memory and connection leaks.
Question 4. Name the four components of JDBC.
Answer:
1. JDBC API
2. JDBC Driver Manager
3. JDBC Test Suite
4. JDBC Drivers (e.g., JDBC-ODBC Bridge, Thin Driver)
In simple words: Four components are JDBC API, Driver Manager, Test Suite, and JDBC Drivers.
Exam Tip: Standard architecture components of JDBC.
Question 5. What are the steps involved in establishing a connection?
Answer:
1. Register/Load the JDBC driver (Class.forName()).
2. Establish the connection using DriverManager.getConnection() with URL, username, and password.
3. Create a statement object.
4. Execute queries and process results.
5. Close the connection.
In simple words: Load driver, establish connection, create statement, execute query, and close connection.
Exam Tip: Memorize this standard JDBC connection sequence.
Question 6. What is ResultSet?
Answer: A ResultSet is a Java object that represents a database query result set, holding table data returned from executing a SQL SELECT statement.
In simple words: A ResultSet holds the table data returned by a database query.
Exam Tip: Navigated using cursor methods like rs.next().
Question 7. What type of parameter that used in executeQuery( ) method?
Answer: It accepts a SQL query string (typically a SELECT statement) as a parameter.
In simple words: executeQuery() takes a SQL select query string as its parameter.
Exam Tip: Returns a ResultSet object.
Question 8. What is Connection? What is its role?
Answer: Connection is an interface in Java that represents a session between a Java application and a database. Its role is to manage database sessions, execute SQL statements, and manage transactions.
In simple words: A Connection object represents an active communication session with a database.
Exam Tip: Used to create statements and manage transactions.
Question 9. What all JDBC classes/objects are used in a database connectivity application?
Answer:
1. Connection
2. Statement (or PreparedStatement)
3. ResultSet
4. DriverManager
In simple words: Key JDBC objects include Connection, Statement, ResultSet, and DriverManager.
Exam Tip: Essential objects required for database operations in Java.
Question 10. What is JDBC? What is its basic functionality?
Answer: JDBC (Java Database Connectivity) is a Java API that defines how a client may connect and access a database. Its basic functionality is to enable Java applications to interact with relational databases to execute SQL queries.
In simple words: JDBC is an API that allows Java programs to connect and interact with databases.
Question 11. What is the JDBC-ODBC Bridge?
Answer: The JDBC-ODBC Bridge is a JDBC driver that uses ODBC drivers to connect to a database, translating JDBC calls into ODBC method calls.
In simple words: The JDBC-ODBC bridge connects Java programs to databases using ODBC drivers.
Exam Tip: Deprecated in modern Java versions in favor of native drivers.
Question 12. Explain the purpose of DriverManager.
Answer: DriverManager tracks database drivers and establishes connections between Java applications and database management systems based on connection URLs.
In simple words: DriverManager manages database drivers and creates active database connections.
Exam Tip: Central class for managing JDBC drivers.
Question 13. Name the methods which are useful for executing SQL statements.
Answer:
1. executeQuery() (for SELECT queries)
2. executeUpdate() (for INSERT, UPDATE, DELETE queries)
3. execute() (for general SQL statements)
In simple words: Methods for executing SQL are executeQuery, executeUpdate, and execute.
Exam Tip: Know the difference between executeQuery (returns ResultSet) and executeUpdate (returns update count).
Question 14. Differentiate between JDBC and ODBC?
Answer:
- JDBC is a Java-specific database access API designed for platform independence.
- ODBC is a language-independent C-based database API that relies heavily on platform-dependent drivers.
In simple words: JDBC is designed specifically for Java, while ODBC is a language-independent database API.
Exam Tip: Highlight Java orientation vs language independence.
Question 15. What are the main tasks of JDBC?
Answer:
1. Establishing a connection with a database.
2. Sending SQL statements to the database.
3. Processing and retrieving query results.
In simple words: Main tasks are connecting to databases, sending SQL statements, and processing results.
Exam Tip: Summarizes the core lifecycle of database connectivity.
Question 16. What are the various steps involved in establishing a JDBC connection?
Answer:
1. Register JDBC driver.
2. Open database connection.
3. Create statement.
4. Execute query.
5. Process results and close connection.
In simple words: Register driver, open connection, create statement, execute query, and close.
Exam Tip: Standard 5-step JDBC procedure.
Question 17. Name the method used to trigger an update query using JDBC.
Answer: executeUpdate()
In simple words: executeUpdate() triggers SQL queries like INSERT, UPDATE, and DELETE.
Exam Tip: Returns an integer representing the number of rows affected.
Chapter 10
Question 1. Identify the web browser software from the following options: (a) Apache Web Server (b) MS Word (c) HTML (d) Mozilla Firefox
Answer: (d) Mozilla Firefox
In simple words: Mozilla Firefox is a web browser.
Exam Tip: Apache is a web server; MS Word is a word processor.
Question 2. A___________ document is created by web server whenever a browser requests the documents. (a) active (b) static (c) dynamic (d) none of the above
Answer: (c) dynamic
In simple words: Dynamic documents are generated on-the-fly by the web server upon request.
Exam Tip: Differentiate static (pre-existing files) from dynamic (generated on request).
Question 3. A___________ document is a fixed content document that is created by web server whenever a browser requests the documents. (a) active (b) static (c) dynamic (d) none of the above
Answer: (b) static
In simple words: Static documents have fixed content stored on the server.
Exam Tip: Stored directly on the server without real-time modification.
Question 4. Identify the web server software from the following options: (a) Apache (b) MS Word (c) HTML (d) Mozilla Firefox
Answer: (a) Apache
In simple words: Apache is a web server software.
Exam Tip: Serves web pages to browsers upon request.
Question 5. The address of a resource on the net is known as: (a) ISP (b) HTTP (c) URL (d) WWW
Answer: (c) URL
In simple words: A URL is the address of any resource on the internet.
Exam Tip: Stands for Uniform Resource Locator.
Question 6. A program that serves requested HTML files and pages. (a) Web Address (b) Web Page (c) Web Server (d) None of these
Answer: (c) Web Server
In simple words: A web server serves requested HTML pages to clients.
Exam Tip: Software that handles HTTP requests from web browsers.
Question 7. What is Uniform Resource Locator?
Answer: Uniform Resource Locator (URL) is the address of a unique resource on the World Wide Web, specifying its location and the protocol used to access it.
In simple words: A URL is the complete web address of a resource on the internet.
Exam Tip: Example: http://www.example.com/index.html
Question 8. What is Web Server?
Answer: A Web Server is a computer system or software program that stores, processes, and delivers web pages to users over the internet via HTTP/HTTPS.
In simple words: A web server stores and delivers web pages to users' browsers.
Exam Tip: Examples include Apache, Nginx, and IIS.
Question 9. What is Web Browser?
Answer: A Web Browser is a software application used to access, retrieve, and view web pages and resources on the World Wide Web.
In simple words: A web browser is software used to view websites on the internet.
Exam Tip: Examples include Chrome, Firefox, and Edge.
Question 11. In the URL, http://www.mycorp.com/pr/master.htm, what is the http component?
Answer: It is the protocol used to access the resource.
In simple words: http is the communication protocol.
Exam Tip: Stands for Hypertext Transfer Protocol.
Question 12. In the URL, http://www.mycorp.com/pr/master.htm, what is the www.mycorp.com component?
Answer: It is the domain name (host server name) of the website.
In simple words: www.mycorp.com is the domain name of the web server.
Exam Tip: Identifies the server hosting the resource.
Question 13. In the URL, http://www.mycorp.com/pr/master.htm, what is the /pr/master.htm component?
Answer: It is the absolute path and filename of the specific resource on the server.
In simple words: This component specifies the file path and name on the server.
Exam Tip: Points to the exact file location.
Question 14. What do you mean by Web Browser, and Web Server?
Answer:
- Web Browser: Client application that requests and renders web pages.
- Web Server: Server software that processes requests and serves web pages.
In simple words: Browsers request web pages, and servers deliver them.
Exam Tip: Classic client-server architecture roles.
Question 15. Which protocol is used to upload/ transfer the file from host to server Internet?
Answer: FTP (File Transfer Protocol)
In simple words: FTP is used for uploading and transferring files over the internet.
Exam Tip: Specialized protocol for file transfer.
Question 16. What is WWW? How does it function?
Answer: World Wide Web (WWW) is a global system of interconnected hypertext documents accessed via the internet. It functions using client-server architecture, where web browsers (clients) request pages from web servers using HTTP.
In simple words: WWW is a collection of linked web pages accessed through browsers and servers using HTTP.
Exam Tip: Invented by Tim Berners-Lee in 1989.
Question 16 (Alt). A web browser & web server are an application of client/server computing concept. Comment on this statement?
Answer: The statement is entirely accurate. The web browser acts as the client that initiates requests for web pages, while the web server acts as the remote host that processes those requests and returns the requested resources.
In simple words: Browsers act as clients requesting data, and servers act as hosts delivering data.
Exam Tip: Excellent example of distributed client-server architecture.
Question 17. What is URL ? What are its components?
Answer: URL (Uniform Resource Locator) is the web address of a resource. Its components are:
1. Protocol (e.g., http:// or https://)
2. Domain Name / Host (e.g., www.example.com)
3. Port number (optional, e.g., :80)
4. File Path / Resource location (e.g., /folder/page.html)
In simple words: A URL consists of a protocol, domain name, optional port, and file path.
Exam Tip: List the standard components of a URL clearly.
Question 18. What is CGI? How it works in Dynamic web Page service?
Answer: CGI (Common Gateway Interface) is a standard protocol that enables web servers to execute external programs (scripts) to generate dynamic web pages in response to user requests.
In simple words: CGI is a standard protocol that lets web servers run scripts to generate dynamic web pages.
Exam Tip: Fundamental technology behind early dynamic web content.
Question 19. Differentiate between Static and Dynamic Web Service?
Answer:
- Static Web Service delivers pre-built HTML files exactly as they are stored on the server without modification.
- Dynamic Web Service generates web pages in real-time using server-side scripts and database interactions based on user requests.
In simple words: Static pages show fixed content, while dynamic pages are generated on-the-fly for each user.
Exam Tip: Highlight real-time generation vs. pre-rendered files.
Please click the below link to access CBSE Class 12 Informatics Practices Worksheet All Chapters
Free study material for Informatics Practices
All topics Printable Assignments & Solutions for Class 12 Informatics Practices
Class 12 Informatics Practices All topics Printable Assignments
Access structured practice assignments for All topics designed in alignment with the latest CBSE curriculum for Class 12 Informatics Practices. These printable sets cover objective and descriptive problem types to support thorough revision.
Key Advantages of Solving All topics Assignments
- Curriculum Standards: Assignments match modern CBSE sample formats to ensure relevant preparation.
- Thorough Revision: Detailed problem sets reinforce core concepts and eliminate conceptual weak spots.
- Execution Speed: Timed practice with assignment sets sharpens overall response timing.
Effective Strategy for Class 12 Informatics Practices Assignments
- Concept Foundation: Review the NCERT book for Class 12 Informatics Practices thoroughly before diving into assignment tasks.
- Self-Evaluation: Solve exercises independently before inspecting professional answer guides.
- Progress Monitoring: Note down complex formulas or concepts, clearing them up using available online practice aids.
FAQs
You can download free PDF assignments for Class 12 Informatics Practices All topics from StudiesToday.com. These practice sheets have been updated for the 2026-27 session covering all concepts from latest NCERT textbook.
Yes, our teachers have given solutions for all questions in the Class 12 Informatics Practices All topics assignments. This will help you to understand step-by-step methodology to get full marks in school tests and exams.
Yes. These assignments are designed as per the latest CBSE syllabus for 2026. We have included huge variety of question formats such as MCQs, Case-study based questions and important diagram-based problems found in All topics.
Practicing topicw wise assignments will help Class 12 students understand every sub-topic of All topics. Daily practice will improve speed, accuracy and answering competency-based questions.
Yes, all printable assignments for Class 12 Informatics Practices All topics are available for free download in mobile-friendly PDF format.