Unit – 1
Introduction
Q1) Write the history of web?
A1) History of Web
● Sir Tim Berners-Lee founded the World Wide Web in 1989 at CERN in Geneva.
● The first text-only browsers were installed in 1990, allowing CERN scientists to access hypertext files and other information. HTML was built on a subset of the generalized markup language norm (SGML). A new protocol called HTTP was created to move HTML documents to remote sites (Hyper Text Transfer Protocol).
● In the fall of 1991, conference goers all over the world began to learn about the pledge, but no sparks flew.
● There were only around 50 websites on the internet in 1993. The National Center for Super Computing application created a browser that enabled users to take advantage of the web's graphical capabilities (NCSA). The browser was given the name Mosaic by NCSA.
Q2) Write the history of internet?
A2) History of Internet
When man first walked on the moon in 1969, the US defense department established the Advanced Research Project Agency (ARPA) to conduct further research. To exchange and share their data, they created a network of four computers.
ARPANET (Advanced Research Project Agency Network) was the name of this network. Many universities were later permitted to enter this network and exchange data. This was the start of 'computer networking,' which grew in size day by day and eventually gave birth to INTERNET, the technology that has changed our lives.
Engineers, scientists, and computer experts used the Internet for research purposes in the past. The network was gradually opened up to private agencies and the general public. People began to use it to transfer messages and files back and forth between computers.
The most fascinating aspect of the Internet is that it is not regulated or maintained by a single entity. The ARPANET expanded around the globe in 1972, with 23 nodes in various countries, and thus became known as the Internet.
Many universities were later permitted to enter this network and exchange data. The Internet is unique in that it is not regulated or maintained by a single entity. It cannot be monopolized or hijacked.
Q3) Explain Protocols Governing Web?
A3) Protocols Governing Web
A protocol is a collection of rules that programs use to communicate with one another.
OR
A protocol is the interface that allows various programs to communicate with one another.
Classifications
● HTML
● TCP/IP
● FTP
● TELNET
HTML: The most popular protocol for distributing information on the internet is HTTP.
The initial version of HTTP 0.9 does not allow for content typing and does not provide provisions for providing meta-data.
Content typing - To figure out what kind of data is being sent.
Meta information - The client's compute is identified by supplementary data, such as environment variables.
TCP/IP: It is a collection of rules that an application may use to bundle its data for transmission through a network of networks.
FTP: It's used to send files through networks.
E-MAIL: It's a way of sending and receiving digital messages over the Internet or other computer networks.
Telnet: Telnet allows you to remotely log into another device and access the files and folders.
Q4) How to Writing Web Projects?
A4) Writing Web Projects
A. Write a project mission statement: Make a mission statement that is unique to what you intend to accomplish.
B. Identify Objectives
Objectives:
I. Specific
II. Measurable
III. Attainable
IV. Realistic
V. Time limited
C. Identify your target user: The users that you choose to visit the site will decide the subject of the website.
This is entirely dependent on.
I. Market research
II. Focus group
III. Understanding intranet audiences
D. Determine the scope: With the help of supporting documentation and the client's approval.
E. Budget:
i. Assumption for budgets.
ii. Budget categories.
iii. Determine hidden costs and tools
F. Planning Issues:
i. Discuss the client's existing information system.
ii. Project team and developing infrastructure.
iii.Where the website will place.
Q5) Explain Connecting to Internet?
A5) Connecting to Internet
There are various ways to link laptops, desktop computers, cell phones, and tablets to the Internet in today's world. It's critical to consider the differences between each link when deciding which form of Internet connection is best for us.
A personal electronic device may attach to the internet in a variety of ways. They're all different in terms of hardware and link speeds. To keep up with technological advancements, faster internet connections are needed. I figured it would be fun to put together a list of the various types of internet connections available for home and personal use, along with their average speeds.
The following are some of the most commonly used Internet connections.
2. Cable connection: Cable runs over cable TV lines and offers an internet connection through a cable modem. There are different speeds depending on whether you are uploading or downloading data. You will get quicker connectivity because coax cable has far more bandwidth than dial-up or DSL telephone lines. Speeds on cable range from 512K to 20 Mbps.
3. Leased connection: A leased link is a permanent telephone connection set up by a telecommunications common carrier between two locations. Leased lines are typically used by companies to link offices that are geographically separated.
A leased line, unlike a regular dial-up link, is still active. The link fee is set at a monthly rate. The gap between end points and the circuit's speed are the two most important factors that influence the monthly charge. The carrier can guarantee a certain degree of service since the link does not hold someone else's communications.
4. DSL connection: Digital Subscriber Line (DSL) is the abbreviation for Digital Subscriber Line. It is a link to the internet that is still “on.” Since two lines are used, your phone will not be tethered while your device is attached. To bind, you don't even need to dial a phone number. DSL uses a router to transport data, with link speeds ranging from 128K to 8 Mbps depending on the service.
Q6) Describe Internet services?
A6) Internet services
We can use internet services to access a vast amount of information such as text, graphics, sound, and apps. The diagram below depicts the four different types of Internet Services.
Fig 1: internet service
Communication services
There are a variety of communication services available that enable individuals or groups to share information.
Below provides a quick overview of these facilities.
● Electronic mail - It's a kind of electronic message that's sent over the internet.
● Telnet - It's used to connect to a remote device that's connected to the internet.
● Newsgroup - Provides a platform for people to talk about shared interests.
● Internet Relay Chat (IRC) - Allows people to connect in real time from all over the world.
● Mailing Lists - Used to bring together a community of internet users to exchange information via email.
● Internet Telephony - Allows internet users to speak to any PC configured to take calls over the internet.
● Instant Messaging - Real-time chat between individuals and groups of people is accessible. For example, Yahoo Messenger and MSN Messenger.
Information services
There are a number of information retrieval services that provide quick access to information on the internet.
Below provides a quick overview of these facilities.
● File Transfer Protocol (FTP) - Allow users to send and receive files.
● Archie - It is a continuously maintained directory of public FTP sites and their contents. It makes it easier to find a file by its name.
● Gopher - On remote locations, it's used to scan for, retrieve, and view documents.
● Very Easy Rodent Oriented Netwide Index to Computer Achieved (VERONICA) - The VERONICA resource is a gopher-based resource. It gives users access to information stored on Gopher's servers.
Web services
Web services enable information to be exchanged between web-based applications.
Web services enable applications to easily communicate with one another.
The web services are offered using the concept of Utility Computing.
World wide web
W3 is another name for WWW. It allows users to view documents stored on several servers across the internet. Text, graphics, audio, video, and hyperlinks can all be found in these documents. Users can navigate between documents using the hyperlinks.
Q7) What do you mean by client-server computing?
A7) Client-Server Computing
In client-server computing, a client requests a resource, which the server fulfills. Although a client is only in touch with one server, a server may support several clients at the same time. Both the client and the server typically communicate over a computer network, but they may also share a single device.
The client-server system is depicted in the diagram below.
Fig 2: client - server computing
Characteristics of client-server computing
The following are the most important aspects of client-server computing:
● A request and response framework are used in client-server computing. The client makes a request to the server, which the server fulfills by providing the requested information.
● The client and server can use the same communication protocol to make it easier for them to communicate with one another. At the application layer, all communication protocols are open.
● A server can only handle a certain number of client requests at any given time. As a result, it responds to requests using a priority-based system.
● By flooding a server with false requests, denial of service attacks make it difficult for it to respond to legitimate client requests.
● A web server is an example of a client-server operating system. It sends the requested web pages back to the clients.
Advantages of client-server computing
The following are some of the benefits of client-server computing:
● All of the required information is stored on a single server. As a result, it's simple to secure data and provide authorization and authentication.
● It is not necessary for the server to be physically close to the clients. Nonetheless, the data can be accessed quickly.
● Since all nodes in the client server model are autonomous and only request data from the server, it is simple to substitute, update, or move them.
● While all nodes, such as clients and servers, are not built on the same platform, they can easily facilitate data transfer.
Disadvantages of client-server computing
The following are some of the drawbacks of client-server computing:
● If all of the clients request data from the server at the same time, the server can become overloaded. The network can become congested as a result of this.
● If the server goes down for whatever reason, none of the clients' requests will be fulfilled. This causes the client-server network to crash.
● Setting up and maintaining a client-server model is very expensive.
Q8) Define core java?
A8) Java
Java is a website as well as a programming language. Java is a high-level programming language that is also robust, object-oriented, and stable.
Java was created in 1995 by Sun Microsystems (which is now a subsidiary of Oracle). The founder of Java, James Gosling, is known as the "Father of Java." It was known as Oak before Java. Since Oak was already a registered company, James Gosling and his team renamed it Java.
Java is an object-oriented programming language that is used to create web and desktop applications. It is based on classes. It is the most widely used programming language and the preferred language for Android development.
Q9) Describe operators and data types in java?
A9) Operators
Java has a large number of operators for manipulating variables. Many of the Java operators can be divided into the following categories.
● Arithmetic Operators
● Relational Operators
● Bitwise Operators
● Logical Operators
● Assignment Operators
Arithmetic Operator
In the same way as algebraic operators are used in mathematical expressions, arithmetic operators are used in mathematical expressions. The arithmetic operators are mentioned in the table below.
Assume integer variable A has a value of 10 and variable B has a value of 20
Sr. No | Operator | Description | Example |
1 | + | Used to add two operands | Result of A+B is 30 |
2 | - | Used to subtract two operands | Result of A-B is -10 |
3 | * | Used to multiply two operands | Result of A*B is 200 |
4 | / | Used to divide two operands | Result of A/B is 2 |
5 | % | Find reminder of the division of two operands | Result of A%B is 0 |
Relational Operator
The Java language supports the following relational operators.
Assume variable A contains value 10 and variable contains value 5.
Sr. No | Operator | Description | Example |
1 | < | This is less than operator which is used to check whether the value of left operand is less than the value of right operand or not | Result of A<B is false.
|
2 | > | This is greater than the operator which is used to check whether the value of the left operand is greater than the value of the right operand or not. | Result of A>B is true. |
3 | ≤ | This is less than or equal to the operator. | Result of A≤B is false.
|
4 | ≥ | This is greater than or equal to the operator. | Result of A≥B is true. |
5 | == | This is equal to the operator which is used to check if the value of both operands are equal or not. | Result of A==B is false.
|
6 | != | This is not equal to the operator which is used to check if the value of both operands are equal or not. | Result of A!=B is true.
|
Bitwise Operator
Long, int, short, char, and byte are all integer types that can be used with Java's bitwise operators.
The bitwise operator operates with bits and performs operations bit by bit. Assumes variable A contains value 10 and variable contains value 5. So the binary values of
A = 0000 1010 and
B = 0000 0101
Sr. No | Operator | Description | Example |
1 | & | This is bitwise AND | Result of (A&B) is 0000 0000 |
2 | | | This is bitwise OR | Result of (A|B) is 0000 1111 |
3 | ^ | This is bitwise Exclusive | Result of (A^B) is 0000 1111 |
4 | ~ | This is bitwise complement | Result of (~A) is 11110101 (~B) is 11111010 |
5 | << | This is used to shift bit on left side | Result of (A<<B) is |
6 | >> | This is used to shift bit on right side | Result of (A>>B) is |
Logical Operator
The logical operators are mentioned in the table below.
Assume the Boolean variable A is true and that variable B is false
Sr. No | Operator | Description | Example |
1 | && | This is logical AND, it returns true when both the values are non-zero. | Result of (A&&B) is true. |
2 | || | This is logical OR, it returns true when any of two values is non zero. | Result of (A||B) is true. |
3 | ! | This is a logical NOT operator, it is used to reverse the logical state of operands. | Result of! (A&&B) is false. |
Assignment Operator
The Java language supports the following assignment operators.
Operator | Description | Example |
= | This is a straightforward assignment operator. Assigns right-side operand values to left-side operands. | C = A + B will assign value of A + B into C |
+= | The AND assignment operator is used to combine two variables. It multiplies the right and left operands and assigns the result to the left operand. | C += A is equivalent to C = C + A |
-= | AND It takes the right operand and subtracts it from the left operand, then assigns the result to the left operand. | C -= A is equivalent to C = C – A |
*= | The AND operator multiplies and assigns. It adds the right and left operands together and assigns the result to the left operand. | C *= A is equivalent to C = C * A |
/= | The AND operator divides and assigns. It multiplies the left and right operands and assigns the result to the left operand. | C /= A is equivalent to C = C / A |
%= | AND It uses two operands to calculate modulus and assigns the result to the left operand. | C %= A is equivalent to C = C % A |
<<= | Operator for both left shift and task. | C <<= 2 is same as C = C << 2 |
>>= | Operator for both the right move and the task. | C >>= 2 is same as C = C >> 2 |
&= | The AND assignment operator is a bitwise AND operator. | C &= 2 is same as C = C & 2 |
^= | bitwise exclusive OR and assignment operator. | C ^= 2 is same as C = C ^ 2 |
|= | bitwise inclusive OR and assignment operator. | C |= 2 is same as C = C | 2 |
Data Types
Data Types in Java are defined as specifiers that allocate different sizes and types of values that can be stored in the variable or an identifier. Java has a rich set of data types. Data types in Java can be divided into two parts :
Primitive Data Types
Primitive Data Types are predefined and available within the Java language. Primitive values do not share state with other primitive values.
There are 8 primitive types: byte, short, int, long, char, float, double, and boolean Integer data types.
Fig 3: primitive data types
Q10) Explain inheritance?
A10) Inheritance
Inheritance is a process in Java that allows one object to inherit all of the properties and behaviors of its parent object. It is an important component of OOPs.
Inheritance in Java refers to the ability to build new classes that are based on existing ones. When you inherit from an existing class, you can use the parent class's methods and fields. You can also add new methods and fields to your current class.
The IS-A relationship, also known as a parent-child relationship, is represented by inheritance.
Basic Terminology
Super class: The term "superclass" refers to a class whose characteristics are passed down from generation to generation (or a base class or a parent class).
Sub class: A subclass is a class that inherits from another class (or a derived class, extended class, or child class). In addition to the superclass fields and methods, the subclass may add its own fields and methods.
Reusability: Inheritance follows the principle of "reusability," which means that if we want to build a new class but there is already one with some of the code we need, we can derive our new class from the current one. We're reusing the existing class's fields and methods in this way.
Types of Inheritance
In Java, there are three types of inheritance based on class: single, multilevel, and hierarchical inheritance.
Multiple and hybrid inheritance are only allowed by interfaces in Java programming.
Fig 5: single inheritance
2. Multilevel Inheritance: A derived class inherits a base class in Multilevel Inheritance, and the derived class also acts as the base class for other classes. Class A serves as a base class for derived class B, which in turn serves as a base class for derived class C in the diagram below.
Fig 6: multilevel inheritance
3. Hierarchical Inheritance: One class act as a superclass (base class) for multiple subclasses in Hierarchical Inheritance. Class A acts as a base class for the derived classes B and C in the diagram below.
Fig 7: hierarchical inheritance
4. Multiple Inheritance: One class can have multiple super classes and inherit features from all parent classes in multiple inheritances. Please keep in mind that classes in Java do not accept multiple inheritances. Interfaces are the only way to achieve multiple inheritances in Java. Class C is derived from interfaces A and B in the diagram below.
Fig 8: multiple inheritance
5. Hybrid Inheritance: It's a combination of two or more of the inheritance forms mentioned above. Hybrid inheritance is not possible with classes because java does not accept multiple inheritances. Interfaces are the only way to achieve hybrid inheritance in Java.
Fig 9: hybrid inheritance
Q11) What do you mean by package and interface?
A11) Package
A package is a framework for grouping and controlling access to related types of classes, interfaces, and sub-packages. It groups classes together into a single unit.
Many predefined packages are already available in Java and can be used when programming.
For example: java.lang, java.io, java.util etc.
Advantages of Package
● Since a package contains a community of classes, it allows for code reuse.
● When several packages have classes with the same name, it aids in resolving naming conflicts.
● The package also includes the ability to hide classes. As a result, other programs would be unable to use the classes from the secret set.
● With the support of packages, access restrictions may be implemented.
● A package's concept can be found in another package.
Types of Packages
Built in package - The Java API already defines built-in packages. Java.util, java.io, java.lang, java.awt, java.applet, java.net, and so on are only a few examples.
User defined package - User specified package refers to the package we build based on our requirements.
Creating a package
We can make our own kit by putting together our own classes and interfaces. At the start of the program, the package statement should be declared.
Syntax
package <packagename>;
class ClassName
{
……..
……..
}
Interface
● While an interface is similar to a class, it only has abstract methods.
● Variables declared in an interface are by default public, static, and final.
● The interface is a tool for achieving complete abstraction.
● There are no constructors in an interface.
Syntax
interface InterfaceName
{
public void method1();
public void method2();
<type> variableName = value;
}
Example
interface Employee
{
static final Id = 11;
static final String name = “XYZ”;
void show();
void getSalary(double salary);
}
Extending Interface
As is the case in class, an interface must extend another interface. It is unable to create a new gui.
Implementing Interface
An interface is implemented by a class. The class will then execute the desired behavior on the gui.
When a class implements an interface, it uses the implements keyword.
Syntax
class ClassName implements interface_name
{
// body of class
}
Q12) Define Exception Handling?
A12) Exception Handling
One of the most essential features of java programming is exception handling, which helps us to manage runtime errors caused by exceptions.
Exception
An exception is an unintended occurrence that disrupts the program's normal flow. When a program encounters an exception, it is terminated. In such cases, we receive an error message created by the machine. Exceptions are useful because they can be managed in Java. We can provide a meaningful message to the user about the issue instead of a machine produced message, which might not be understandable to a user, by handling exceptions.
Why Exceptions Occur?
There are many reasons why a program could throw an exception. For instance, opening a non-existing file in your software, a network connection issue, or incorrect input data given by the user, to name a few examples.
Exception Handling
If a program encounters an exception that is not addressed by the programmer, the program is terminated and the user is presented with a system-generated error message.
Example
Exception in thread "main" java.lang.ArithmeticException: / by zero at ExceptionDemo.main(ExceptionDemo.java:5)
ExceptionDemo: The class name
main: The method name
ExceptionDemo.java: The filename
java:5: Line number
Advantages of Exception Handling
When an exception occurs, exception management guarantees that the program's flow does not interrupt. For example, if a program contains a large number of statements and an exception occurs in the middle of executing any of them, the statements following the exception will not be executed, and the program will end suddenly.
Through managing, we ensure that all of the statements are executed and that the program's flow is not disrupted.
Types of Exception
There are two types of exception
● Checked exception
● Unchecked exception
Checked Exception - Checked exceptions are all exceptions other than Runtime Exceptions that the compiler tests during compilation to see whether the programmer has treated them or not. Compilation errors can occur if these exceptions are not handled/declared in the software.
SQLException, IOException, ClassNotFoundException, and so on.
Unchecked Exception - Unchecked Exceptions are another name for Runtime Exceptions. These exceptions are not tested at compile time, so the compiler has no way of knowing whether the programmer has dealt with them or not. It is the programmer's duty to deal with these exceptions and have a secure escape.
For example,
ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc.
Keywords
In Java, there are five keywords that are used to handle exceptions.
try - The "try" keyword is used to designate a block where exception code should be placed. Either grab or finally must come after the try block. This means that we can't just use the try block.
catch - To manage the exception, the "catch" block is used. It must be followed by a try block, so we can't just use catch block. It can be followed by a later finally block.
finally - The "finally" block is used to run the program's most significant code. Whether or not an exception is treated, it is run.
throw - To throw an exception, use the "throw" keyword.
throws - Exceptions are declared using the "throws" keyword. There isn't any exception thrown. It specifies that an exception can occur in the process. It's often used in conjunction with a method signature.
Q13) Describe Multi Thread programming?
A13) Multi Thread programming
Since Java is a multi-threaded programming language, we can use it to create multi-threaded programs. A multi-threaded program is made up of two or more parts that can run in parallel, each of which can handle a different task at the same time, maximizing the use of available resources, particularly when your machine has multiple CPUs.
In Java, multithreading is the method of running several threads at the same time.
A thread is the smallest unit of processing and is a lightweight sub-process. Multitasking is accomplished by the use of multiprocessing and multithreading.
Since threads share memory, we use multithreading rather than multiprocessing. They save memory by not allocating a separate memory field, and context-switching between threads takes less time than processing.
Multithreading in Java is mainly used in sports, animation, and other similar applications.
Advantages of Multithreading
Life cycle of Thread
In its life cycle, a thread goes through many phases. A thread, for example, is born, starts, runs, and then dies.
The diagram below depicts a thread's entire life cycle.
Fig 10: life cycle of thread
The stages of the life cycle are listed below.
● New - In the new state, a new thread starts its life cycle. It will stay in this state until the thread is started by the program. A born thread is another name for it.
● Runnable - When a newly created thread is started, it becomes runnable. When a thread is in this state, it is considered to be doing its job.
● Running - If the thread scheduler has picked it, it is in the running state.
● Waiting - When a thread is waiting for another thread to complete a job, it will migrate to the waiting state. Only when another thread signals the waiting thread to begin executing does a thread transition back to the runnable state.
● Dead - When a runnable thread completes its task or otherwise terminates, it enters the terminated state.
Q14) What do you mean by java applet?
A14) Java Applet
Since Java is a multi-threaded programming language, we can use it to create multi-threaded programs. A multi-threaded program is made up of two or more parts that can run in parallel, each of which can handle a different task at the same time, maximizing the use of available resources, particularly when your machine has multiple CPUs.
In Java, multithreading is the method of running several threads at the same time.
A thread is the smallest unit of processing and is a lightweight sub-process. Multitasking is accomplished by the use of multiprocessing and multithreading.
Since threads share memory, we use multithreading rather than multiprocessing. They save memory by not allocating a separate memory field, and context-switching between threads takes less time than processing.
Multithreading in Java is mainly used in sports, animation, and other similar applications.
Advantages of Multithreading
Life cycle of Thread
In its life cycle, a thread goes through many phases. A thread, for example, is born, starts, runs, and then dies.
The diagram below depicts a thread's entire life cycle.
Fig 10: life cycle of thread
The stages of the life cycle are listed below.
● New - In the new state, a new thread starts its life cycle. It will stay in this state until the thread is started by the program. A born thread is another name for it.
● Runnable - When a newly created thread is started, it becomes runnable. When a thread is in this state, it is considered to be doing its job.
● Running - If the thread scheduler has picked it, it is in the running state.
● Waiting - When a thread is waiting for another thread to complete a job, it will migrate to the waiting state. Only when another thread signals the waiting thread to begin executing does a thread transition back to the runnable state.
● Dead - When a runnable thread completes its task or otherwise terminates, it enters the terminated state.
Q15) Explain event handling?
A15) Event Handling
An occurrence occurs when the state of an entity changes. For instance, clicking a button, dragging the mouse, and so on. For event management, the java.awt.event package offers a number of event classes and Listener interfaces.
Event class and listener interface
Event Classes | Listener Interface |
ActionEvent | ActionListener |
MouseEvent | MouseListener and MouseMotionListener |
MouseWheelEvent | MouseWheelListener |
KeyEvent | KeyListener |
ItemEvent | ItemListener |
TextEvent | TextListener |
AdjustmentEvent | AdjustmentListener |
WindowEvent | WindowListener |
ComponentEvent | ComponentListener |
ContainerEvent | ContainerListener |
FocusEvent
| FocusListener |
Steps to perform event handling
To handle a case, you must take the following steps:
Registration methods
Many classes have registration methods for registering the part with the Listener.
Consider the following scenario:
● Button
○ public void addActionListener(ActionListener a){}
● MenuItem
○ public void addActionListener(ActionListener a){}
● TextField
○ public void addActionListener(ActionListener a){}
○ public void addTextListener(TextListener a){}
● TextArea
○ public void addTextListener(TextListener a){}
● Checkbox
○ public void addItemListener(ItemListener a){}
● Choice
○ public void addItemListener(ItemListener a){}
● List
○ public void addActionListener(ActionListener a){}
○ public void addItemListener(ItemListener a){}
Q16) Describe AWT?
A16) AWT
Java AWT (Abstract Window Toolkit) is a Java API for creating graphical user interface (GUI) or window-based applications. The Java AWT API is a set of classes and methods for creating and managing graphical user interface (GUI) applications.
The AWT was created to provide a standardized collection of tools for creating graphical user interfaces that could be used on a number of platforms. The AWT tools are implemented using the native GUI toolkit of each platform, retaining the look and feel of each platform. This is one of the benefits of using AWT.
However, the drawback of this approach is that when a GUI is configured for one platform, it can appear differently when viewed on another platform, implying that AWT components are platform based.
TextField, Label, TextArea, RadioButton, CheckBox, Choice, List, and other AWT api classes are available in the java.awt package.
Swing is built on top of the AWT framework, i.e., Swing is an enhanced GUI API that expands the AWT. However, nowadays, AWT is only used because most GUI Java programs are written in Swing, which has a rich set of GUI controls and is lightweight.
Q17) Define AWT controls?
A17) AWT controls
The user can communicate with the application using AWT controls, such as the TextField control, which allows the user to enter any message.
Layout Managers create templates that automatically place controls within containers. We'll use Applet as a container in this chapter. Applet comes with FlowLayout by default.
AWT Controls
The following control groups are available in AWT.
● Label
● TextField
● Button
● Checkbox
● RadioButton
● TextArea
● Choice (Drop Down List)
● List
● ScrollBar
All of these groups are Component's children (subclasses).
Label
A label is a graphical user interface control that displays static text. The Label class and its constructors, which are described below, can be used to build a label:
Label()
Label(String str)
Label(String str, int how)
Button
The most popular GUI control is a push button. The Button class and its constructors can be used to build a push button or a button, as shown below:
Button()
Button(String str)
Checkbox
The Checkbox class and its constructors can be used to generate a checkbox control:
Checkbox()
Checkbox(String str)
Checkbox(String str, boolean on)
Checkbox(String str, boolean on, CheckboxGroup cbGroup)
Checkbox(String str, CheckboxGroup cbGroup, boolean on)
Drop Down list
A drop down box, also known as a combination box, displays a list of options (strings). When a user selects an object from a drop down box, a list of options appears from which the user can choose one.
The Choice class can be used to build a drop down box. The option class has only one constructor that can be used to generate an empty list.
List
A List box displays a list of options from which the user can choose one or more. The user can see more than one object in the list box. The List class and the following constructors can be used to build a list box:
List()
List(int numRows)
List(int numRows, boolean multipleSelect)
Text field
A text field also known as a text box, is a single-line text entry control that enables the user to type only one line of text. The TextField class, along with its constructors, can be used to build a text field:
TextField()
TextField(int numChars)
TextField(String str)
TextField(String str, int numChars)
Text Area
A text area is a multi-line text entry control that allows a user to type several lines of text. The TextArea class and the following constructor can be used to build a text area:
TextArea()
TextArea(int numLines, int numChars)
TextArea(String str)
TextArea(String str, int numLines, int numChars)
TextArea(String str, int numLines, int numChars, int sBars)
numLines specifies the text area's height, numChars specifies the text area's width, str specifies the text area's initial text, and sBars specifies the scroll bars in the constructors above.
Q18) Describe Layout managers?
A18) Layout managers
Layout Managers are used to organize components in a specific way. The interface Layout Manager is applied for all types of layout managers.
The layout managers are described by the following classes:
Border Layout
The Border Layout is used to divide the components into five different regions: north, south, east, west, and middle. Only one component can be present in each region (area). That is the standard frame or window arrangement. For each field, the Border Layout provides five constants:
Fig 12: example of border layout
Flow Layout
The Flow Layout is used to line up the components one after another in a line (in a flow). It is the applet or panel's default layout.
Field of flow layout class
Fig 13: example of flow layout
Grid Layout
The Grid Layout is used to make a rectangular grid out of the components. Each rectangle displays a single part.
Fig 14: example of grid layout
constructor of gridlayout class
Card Layout
The Card Layout class organizes the components such that only one is available at any given time. It is called Card Layout because it treats each part as a card.
Constructors of CardLayout class
Fig 15: example of card layout
GridbagLayout
Components may be aligned vertically, horizontally, or along their baseline using the Java GridBagLayout class.
It's possible that the components aren't all the same size. A dynamic, rectangular grid of cells is maintained by each GridBagLayout object. Each portion has a display area that consists of one or more cells. GridBagConstraints is associated with each component. We use the constraints object to organize the display area of the part on the grid. In order to decide component size, the GridBagLayout manages each component's minimum and desired sizes.
Fig 16: example of Gridbaglayout
Box Layout
The Box Layout is used to vertically or horizontally organize the elements. Box Layout offers four constants for this reason. The following are the details:
Constructor
● BoxLayout(Container c, int axis): creates a box arrangement with the specified axis that arranges the components.
Fig 17: example of box layout
Q19) What do you mean by string handling?
A19) String Handling
The basic goal of the String Handling principle is to store string data in main memory (RAM), manipulate string data, retrieve part of the String, and so on. String Handling includes a variety of definitions that can be applied to a string, such as string concatenation, string comparison, and finding substrings.
An immutable series of Unicode characters is contained in a Java String. The difference between a Java String and a string in C or C++ is that a string in C or C++ is simply an array of char. The java.lang package contains the String class.
Immutable class in Java
The term "immutable class" refers to the fact that once an object is made, its content cannot be changed. In Java, you should. All wrapper classes in Java, including String, Integer, Byte, Short, Float, Double, and others, are immutable.
String
String is described as a sequence of characters enclosed in double quotes (" ").
Example: “web technology”
A fundamental data type called char is used in web technology to store character data. Similarly, we have three predefined classes for storing string data and performing various operations on string data:
● String
● StringBuffer
● StringBuilder
Creating a string object
A string object can be generated in a variety of ways; here are a few examples.
2. Using new keyword - The new operator, which allocates memory for the object, can be used to generate a new string object.
Concatenating string
There are 2 methods to concatenate two or more strings.
String comparison
To compare string objects, Java provides methods and operators both. So we can compare strings in the following three ways.
Q20) What do you mean by I/O?
A20) I/O
To process the input and generate the output, Java I/O (Input and Output) is used.
To render I/O operations faster, Java employs the idea of a stream. All of the classes available for input and output operations are found in the java.io package.
The Java I/O API can be used to handle files in Java.
Stream
A stream is a set of data in a particular order. A stream in Java is made up of bytes. It's called a stream because it resembles a continuous stream of water.
Three streams are automatically generated for us in Java. The console is connected to both of these streams.
1) System.out: standard output stream
2) System.in: standard input stream
3) System.err: standard error stream