Fundamentals of Java
Fundamentals of Java
Notes
NETBEANS IDE – An integrates development environment (IDE).
Netbeans IDE is a free and open-source code product provided
by the Apache Software Foundation. GUI (graphical user
interface).
1. Menu Bar: A horizontal strip at the top of NetBeans with menus like File, Edit,
and Run, showing the current project name and window controls.
2. Toolbars: Icons below the menu bar for quick access to commands like New
File, Undo, and Run Project.
3. The design area, also known as the GUI builder, is the main window where you
can create and edit Java GUl forms. The design view is the default view of the
form.
4. Projects Window- : Displays project files and classes in a tree structure on the
left.
All the components\controls are categorised into the following two types-:
Parent Controls: Act as a background for child controls; moving or deleting them
affects all child controls.
Child control: These controls are placed inside a container control.
COMPONENTS IN SWING-:
Swing provides GUI components like buttons, checkboxes, and list boxes, with
properties (appearance), methods (actions), and events (interactions).
· Container Components: Includes Frame, Panel, and more for structuring GUIs,
created using Java classes like JFrame and JPanel.
Ø Frame
A top-level container in Swing displayed as a resizable window with a title bar,
border, and close button. It holds other components and is created using the
`JFrame` class.
Ø Panel
The panel component is a lightweight container which cannot be displayed on
its own but must be added to other containers like Frame.
· Child Components: Swing also provides several child components like Button,
Text Field, Radio Button, Check Box, Text Area, etc. These are placed inside
container component.
Ø Label: The Label component is used to display short text such as captions or
messages. It is associated with the JLabel class of java.
Ø Text Field: A lightweight component for inputting or displaying a single line of
text, created using `JTextField`. It supports text justification, font
customization, and triggers events on pressing Enter.
Ø Button: A component that triggers an event when clicked, invoking the
`actionPerformed()` method to perform a task. Buttons in Java, including
command, checkboxes, toggle, and radio buttons, are subclasses of
`AbstractButton`. They share common features and are part of the `javax.swing`
package for event handling.
Ø Text Area: A component that allows users to enter or display multiple lines of
text. It automatically adds scroll bars when needed. Created using the
`JTextArea` class in Java for handling multi-line input.
Ø Password: The Password Field component is used to input confidential data
like passwords which are single line. We can suppress the display of input. Each
character entered can be replaced by an echo character. By default, the echo
character is an asterisk, Java uses the JPasswordField class to create a Password
Field component.
Commonly used properties of the Password component are as follows:
COMPUTER LANGUAGES
A computer does not understand the instructions given in a normal spoken
language; it has to be given instructions in any computer language i.e a
programming language. The programming languages can be categorized into
the following two types of languages:
1. Low level language- Computer language in which the codes are written
in the form of 0 and 1 is called low-level language (LLL). It is also called
machine-level language as it is very close to the machine. Binary and
assemble languages are examples of this.
Based on the approach or format of writing they are categorized into top-
down and bottom-up approaches. The top-down approaches are also
known as procedure-oriented programming (POP) approaches. On the
other hand, the bottom-up approaches are also known as the object-oriented
programming (OOP) approach.
Introduction to Java
Java is one of the popular general-purpose object-oriented programming languages
that is used to develop software packages,
Characteristics of java-
4. it has many security features that makes application programs safe & secure.
JAVA TOKENS
1. Keywords - Keywords are reserved words which have some specific
meaning. They represent an operation that is already explained to the Java
compiler. We cannot change the meaning of the keywords. These are
predefined words by Java so they cannot be used as a variable or object
name or class name.
DATA TYPES
A data type is used to define the size and type of value that a variable can store.
The Java language is rich in its data types It provides two types of data types:
primitive and non-primitive.
VARIABLES
A variable is a storage location on the computer's memory where a particular type
of value can be stored. There are three types of variables in Java:
· Local variables- A variable that is declared inside the body of a method or a block
is known as the local variable. The local variable is accessible only within the
method in which it is declared.
· Instance variables- A variable that is declared inside the class but outside the
body of the method is known as an instance variable.
· Static variables - A variable that is declared inside a class using the static
keyword is known as a static variable.
SELECTION STATEMENT
1. If Statement- 'if' statement is a decision-making statement. It is applied in a
situation when the output of expression is True (i.e., Yes), then a course of
action or the statement is executed, otherwise, the course of action or the
statement is ignored.
Syntax: if (test expression)
Statement;
If the value of the expression do not match with any of the case values, then the
default statement will be executed (default is also a keyword). The default
statement in switch is optional.
The syntax of the switch statement is as follows:
switch (expression)
{
case constant 1: statement 1;
case constant 2: statement 2;
case constant 3: statement 3;
….
….
default: default statement;
}
PRACTICE QUESTION
Ans. C
Ans. C
Ans. B
Ans. D
Ques6. The act of breaking a program into individual components to reduce the
complexity is called ________ .
Ans. Modularity
Ques8. Radio buttons are created with the help of ____ class.
Ans. JRadioButton
Ans. True
Ques10. NetBeans IDE is a free and open-source product provided by the Apache
Software Foundation. (T/F)
Ans. True
Ques11. 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 were move 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.
Ques13. What are the rules for naming a valid java identifiers?
Answer:
Rules for naming a valid java identifiers are as follows:
o It consists of letters, numbers, underscore and dollar sign
o It must not start with a digit
o It is case sensitive
o It cannot contain space
o It does not have the same name as any keyword.