11-IT Unit 5 First Topic

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Class Notes

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

How GUI application works?

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.

Java allows three types of integer literals -


 Decimal Integer Literals (Base 10) e.g. 1234, 41, +97, -17 etc.
 Octal Integer Literals (Base 8) e.g.010, 014 (Octal must start with 0)
 Hexadecimal Integer Literals (Base 16) e.g. 0xC, 0xab (Hex numbers must start with 0x)
L or U suffix can used to represent long and unsigned literals respectively.
Floating / Real Literals: A real literals are fractional numbers having at least one digit before and after
decimal point with + or – sign.

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

 The Boolean Literals represents either TRUE or FALSE. It always Boolean


type.
 A null literals indicates nothing. It always null type.
 Character Literals must contain one character and must enclosed in single
quotation mark. e.g. ‘a’, ‘%’ , ‘9’ , ‘\\’ etc.
 Java allows some non-graphic characters (which can not betyped directly through
keyboard) by using Escape sequence (\) .
 The following Escape characters are commonly used in Java.
 \a (alert),\b (backspace),\f (Form feed),\n (new line),\r (return key),\t (Horizontal tab),\v
(vertical tab),\\ (back slash),\’ (single quote),\” (double quote) ,\? (question mark),\0 (null)
etc.
 String Literals is a sequence of zero or more characters enclosed in double quotes.
 E.g. “abs”, “amit” , “1234” , “12 A” etc.

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.

Variable Naming Conventions


Each variable needs to have a name so that it can be referenced anywhere during the application. Each
programming language has its own set of rules for naming variables. The rules and conventions for naming
variables in Java are summarized below:
● Variable names are case sensitive.
● Keywords or words, which have special meaning in java, should not be used as
the variable names.
● Variable names should be short and meaningful.
● All variable names must begin with a letter, an underscore (_) or a dollar sign ($).
The convention is to always use a letter and avoid starting variable names with
underscore (_) and dollar sign ($).
● After the first initial letter, variable names may contain letters and digits (0 to 9) and ( _, $), but no spaces
or special characters are allowed.

Creating a new Form


To create a new application project called "Books":
1. Choose File > New Project. Alternately, click the New Project icon in the toolbar.
2. From the Categories pane select Java and in the Projects pane, choose Java Application. Click Next.
3. Enter a name (in this case Books) in the Project Name field and specify the project location by
clicking on the Browse button. By default, the project is saved in the NetBeans Projects folder in My
Documents and so this is the default Project location displayed in this field.
4. Ensure that the Set as Main Project checkbox is selected and clear the Create Main Class field.
5. Click Finish.
 A button is a component that the user presses or pushes to trigger a specific action. When the user
clicks on the button at runtime, the code associated with the click action gets executed.
 jFrame: Used as a Basic Window or form.
 jLabel: Allows Non-editable text or icon to be displayed.

 The Text Area component allows us to accept multiline input from the user or display multiple lines
of information. This component automatically adds vertical or horizontal scroll bars as and when
required during run time.
 jCheckBox is a small box like component that is either marked or unmarked. When it is clicked, it
changes from checked to unchecked or vice versa automatically.

 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.");
}

5. Write a JAVA program to accept 3 values and find the greatest.

Note: ‘Content developed/prepared absolutely from home.

You might also like