- Data Types and Wrapper Class: In Java, a data type is a classification of data that specifies the type of value that a variable can hold. Java supports two types of data types - primitive and reference types. Primitive data types are basic data types that are predefined in Java, while reference types are created by the programmer.
Wrapper classes are classes that provide a way to use primitive data types as objects. The wrapper classes provide methods to convert primitive data types into objects and vice versa. The wrapper classes are useful when using Java collections or other Java APIs that require objects rather than primitive data types.
The primitive data types supported in Java are:
- byte: 8-bit signed integer
- short: 16-bit signed integer
- int: 32-bit signed integer
- long: 64-bit signed integer
- float: 32-bit floating-point number
- double: 64-bit floating-point number
- char: 16-bit Unicode character
- boolean: true/false value
- Java Program to Implement Button and Label:
javaimport java.awt.*;
import java.awt.event.*;
public class ButtonLabelExample extends Frame implements ActionListener {
Label label;
Button button;
public ButtonLabelExample() {
label = new Label();
label.setBounds(100, 50, 200, 20);
button = new Button("Click");
button.setBounds(100, 100, 80, 30);
button.addActionListener(this);
add(button);
add(label);
setSize(300, 300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
label.setText("Button Clicked");
}
public static void main(String[] args) {
new ButtonLabelExample();
}
}
- String in Java: In Java, a String is a sequence of characters. It is a reference data type that is immutable, meaning that once a String object is created, its value cannot be changed. There are two ways to create a String object - using a String literal or using the new keyword.
Using a String literal:
arduinoString str1 = "Hello World";
Using the new keyword:
javascriptString str2 = new String("Hello World");
- Event Handling: Event handling is the process of responding to user actions, such as button clicks or key presses, in a program. In Java, event handling is achieved through event listeners.
For example, to handle a button click event, you can create an ActionListener and add it to the button:
typescriptbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// code to handle button click event
}
});
- Short Notes on: (a) Listeners: Listeners are objects that are registered to receive events and handle them. They are used in event-driven programming to handle user actions, such as button clicks or key presses.
(b) Inheritance: Inheritance is a mechanism in object-oriented programming that allows a class to inherit properties and methods from another class. The class that inherits is called the subclass, and the class that is inherited from is called the superclass.
(c) Thread: A thread is a separate path of execution in a program. In Java, threads are used to perform tasks concurrently, which can improve the performance and responsiveness of a program.
- HTML: HTML (Hypertext Markup Language) is a markup language used to create web pages. It is used to structure content and define the layout and appearance of web pages. HTML is composed of tags that are used to define elements, such as headings, paragraphs, and images.
The structure of an HTML document consists of three parts:
- The document type declaration (DTD), which defines the type of document and
specifies the version of HTML being used.
- The HTML element, which contains the entire web page.
- The head element, which contains information about the document, such as the title and any links to external resources.
- The body element, which contains the content of the web page.
- Socket: A socket is an endpoint of a two-way communication link between two programs running on a network. In Java, sockets are used to communicate between client and server programs.
A TCP/IP-based server socket is a socket that waits for incoming client connections. When a client connects to the server socket, a new socket is created for the communication between the client and server.
- Servlet Lifecycle: The servlet lifecycle is the sequence of events that occur during the lifetime of a servlet. The lifecycle consists of the following stages:
- Loading and instantiation
- Initialization
- Servicing the request
- Destroying the servlet
- JSP: JSP (JavaServer Pages) is a technology used to create dynamic web pages. JSP pages are HTML pages with embedded Java code that is executed on the server-side to generate dynamic content.
The advantages of JSP are:
- Separation of presentation and logic
- Reusability of code
- Easy maintenance
- Better performance compared to CGI scripts
To call stored procedures from JSP, you can use the JSP standard tag library (JSTL) or JDBC. For example, using JSTL:
sql<sql:query dataSource="jdbc/mydb">
{call myproc(?, ?)}
<sql:param value="value1"/>
<sql:param value="value2"/>
</sql:query>