0% found this document useful (0 votes)
7 views23 pages

Java

The document provides an overview of Java programming fundamentals, focusing on the NetBeans IDE, its components, and how to create and manage Java applications. It covers object-oriented programming concepts, data types, variables, operators, and control structures, along with practical steps for creating projects and adding components in NetBeans. Additionally, it includes multiple-choice questions to reinforce learning.

Uploaded by

anirudh7d24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views23 pages

Java

The document provides an overview of Java programming fundamentals, focusing on the NetBeans IDE, its components, and how to create and manage Java applications. It covers object-oriented programming concepts, data types, variables, operators, and control structures, along with practical steps for creating projects and adding components in NetBeans. Additionally, it includes multiple-choice questions to reinforce learning.

Uploaded by

anirudh7d24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Fundamentals of Java Class 11 Notes

Programming in Java is simple to write, compile, and debug. Reusable code and modular
programmes can be made with its assistance. As few implementation dependencies as
possible are built into Java, an object-oriented, class-based programming language.

NetBeans IDE
For the development of applications on the Windows, Mac, Linux, and Solaris operating
systems Net Beans platform is best, NetBeans is GUI based free and open source software.
NetBeans helps to developing Java based software easily, It also support many other
language like HTM5 etc.

Components of NetBeans IDE

The user can easily interacts with NetBeans COMPONENTS which helps the user to design
the software, NetBeans components include jlabels, jbuttons, jtextfields, etc. There are two
types of controls –

Parent or container controls – Controls that serve as a parent or container serve as the
backdrop for other controls. For example – Frame.

Child controls – Child controls are controls that are contained within a container control.
Text field, label, button, etc. are a few examples.

Note – We use the drag and drop feature of NetBeans to place components on the
form to design an
effective interface for our applications.

Creating a New Project

1. Select New Project from the File menu. You can also click the New Project button in the
IDE toolbar.
2. In the Categories pane, select the General node. In the Projects pane, choose the Java
Application type. Click the Next button.
3. Enter the name of the project in the Project Name field and specify the project location.
Do not create a Main class here.
4. Click the Finish button.

Properties in NetBeans IDE Control

jButton Properties & Method

Properties –

1. Background – Sets the background color.


2. Enabled – Contains enabled state of component – true if enabled else false.
3. Font – Sets the font.
4. Foreground – Sets the foreground color.
5. horizontal alignment – Sets the horizontal alignment of text displayed on the
button.
6. Label – Sets the display text.
7. Text – Sets the display text
Method –

1. getText() – Retrieves the text typed in jButton.


String result=<button-name>.getText( );
2. setEnabled – Enables or disables the button.
<button-name>.setEnabled(boolean b);
3. setText() – Changes the display text at runtime.
<button-name>.setText(String text);
4. setVisible – Makes the component visible or invisible – true to make the
component visible; false to make it invisible.
<button-name>.setVisible(boolean aFlag);
jTextField Properties and Method

Properties –

[Link]- Sets the background color.


[Link] – Sets the type of border that will surround the text field.
[Link] – If set true user can edit textfield. Default is true.
[Link] – Contains enabled state of component- True if enabled else false.
[Link] – Sets the font.
[Link] – Sets the foreground color.
[Link] – Sets the horizontal alignment of text displayed in the
textField.
8. text – Sets the display text
9. toolTipText – Sets the text that will appear when cursor moves over the
component.
Method –

1. getText() – Retrieves the text in typed in jTextField.


String result=<textfield-name>.getText( );
2. isEditable() – Returns true if the component is editable else returns false.
boolean b=<textfield-name>.isEditable( );
3. isEnabled() – Returns true if the component is enabled,else returns false.
boolean b =<textfield-name>.isEnabled( );
4. setEditable – Sets whether the user can edit the text in the textField. true if
editable else false.
<textfield-name>.setEditable(boolean b);
5. setText() – Changes the display text at runtime.
<textfield-name>.setText(String t);
6. setVisible() – Makes the component visible or invisible – true to make the
component visible; false to make it invisible.
<textfield-name>.setVisible(boolean b);
jLabel Properties and Method

Properties –

1. background – Sets the background color.


2. enabled – Contains enabled state of component- true if enabled else false.
3. font – Sets the font.
4. foreground – Sets the foreground color.
5. horizontalAlignment – Sets the horizontal alignment of text displayed in the
component.
6. text – Sets the display text
Method –

1. getText() – Retrieves the text in typed in jLabel.


String result=<label-name>.getText();
2. isEnabled() – Returns true if the component is enabled,else returns false.
boolean b=<label-name>.isEnabled();
3. setText() – Changes the display text at runtime.
<label-name>.setText(String t);
4. setVisible() – Makes the component visible or invisible – true to make the
component visible; false to make it invisible.
<label-name>.setVisible(boolean b);
jTextArea Properties and Method

Properties –

[Link] – Sets the background color.


[Link] – Sets number of columns preferred for display.
[Link] – If set true user can edit textfield. Default is true.
[Link] – Contains enabled state of component- true if enabled else false.
[Link] – Sets the font.
[Link] – Sets the foreground color.
[Link] – Indicates whether line of text should wrap in case it exceeds
allocated width.(Default is false)
8. rows Sets – number of rows preferred for display.
9. text – Sets the display text
10. wrapStyleWord – Sends word to next line in case lineWrap is true and it
results in breaking of a word, when lines are wrapped.
Method –

1. append() – Adds data at the end.


<textarea-name>.append(String str);
2. getText() – Retrieves the text in typed in jTextArea.
String str = <textarea-name>.getText();
3. isEditable() – Returns true if the component is editable else returns false.
boolean b = <textarea-name>.isEditable();
4. isEnabled()- Returns true if the component is enabled, else returns false.
boolean b = <textarea-name>.isEnabled();
5. setText() – Changes the display text at runtime.
<textarea-name>.setText(String t);
jPassword Properties

1. background – Sets the background color.


2. font – Sets the font.
3. foreground – Sets the foreground color.
4. text – Sets the display text
5. echoChar – Sets the character that will be displayed instead of text.
Object Oriented Programming
Object Oriented Programming follows bottom up approach in program design and
emphasizes on
safety and security of data. It helps in wrapping up of data and methods together in a
single unit
which is known as data encapsulation. It arranges the architecture of software around data
or objects rather than functions and logic. An object is a data field with particular
characteristics and behaviour.

The major components of Object Oriented Programming are as follows:


1. Class
2. Object
3. Data Members & Methods
4. Access Specifier and Visibility Modes

Data Members and Methods

Methods and data members are found in classes. Data members declare inside the class, it
is variable which we are declaring inside the class. In general, data members are kept secret
so that values can only be altered at the discretion of the class function members. Data
members may be private or public. A method is a function declared inside a class.

The JTextField, JLabel, JTextArea, JButton, JCheckBox and JRadioButton are all classes and
the jTextField1, jLabel1, jTextArea1, jButton1, jCheckBox1 and jRadioButton1 components
are all objects. The setText(), setEnabled(), pow(), substring() are all methods of different
classes.
Image Source
[Link]

Variables

Variables are containers used to store the values for some input, intermediate result or the
final result of an operation. The characteristics of a variable are:
• It has a name.
• It is capable of storing values.
• It provides temporary storage.
• It is capable of changing its value during program execution.

Data Types

Data type states the way the values of that type are stored, the operations that can be
done on that type, and the range for that type.

Numeric Data Types –


These data types are used to store integer values only i.e. whole numbers only. The storage
size and range is listed below:

Floating Data Types –


These data types are used to store numbers having decimal points i.e. they can store
numbers having fractional values.

Character Data Types –

These data types are used to store characters. Character data types can store any type of
values – numbers, characters and special characters. The char data type value is always
enclosed inside ” (single quotes), whereas a string data type value is enclosed in “” (double
quotes).

Operators
Operators are symbols that manipulate, combine or compare variables. The operators
available in java are summarized below –

Assignment Operator

One of the most common operators is the assignment operator “=” which is used to assign
a value to a variable. The value on the right hand side can be a number or an arithmetic
expression.
For example:
int sum = 0;
int prime = 4*5;

Arithmetic Operators

These operators execute multiplication, division, addition, and subtraction. These symbols
resemble those used in mathematics. Only “percent,” which divides one operand by
another and returns the remainder as its result, differs from the others.

+ additive operator
– subtraction operator
* multiplication operator
/ division operator
% remainder operator

Relational Operator

A relational operator is used to test for some kind of relation between two entities.
Logical Operator

A logical operator denotes a logical operation. Logical operators and relational operators
are used together to form a complex condition. Logical operators are –

Bitwise Operator

Bitwise operators can be used to change a number’s individual bits. They are compatible
with all integral kinds (char, short, int, etc). They are utilised while updating and searching a
binary indexed tree.

Creating New Project in NetBeans –

1. Select New Project from the File menu. You can also click the New Project button in the
IDE toolbar.
2. In the Categories pane, select the General node. In the Projects pane, choose the Java
Application type. Click the Next button.
3. Enter the name of the project in the Project Name field and specify the project location.
Do not create a Main class here.
4. Click the Finish button.

Adding a Button Component to a Form

We want to add a button so follow the given steps to add a JButton to the form –
Step 1 : In the Palette window, Select the JButton component from the Swing Controls
category.
Step 2 : Move the cursor over the Form. When the guidelines appear, indicating that the
JButton is positioned in desired location, click to place the button.
Attaching Code to a Form Component

The next step after placing the button is to write the code that will cause the application to
close when the button is pressed. To accomplish the same thing, double-click the button to
associate a code with the action, i.e. the button click. The source window is opened by
double clicking on the component, and the pointer is moved to the area where code has to
be added. Keep in mind that certain code is pre-generated and cannot be altered.

Executing a File

Now that the code for the first application is ready let us test our first application. To
execute the application simply select Run>Run File or press Shift+F6

Changing Properties of Components

Each component of our application including the form has certain attributes associated
with it. The Properties Window displays the names and values of the attributes (properties)
of the currently selected component. We can edit the values of most properties in the
Properties window.

We want to change the text displayed on the button. There are four ways of doing the
same in the design view:
● Select the button component by clicking on it. In the Properties window highlight the
text property and type STOP in the textbox adjacent.
● Alternatively select the object. Left click on the button to highlight the display text. Type
STOP and press Enter.
● Select the object > Press F2 – to make the display text editable. Type in the new text and
press Enter.

Displaying a Message in a Dialog Box


Now that we are familiar with the creation process, let’s attempt some more experiments
and see if we can get a message to appear when the button is clicked. To construct a new
form with a straightforward button as shown in Figure 5.25, follow the same procedure.
Change the button’s attributes as needed and Make “Wish Me” the text property.

Control Structures

If Statement

The if statement enables choosing (decision-making) based on how a condition turns out.
The statement that comes after the if statement will be executed if the condition evaluates
to true, and the statements that come after the else clause will be executed if the condition
evaluates to false. The decision or conditional statements are other names for the selection
statements.

The syntax of if statement is as shown below:

Syntax:
if (conditional expression)
{
Statement Block;
}
else
{
Statement Block;
}

Points to remember about if statement –

• The conditional expression is always enclosed in parenthesis.


• The conditional expression may be a simple expression or a compound expression.
• Each statement block may have a single or multiple statements to be executed. In case
there is a single statement to be executed then it is not mandatory to enclose it in curly
braces ({}) but if there are multiple statements then they must be enclosed in curly braces
({}).
• The else clause is optional and needs to be included only when some action is to be
taken if the test condition evaluates to false.

Nested if . . . else

As opposed to the straightforward if statement, which may be used to test a single


condition, these control structures are used to test for several conditions. The following is
the syntax for nested if else:

Syntax:
if (conditional expression1)
{
statements1;
}
else if (conditional expression2)
{
statements2;
}
else if (conditional expression3)
{
statements3;
}
else
{
statements4;
}

Switch Statement

With the use of a range of character or numeric values, this selection statement enables us
to evaluate the value of an expression. When a matching value is found, the control jumps
to the statement related to that value, which is then run until the break statement or end of
switch is reached. The syntax of the switch statement is as follows:

switch (Variable/Expression)
{
case Value1: statements1 ;
break ;
case Value2: statements2 ;
break ;
.
.
default:statements3 ;
}

Comparing Switch and If..else Statements

The if-else statement verifies both the logical expression and equality. Switch, on the other
hand, just verifies equality. The if statement evaluates types such as boolean, character,
pointer, floating-point, and integer. The switch statement, on the other hand, exclusively
evaluates character or numeric datatypes.

Employability Skills Class 11

Fundamentals of Java Class 11 MCQ


1. NetBeans is an IDE using which we can develop ___________ in Java.
a. GUI application
b. CUI application
c. BW application
d. None of the above
* Answer ⟵
a. GUI application
2. NetBeans provides various components used to create a GUI front-end interface
like ___________.
a. jTextArea
b. jLabel
c. jButton
d. All of the above

* Answer ⟵
d. All of the above
3. GUI components’ __________ is controlled by their properties and methods.
a. Appearance
b. Behavior
c. Both a) and b)
d. None of the above

* Answer ⟵
c. Both a) and b)
4. We should use meaningful names for controls on the _________ in the code. It makes
programming convenient.
a. Form
b. Variables
c. Both a) and b)
d. None of the above

* Answer ⟵
c. Both a) and b)
5. Some useful Data Types supported in Java are ___________.
a. Int & Boolean
b. Double
c. Char
d. All of the above

* Answer ⟵
d. All of the above
6. String is an _________ type supported in Java.
a. Object
b. Constraint
c. Class
d. None of the above

* Answer ⟵
a. Object
7. A variable must be declared _____________.
a. After it can be used
b. Between it can be used
c. Before it can be used
d. None of the above

* Answer ⟵
c. Before it can be used
8. What are the different operators used in Java _________.
a. Logical Operator
b. Conditional Operator
c. Comparison Operator
d. All of the above

* Answer ⟵
d. All of the above
9. The __________ selects among a set of statements depending on the value of a
controlling expression.
a. If Statement
b. For Statement
c. While Statement
d. None of the above

* Answer ⟵
a. If Statement
10. If else statement is also known as ________.
a. Control statement
b. Structure statement
c. Program statements
d. All of the above

* Answer ⟵
a. Control statement
11. An IF statement in Java is also a _______ statement.
a. Number
b. conditional
c. String
d. None of the above

* Answer ⟵
b. conditional
12. In Java, an ELSE statement needs to come after a _________ statement.
a. IF
b. ELSE IF
c. IF or ELSE IF
d. None of the above

* Answer ⟵
c. IF or ELSE IF
13. It is required to define an IF statement code between two braces.
a. False
b. True
c. Some time True and Some time False
d. None of the above

* Answer ⟵
a. False
14. An ELSE statement’s code may be enclosed in braces.
a. FALSE
b. TRUE
c. Some time True and Some time False
d. None of the above

* Answer ⟵
b. TRUE
15. Without an IF statement, an ELSE or ELSE-IF statement in Java cannot occur.
a. FALSE
b. TRUE
c. Some time True and Some time False
d. None of the above

* Answer ⟵
b. TRUE
16. if the condition is false in if condition, which of the following will be true.
a. IF Statement will be executed
b. ELSE Statement is executed.
c. IF and ELSE both will not execute.
d. IF and ELSE both will execute.

* Answer ⟵
b. ELSE Statement is executed.
17. How many lines of code can be written inside an IF, ELSE, or IF-ELSE block in Java?
a. 25
b. 72
c. 105
d. None of the above

* Answer ⟵
d. None of the above
18. In which of the following situations is an IF-ELSE statement preferable to a
SWITCH statement?
a. Checking multiple condition
b. Checking for Less-than condition
c. Checking for Ranges
d. All of the above

* Answer ⟵
d. All of the above
19. How many ELSE-IF statements can be present between the beginning IF and the
closing ELSE statements?
a. 44
b. 55
c. 320
d. None of the above

* Answer ⟵
d. None of the above
20. Select the proper Java IF statement syntax from the list below.
a. if(condition) //statement
b. if(condition){ //statement}
c. if(condition){ //statement1 //statement2}
d. All of the above

* Answer ⟵
d. All of the above
21. What does the Java programme with IF-ELSE statements produce?
if(TRUE)
[Link](“True”);
else
[Link](“False”);
a. True
b. False
c. Compiler error
d. None

* Answer ⟵
c. Compiler error
22. What is the output of the Java program?
int a=10;
if(a==9)
[Link](” My “);
[Link](“School”);
else
[Link](“My Class”);
a. My School
b. My Class
c. Compiler error
d. None of the above

* Answer ⟵
c. Compiler error
23. What is the output of the Java program?
String name1=”My School”, name2=”My Class”;
if(name1 == “My School”)
{
[Link](“My School “);
[Link](“My Class”);
}
if(name2 == “No Class”)
{
[Link](“My Class”);
}
a. My School My Class
b. My School My Class My Class
c. Compiler error
d. None of the above

* Answer ⟵
a. My School My Class
24. What is the output of the Java program?
String name=”Anurag”;
if(name == “Anand”)
{
[Link](“Anurag”);
}
[Link](“Computer Science”);
a. Anurag Computer Science
b. Anurag
c. Computer Science
d. Compiler error

* Answer ⟵
c. Computer Science
25. What is the output of the Java program with ELSE-IF statements?
int marks=90;
if(marks >= 80)
[Link](“Distinction”);
else if(marks >=33)
[Link](“Pass”);
else
[Link](“Fail”);
a. Distinction
b. Pass
c. Fail
d. Compiler error

* Answer ⟵
b. Pass
26. What is the output of Java program below?
float temp = 97.3;
if(temp > 97.3)
{
[Link](“High Temperature”);
}
else
{
[Link](“Temperature”);
}
a. High Temperature
b. Temperature
c. Compiler error
d. None of the above

* Answer ⟵
a. High Temperature
27. What is the output of the Java program?
int marks = 91;
if(marks > 32)
{
if(age <= 100)
{
[Link](“Pass”);
}
}
else
{
[Link](“Fail”);
}
a. Pass
b. Fail
c. Compiler error
d. None of the above

* Answer ⟵
a. Pass
28. What is the output of the Java program?
int marks=55;
if(marks > 55);
[Link](“Pass “);
[Link](“Fail”);
a. Fail
b. Pass
c. Pass Fail
d. Compiler error

* Answer ⟵
c. Pass Fail
29. What is the result of the IF statement in a Java programme?
if(true)
{
break;
[Link](“School”);
}
a. No Output
b. School
c. Compiler error
d. None of the above

* Answer ⟵
c. Compiler error
30. Java is a ______ programming language.
a. Procedure Oriented
b. Object-Oriented
c. Practical
d. All of the above

* Answer ⟵
b. Object-Oriented
31. The code in the Java programming language is put inside ___________.
a. Blocks
b. Methods
c. Classes, Interfaces
d. All the above

* Answer ⟵
d. All of the above
32. What file extension is associated with the Java class source code?
a. .jpp
b. .jsp
c. .java
d. None of the above

* Answer ⟵
c. .java
33. What file extension is associated with compiled Java class files?
a. .jpp
b. .java
c. .class
d. .clear

* Answer ⟵
c. .class
34. In Java, the keyword used to declare a class is _________.
a. Function
b. Method
c. class
d. Java

* Answer ⟵
c. class
35. A Java class can contain___________.
a. Variables
b. Methods, Constructors
c. Inner Classes (A class inside another class)
d. All of the above

* Answer ⟵
d. All of the above
36. In Java, the word ________ is used to create a new object.
a. java
b. new
c. class
d. function

* Answer ⟵
b. new
37. In Java, an object is created at _________ time.
a. Assembling time
b. Run time
c. Compile-time
d. None of the above
* Answer ⟵
b. Run time
38. Select the appropriate Java class declaration syntax from the list below.
a.
class CLASSNAME
{

}
b.
CLASSNAME class
{

}
c.
class CLASSNAME;
{

}
d.
Class CLASSNAME
{

* Answer ⟵
a. class CLASSNAME { }
39. Pick the appropriate method for producing an object of the class listed below.
class Table
{
Table(){[Link](“Table Created”);}
}
a. Table t = new Table;
b. Table t = new Table();
c. Table() t = new Table();
d. None of the above

* Answer ⟵
b. Table t = new Table();
40. A control statement in Java is called a _________ SWITCH case statement.
a. Iteration
b. Loop
c. Selection
d. Jump

* Answer ⟵
c. Selection
41. Which is the Java language equivalent of SWITCH?
a. break, continue
b. for, while
c. if, else
d. goto, exit
* Answer ⟵
c. if, else
42. What keywords are needed in Java to implement a SWITCH case?
a. switch, case
b. default
c. break
d. All of the above

* Answer ⟵
d. All of the above
43. Select the proper SWITCH statement syntax for Java from the list below.
a.
switch(input)
{
case constant1: //statements; break;
case constant2: //statements; break;
default: //statements;
};
b.
switch(input)
{
case constant1: //statements; break;
case constant2: //statements; break;
default: //statements;
}
c.
switch(input)
{
case constant1: //statements; break;
case constant2: //statements; break;
default case: //statements;
};
d.
switch(input)
{
case constant1: //statements; break;
case constant2: //statements; break;
default case: //statements;
}

* Answer ⟵
b. switch(input) { case constant1: //statements; break; case constant2: //statements; break;
default: //statements; }
44. What is the result of the following Java application with SWITCH?
int a=10;
switch(a)
{
case 10: [Link](“Welcome”);
}
a. No output
b. Welcome
c. Compiler error as there is no BREAK.
d. None

* Answer ⟵
b. Welcome
45. What does the Java programme below produce?
String animal = “Horse”;
switch(animal)
{
break: [Link](“DOMESTIC”);
}
a. No output
b. Horse
c. DOMESTIC
d. Compiler error

* Answer ⟵
d. Compiler error

Java NetBeans Programs for Class 11


1. What is the purpose of NetBeans IDE?
Answer – Java applications can be simply created utilizing the effective GUI builder in the
NetBeans IDE. We can create application by dragging and dropping GUI elements from a
palette onto a container. Correct spacing and alignment of the various components in
relation to one another are handled automatically by the GUI builder.

3. What is the difference between Parent control and Child control in NetBeans?
Answer – There are two different type of control –
a. Parent or container controls – Controls that serve as a parent or container serve as the
backdrop for other controls. Consider Frame. All of a parent control’s child controls are also
destroyed when we remove it. All of a parent control’s child controls move with it when the
parent control is moved.

b. Child controls – Child controls are controls that are positioned inside a container
control. For instance, a text field, a label, a button, etc.

Java NetBeans Programs for Class 11

4. Write any two property of jFrame Form?


Answer – The two property of jFrame Form are –
a. defaultCloseOperation – Sets action to be performed when the user attempts to close
the form.
b. Title – Sets the text to be displayed in the Title bar of the form window.

5. What id purpose of property in NetBeans?


Answer – An object’s properties are used to determine how it will display on the form. For
instance, you can alter a textfield’s background color, font, and other properties by
changing its background attribute.
6. What is Methods?
Answer – To do some action on the object, methods are employed. For instance, you may
use a textfield’s setText() method to show something in it or use its getText() method to
retrieve its contents. Getters and setters are the two categories into which methods can be
separated.

Java NetBeans Programs for Class 11

7. What is Event?
Answer – Events are the actions which are performed on controls. Examples of events are
mouseClick, mouseMoved,keyPressed etc. When the user performs any action on a control,
an event happens and that event invokes the corresponding part of the code and the
application behaves accordingly.

8. Write any two method of jButton?


Answer –
a. getText() – Retrieves the text typed in jButton.
String result=<button-name>.getText( );
b. setText() – Changes the display text at runtime.
<button-name>.setText(String text);

9. What is Object Oriented Programming Language?


Answer – Object-oriented programming is known as OOP. While object-oriented
programming involves constructing objects that include both data and functions,
procedural programming involves developing procedures or functions that perform actions
on the data.

Java NetBeans Programs for Class 11

10. What are the major components of Object Oriented Programming?


Answer – The major components of Object Oriented Programming are –
1. Class
2. Object
3. Data Members & Methods
4. Access Specifier and Visibility Modes

11. What is data member and method?


Answer – Methods and data members are accessible in classes. In actual Java
programming, the methods are a series of steps put together to carry out a certain action
on the data, whilst the data will need to adhere to a specified data type, such as char, int,
float, or double.

12. What is Variables?


Answer – Variables act as a kind of container for the data they hold. Because they can
change their value but not their name, these things are called variables.

Java NetBeans Programs for Class 11

13. What are the different characteristics of variable?


Answer – The characteristics of a variable are:
• It has a name.
• It is capable of storing values.
• It provides temporary storage.
• It is capable of changing its value during program execution.

14. What is Data types? What are the different type of Data Type.
Answer – The data type describes the actions that may be performed on the type, the
range for the type, and how the type’s values are stored. Some of the example of data
types are –

a. Numeric Data Type – These data types are used to store integer values only i.e. whole
numbers only.
Example Byte, Short, Int, Long

b. Floating Data Types – These data types are used to store numbers having decimal
points i.e. they can store numbers having fractional values. for example float & double.

c. Character Data Types – These data types are used to store characters. Character data
types can store any type of values – numbers, characters and special characters.

Java NetBeans Programs for Class 11

15. What is Operator? What are the different type of operators.


Answer – Operators are symbols that manipulate, combine or compare variables. The
operators available in java are –
a. Assignment Operator – One of the most common operators is the assignment operator
“=” which is used to assign a value to a variable. We assign the value given on the right
hand side to the variable specified on
the left hand side.

b. Arithmetic Operator – These operators perform addition, subtraction, multiplication,


and division. These symbols are similar to mathematical symbols. example +, -, *, /, %

c. Relational Operator – A relational operator is used to test for some kind of relation
between two entities. A mathematical expression created using a relational operator forms
a relational expression or a condition. example ==, !=, >, <, >=, <=

16. What is Bitwise Operator?


Answer – Bitwise operators can be used to change a number’s individual bits. They are
compatible with all integral kinds (char, short, int, etc). They are utilised while updating and
searching a binary indexed tree.

Java NetBeans Programs for Class 11

17. Design a GUI application to accept the side of a square in a text field and
calculate the area and perimeter of the square. Add Refresh button to clear all text
fields and a Stop button to end the application.
Hint [ Area of a square = side * side and perimeter = 2(side +side)]
Answer – //Coding for jButton1 (“Calculate the area” button)
private void jButton1ActionPerformed([Link] evt)
{
double a,b;
a=[Link]([Link]());
b=a*a; [Link]([Link](b));
}

//Coding for jButton2 (“Calculate the perimeter” button)


private void jButton3ActionPerformed([Link] evt)
{
doublea,c;
a=[Link]([Link]());
c=4*a;
[Link]([Link](c));
}

//Coding for jButton4 (“Refresh” button)


private void jButton4ActionPerformed([Link] evt)
{
[Link](” “);[Link](” “);[Link](” “);
}

You might also like