0% found this document useful (0 votes)
106 views

Unit 5, Java Notes

The document provides information about programming in Java using NetBeans IDE. It discusses the components of NetBeans IDE including parent/container controls and child controls. It also describes properties and methods of various Java controls like jButton, jTextField, jLabel, jTextArea and jPassword. The document further explains concepts of object oriented programming in Java including class, object, data members, methods, variables and different data types in Java.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Unit 5, Java Notes

The document provides information about programming in Java using NetBeans IDE. It discusses the components of NetBeans IDE including parent/container controls and child controls. It also describes properties and methods of various Java controls like jButton, jTextField, jLabel, jTextArea and jPassword. The document further explains concepts of object oriented programming in Java including class, object, data members, methods, variables and different data types in Java.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

GBSSS New Seemapuri

Information Technology, Class XI

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.

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 –

1. Background- Sets the background color.


2. Border – Sets the type of border that will surround the text field.
3. editable – If set true user can edit textfield. Default is true.
4. enabled – Contains enabled state of component- True if enabled
else false.
5. font – Sets the font.
6. foreground – Sets the foreground color.
7. horizontalAlignment – 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 –

1. background – Sets the background color.


2. columns – Sets number of columns preferred for display.
3. editable – If set true user can edit textfield. Default is true.
4. enabled – Contains enabled state of component- true if enabled
else false.
5. font – Sets the font.
6. foreground – Sets the foreground color.
7. lineWrap – 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.
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.

Questions and Answers

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.

2. 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.

3. 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.

4. 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.

5. 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.

6. 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.

7. 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);

8. 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.
9. 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

10. 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.

11. 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.

12. 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.

13. 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.

14. 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 ==,
!=, >, <, >=, <=

15. 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.

You might also like