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

Fundamentals of Java

This document provides an overview of Java programming fundamentals, including the NetBeans IDE, its features, and user interface components. It covers key concepts of object-oriented programming (OOP), Java syntax, data types, variables, and selection statements. Additionally, it includes practice questions to reinforce understanding of the material.

Uploaded by

mostlyme2008
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Fundamentals of Java

This document provides an overview of Java programming fundamentals, including the NetBeans IDE, its features, and user interface components. It covers key concepts of object-oriented programming (OOP), Java syntax, data types, variables, and selection statements. Additionally, it includes practice questions to reinforce understanding of the material.

Uploaded by

mostlyme2008
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

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

FEATURES OF NETBEANS IDE –


· Embedded compiler and debugger.
· Auto completion of code.
· Syntax highlighting feature is there.
· Easy to use.

USER INTERFACE OF NETBEANS-

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.

5. Navigator Window: Shows a hierarchy of controls on the current form and


highlights the selected one.

6. Palette Window: Contains drag-and-drop GUI components, grouped by


categories like Swing Controls and Containers.

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.

7. Properties Window: Displays properties of the selected control or node with


tabs for Properties, Events, and Code. It can be repositioned or opened via the
Window menu.

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:

Commonly used methods of the Password component are as follows:

 Radio Button- The Radio Button component is used to provide


two or more choices to the user and allow him to select any one of them. All
Radio Button components present on the form belong to a group allowing
the user to select only a single option. Java uses the IRadioButton class to
create a Radio Button component.
The methods of the Radio Button component are as follows:

 Check Box – A check box component is a rectangular box that can be


either checked or unchecked. When it is clicked, it changes from checked
to unchecked or vice versa automatically. It is used to provide several
choices to the user and allow him to select multiple choices like selecting
favourite sports, etc. Internally, the jCheckBox class is used in the
creation of the check box component.
 Combo Box - A component used to display multiple options in a
dropdown menu, showing one option at a time. It saves space and is
easier to design than Radio Buttons or Check Boxes. It is best for single
selection, while the List component is better for selecting multiple
options from a large set.

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.

2. High level language- computer language in which we write the codes in a


general language like English is called high-level language (HLL).
Similar to the English language, high-level language also follows some
grammar rules of computer language. C, C++, Java, Python, etc. are
some of the examples of the HLL.

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.

POP AND OOP APPROACH DIFFERENCE-:


BASIC CONCEPTS OF OOP-:

1. CLASS- A class is defined as a collection of objects or a blueprint to


create objects.
2. OBJECT- An object is the basic unit of object-oriented programming
and corresponds to things or entities that are related to a particular class.
 ATTRIBUTES- The characteristics that identifies objects are the
attributes. For example, Birds are a class and Parrot, Pigeon, Eagle
and Vulture are the objects of the class Birds, every bird has got some
distinguished features such as Size, Colour, Voice, Flying Speed etc.
These features are called the attributes or the state of that object.
3. DATA ABSTRACTION- Data abstraction is a process that involves
identifying the essential features of an object without including the
internal details. Consider an example of television which consists of
features like changing the channel, volume control, ON/OFF switch, etc.
4. DATA ENCAPSULATION- The wrapping up of data and functions into
a single unit (called class) is known as Encapsulation.
There are two features of encapsulation:

o It protects the data of a class from accidental manipulation or misuse by


the functions which are outside the class.
o Any changes made in the data and functions of a class do not affect to
other classes.
5. MODULARITY- The act of breaking a program into individual
components to reduce the complexity is called modularity.
6. INHERITANCE- The process by which one class acquires the
properties and functionalities of another class is called inheritance.
7. POLYMORPHISM- Poly which means Many and Morphs which means
Forms. It means the ability to process the data in more than one form.

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-

1.it is high level and Object-oriented programming language.

2.the codes of java programs are case-sensitive.

3. it is ideally suited for the integration of video,audio,animation and graphics in


the internet environment.

4. it has many security features that makes application programs safe & secure.

JAVA PROGRAMMING ENVIRONMENT- Java programs are saved with


.java extension.java compliers the code to generate .class file which contains
intermediate format (highly optimized code) known as bytecode.
When this bytecode is to be run on any other computer , and interpreter is required
which is known as Java Virtual machine (JVM) that translates the bytecode to
machine code or object code.

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.

2. Identifiers – They are the fundamental building blocks or units of a program


that are used for naming classes,methods,variables,objects,etc. In a program.

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 key word.

Examples – _hello, _HeLlo, RETURN_123.

1Hello , @hello – these are invalid identifiers

3. Literals-: Denotes a constant value. Various types of literals are-:


 Character literal-: enclosed with single quotes and have one character.
For ex. ‘a' is a character literal means letter a.
 String -: always enclosed with double quotes. For example,”hello world”.
 Integer-: any no. Without fraction. For ex. 10 and 012
 Floating-point-: any no. With decimal. Eg.190.25
 Boolean literal-: can have either true or false values.

4. Operators: - are the symbols that do computation(calculation) with


designated or given value. They are divided into following groups:
 Unary – it works on a single operand
 Binary - it works on a two operand
 Ternary - it works on a three operand
 Arithemetic Operators – They are used to perform mathematical operations
like addition, subtraction, multiplication, division, modulus, etc. These
operators work with two operands. So, they are also called binary operators.
Java provides the following arithemetic operators:

 Relational Operators – They are used to compare two valuees or


operands. They return either True or False. True or False are also referred
to as 1 or 0 respectively. They are also called binary operators.
 Logical Operators – They are used to combine two or more relational
expressions. They also come under binary operators. In Java, there are
mainly three logical operators which are listed in the following table:
 Assignment Operator - The assignment operator (=) is used to assign the
value of the right expression to the left operand. This operator can be used
with arithmetic operators to form various other assignment operators. These
operators are known as shorthand assignment or compound assignment
operators. The assignment operators are described in the following table

 Ternary Operator - The operator which requires three operands to work is


known as the ternary operator. it is also called a conditional operator as it
returns the result based on the provided conditional expression. Java
provides only one ternary operator

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.

1. Primitive data types- It consists of numeric and floating-point


data types-:
· Numeric data types - byte, short, int, long
· Floating-point data types- float, double
· Character data types – It is used to store values in the form
of characters.
· Boolean data type- It is used to store either true or false
value.
2. Non-primitive data types – Non-primitive data types are
derived from primitive data types. These are also known as
reference data types. Some of the examples of non-primitive
data types are class, interface, and array.

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;

2. If-else Statement- if else' statement is a decision-making statement. It is


applied in a situation when the output of an expression is True (ie., Yes),
then it follows one direction of execution/statement otherwise if it is False
(l.e., No), then it follows the other direction of execution.
Syntax: if (test expression)
True-block statements(s);
else
False-block statement(s);

3. Switch Statement- Switch is a keyword. It is a built-in multiple decision-


making statement. The switch statement tries to match the value of a given
variable (or expression) with a list of values which are attached to the case
statement and when a match is found, the block of statement(s) associated
with that case is executed (case is a keyword).

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

Ques1. Which of these cannot be used for a variable name in Java?


a) identifier & keyword
b) identifier
c) keyword
d) none of the mentioned

Ans. C

Ques2. Which of the following is not an OOPS concept in Java?


a) Polymorphism
b) Inheritance
c) Compilation
d) Encapsulation

Ans. C

Ques3. Which of these are selection statements in Java?


a) break
b) continue
c) for()
d) if()
Ans. D

Ques4. Java is a _____ programming language


a. Procedure Oriented
b. Object-Oriented
c. Practical
d. All of the above.

Ans. B

Ques5. NetBeans provides various components used to create a GUI front-end


interface like
a. jTextArea
b. jLabel
c. jButton
d. All of the above

Ans. D

Ques6. The act of breaking a program into individual components to reduce the
complexity is called ________ .

Ans. Modularity

Ques7. ___ is also known as GUI builder.

Ans. Design area

Ques8. Radio buttons are created with the help of ____ class.

Ans. JRadioButton

Ques9. Child controls are placed inside a container control. (T/F)

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.

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

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.

Ques14. Write any four features of NetBeans IDE.


Answer:
NetBeans IDE has the following features:
• Embedded compiler and debugger
• Auto-completion of code
• Editing and debugging is easier
• Syntax highlighting feature is there

Ques15. What are the advantages of the POP approach?


Answer:
Ans. Some of the advantages of POP are as follows:
• It is easy to use.
• It has the ability to re-use the same function at different places in the program
without copying it.
• It provides an easier way to keep track of program flow.
• It has the ability to be strongly modular or structured. It needs less memory to
execute.

Ques16. When do we use the Radio Button component?


Answer:
The Radio Button component is used to provide the choices to the user and allow
him to select any one choice.

You might also like