Information Technology · Class 12 Commerce
Ch 2Programming — Class 12 Information Technology, concept-first.
In the first year you learned to write simple Java programs — declaring variables, using operators, taking decisions with if/switch, repeating work with loops, and organising code into methods. This chapter builds directly on that foundation, so we begin with a short review to fix the vocabulary we will keep using.
Key concepts
Hover a concept to preview it and jump to its most relevant Q&A.
Access Specifiers and Encapsulation
Access specifiers control who may use a class member: public (anywhere), private (same class only), protected (class, package and subclasses) and default (same package).
Most relevant Q&A
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
Programming Fundamentals — A Quick Review
In the first year you learned to write simple Java programs — declaring variables, using operators, taking decisions with if/switch, repeating work with loops, and organising code into methods.
Access Specifiers and Encapsulation
When a class has fields and methods, we usually do not want every other part of the program to reach in and change them freely.
Inheritance
Inheritance lets one class reuse the fields and methods of another class instead of rewriting them. The class we inherit from is the parent (also called superclass or base class); the class that inher…
Common Library Classes — String and Math
Java ships with a large collection of ready-made classes called the standard library. Instead of writing common operations yourself, you call methods that are already written and tested.
Connecting Java to a MySQL Database — ODBC and JDBC
Most real programs must store and fetch data from a database. In this course the database is MySQL (a relational database that keeps data in tables).
Building a Web Page with HTML — Basic Tags
A web page is a document you view in a browser. Web pages are written in HTML — HyperText Markup Language.
HTML Tables, Lists and Forms
Beyond plain text, HTML gives us structured elements to organise information: tables for rows and columns, lists for items, and forms to collect input from the visitor.
Static vs Dynamic Pages, DHTML and an Introduction to XML
Not all web pages behave the same way. A key distinction is between static and dynamic pages, and alongside plain HTML you will meet two related terms — DHTML and XML.
Exercises
+−Show 14 questionsHide questions14 questions
- Q1What are access specifiers in Java? Name the four levels and state, for each, from where a member can be accessed.Free
- Q2What is encapsulation? Explain how making a field `private` with public getter and setter methods protects an object's data, with a short ex…Free
- Q3Define inheritance. Write a Java program in which a class `Student` inherits from a class `Person`, reusing a field and a method of `Person`…Free
- Q4What is method overriding? Explain the role of the `super` keyword, giving a short example.Preview
- Q5Which types of inheritance does Java support for classes, and which does it not? Explain why the unsupported one is disallowed.Preview
- Q6Predict the output of the following code and explain each result: ```java String s = "Commerce"; System.out.println(s.length()); System.out.…Preview
- Q7Why should `equals()` be used instead of `==` to compare two strings? Illustrate with a short example.Preview
- Q8Using the `Math` class, write Java statements to compute (i) the square root of 225, (ii) 2 raised to the power 10, and (iii) the larger of…Preview
- Q9Distinguish between ODBC and JDBC. Why is JDBC generally preferred for a Java program?Preview
- Q10List, in order, the five steps a Java program follows to connect to and read from a MySQL database using JDBC, naming the key object involve…Preview
- Q11Write the HTML code for a complete web page whose browser-tab title is "My Page" and which displays a main heading "Welcome" and a paragraph…Preview
- Q12Write HTML to display a table with the heading row "Roll" and "Name" and one data row "1" and "Rina". Also state which tags create (i) a row…Preview
- Q13Differentiate between a static web page and a dynamic web page, with one example of each.Preview
- Q14What is XML, and how does it differ from HTML? Give a small XML example that stores one student's roll, name and marks.Preview