11-IT Unit 5 First Topic
11-IT Unit 5 First Topic
11-IT Unit 5 First Topic
Class: XI
Topic: Unit-5:
Subject: Information Technology (802) Understand Integrated Development Environment
(NETBEANS)
What is JAVA?
JAVA is an Object Oriented programming language as well a platform.
By using JAVA, we can write Platform independent application programs, which can run
on any type of OS and Hardware.
JAVA is designed to build Interactive, Dynamic and Secure applications on
network computer system.
Characteristics of JAVA
Object Oriented Language: Java is Object Oriented Language (a real-world programming
style)
Open Source Product: It is Open Source i.e. freely available to all with no cost.
Write Once Run Anywhere (WORA): JAVA Program can be run on any type of H/W and
OS platforms i.e. Java programs are platform independent.
Light Weight Code: Big applications can be developed with small code.
Security: JAVA Programs are safe and secure on Network.
Interpreter & Compiler based Language: JAVA uses both Compiler and Interpreter (JVM)
to produce portable and platform-independent object code.
Built-in Graphics & Supports Multimedia: JAVA is equipped with Graphics feature. It is
best for integration of Audio, Video and graphics & animation.
NetBeans ID: NetBeans IDE is used to create java applications very easily using the efficient GUI builder.
It allows us to develop applications by dragging and positioning GUI components from a palette onto a
container. The GUI builder automatically takes care of the correct spacing and alignment of the different
components relative to each other.
Palette
Design Area
Properties Window
Output
Inspector
Window Window
1. Title Bar
2. Menu Bar with pull down menus
3. Toolbars
4. GUI builder: It is an area to place components on the form visually. There are two views of
the GUI builder- the Design View and the Source View. We can switch over from one view
to another by simply clicking on the source and design tabs directly above the Design Area.
5. Palette: Palette contains controls or components used to create GUI applications. PROG
6. Inspector Window: This window is used to display a hierarchy of all the components or
controls placed on the current form.
7. Properties Window: Using this window we can make changes in the properties of currently
selected control on the form.
8. Code Editor Window: - It is the area where we write code for our java application.
Basics of GUI Applications
Graphical User Interface (GUI) based application contains Windows, Buttons, Text boxes,
Dialogue boxes and Menus etc. known as GUI components. While using a GUI application, when
user performs an action, an Event is generated which causes a Message sent to application to take
action.
What is Event?
An Events refers to the occurrence of an activity by user like click, double click etc.
What is Message?
A Message is the information/request sent to the application when event occurs.
JAVA Tokens: The smallest individual unit in a program is known as Token. It may any word, symbols or
punctuation mark etc. Following types of tokens used in Java-Keywords, Identifiers, Literals,
Punctuators (; [] etc), Operators(+,-,/,*, =, == etc.)
Keywords in Java: Keywords are the reserve words that have a special meaning to the compiler. Key words
can’t be used as identifiers or variable name etc. Commonly used key words are- char, long, for, case, if,
double, int, short, void, main, while , new etc.
Identifiers in Java: Identifiers are fundamental building block of program and used as names given to
variables, objects, classes and functions etc.
The following rules must be followed while using identifiers.
Identifiers may have alphabets, digits and dollar ($), underscore (_) sign.
They must not be Java keywords.
They must not begin with digit.
They can be of any length.
They are Case Sensitive ie. Age is different from age.
Literals in Java: Literals or constants are data items that have fixed data value.
Java allows several types of literals like- Integer Literals, Floating Literals, Boolean Literals, Character
Literals, String Literals, The null literals.
Integer Literals: An integer constant or literals must have at least one +/- digit without decimal point.
The following are valid real numbers- 2.0, 17.5, -13.0. -0.00626
The following are invalid real numbers- 7, 7. , +17/2 and 17,250.26 etc.
Other Literals
Data types in JAVA: Data types are means to identify the type of data and associated operations of
handling it. Java offers two types of data types.
Primitive: These are in-built data types offered by the compiler. Java supports 8 primitive
data types e.g. byte, short, int, long, float, double, char, boolean.
Reference: These are constructed by using primitive data types, as per user need. Reference
data types store the memory address of an object. Class, Interface and Array are the example
of Reference Data types.
Components
COMPONENTS (ALSO known as "widgets") are the basic interface elements the user interacts
with: jlabels, jbuttons, jtextfields etc. Components are placed on a container (like the jFrame).
There are two types of controls
• Parent or container controls: They act as a background for other controls.
For example-Frame. When we delete a parent control, all its child controls get deleted. When we move a
parent control all its child controls also move along with it.
• Child controls: controls placed inside a container control are called child controls.
For example-Text Field, Label, Button etc.
The radio buttons are used to provide the user several choices and allow him to select one of the
choices (the radio buttons belong to a group allowing the user to select single option). But radio
buttons occupy a lot of space.
The jPassword component is used to enter confidential input like passwords which are single line.
jComboBox is like a drop down box - you can click a drop-down arrow and select an option from a
list whereas jList provides a scrollable set of items from which one or more may be selected.
JOptionPane allows to create pop-up window or dialog with predefined style.
when we want to request information from the user, display information to the user or a combination
of both.
The major components of Object Oriented Programming are as follows:
1. Class
2. Object
3. Data Members & Methods
4. Access Specifier and Visibility Modes
A class is used to encapsulate data and methods together in a single unit. It helps the
programmer to keep the data members in various visibility modes depending upon what kind of
access needs to be provided in the remaining part of the application.
An object is an instance of a class that is capable of holding actual data in memory locations.
Class and objects are related to each other in the same way as data type and variables.
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
A variable is a placeholder for data that can change its value during program execution. 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.
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.
Operators
Assignment Operator:
One of the most common operators is the assignment operator "=" which is used to assign a
value to a variable.
Arithmetic Operators:
These operators perform addition, subtraction, multiplication, and division. These symbols are
similar to mathematical symbols. The only symbol that is different is "%", which divides one
operand by another and returns the remainder as its result.
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.
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 are used to perform manipulation of individual bits of a number. They can be
used with any of the integral types (char, short, int, etc). They are used when performing
update and query operations of Binary indexed tree.
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
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.
1. Write a JAVA program to add two number.
String S1=JTF1.getText();
String S2=JTF2.getText();
int x = Integer.parseInt(S1);
int y = Integer.parseInt(S2);
int sum = x + y;
JTF3.setText(""+sum);
2. Write a JAVA code to accept a 2 digit number and calculate the sum of its digits.
int a = Integer.parseInt(JTF1.getText());
int b = a / 10;
int c = a % 10;
int sum = b+ c;
JTF2.setText(""+sum);
3. Write a JAVA code to accept a 2 digit number and reverse its digits.
4. Write a JAVA code to accept any values between 1 to 100 and check if it is an even number.
int n = Integer.parseInt(JTF1.getText());
int r = n % 2 ;
if ( r == 0)
{
JTF2.setText ("It is an EVEN No.");
}
Else
{
JTF2.setText("It is an ODD No.");
}