0% found this document useful (0 votes)
38 views19 pages

OOP 2 Marks Unit I To V

Uploaded by

Pavithra N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views19 pages

OOP 2 Marks Unit I To V

Uploaded by

Pavithra N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

UNIT - I
1. What is Java?

Java is a high-level object-oriented programming language, which provides developers with


the means to create powerful applications, which are very small in size, platform independent,
secure and robust.

2. Define OBJECT ORIENTED PROGRAMMING (OOP):

Object-Oriented Programming System (OOPs) is a programming paradigm based on the concept


of ―objects that contain data and methods, instead of just functions and procedures.

• The primary purpose of object-oriented programming is to increase the flexibility and


maintainability of programs.
• Object oriented programming brings together data and its behavior (methods) in to a
single entity (object) which makes it easier to understand how a program works.

3. Define PROCEDURE-ORIENTED PROGRAMMING [POP]


Procedure-Oriented Programming is a conventional programming which consists of writing a list
of instructions for the computer to follow and organizing these instructions into groups known as
Functions (or) Procedures (or) subroutines (or) Modules.
Example: A program may involve the following operations:
• Collecting data from user (Reading)
• Calculations on collected data (Calculation)
• Displaying the result to the user (Printing)

4. Features/Characteristics of OOP
OOPs simplify the software development and maintenance by providing some concepts:

1. Class - Blue print of Object

2. Object - Instance of class

3. Encapsulation - Protecting our data

4. Polymorphism - Different behaviors at different instances

5. Abstraction - Hiding irrelevant data

6. Inheritance - An object acquiring the property of another object

5. Define Class
A class is a collection of similar objects and it contains data and methods that operate on that
data. In other words ― Class is a blueprint or template for a set of objects that share a
common structure and a common behavior. It is a logical entity.

1
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

A class in Java can contain:


• fields
• methods
• constructors
• blocks
• nested class and interface

6. Syntax to declare a class and Give an Example.

class <class_name> { field; method; }

7.Define Object.
Any entity that has state and behavior is known as an object. Object is an instance of a class.
• For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.
• The object of a class can be created by using the new keyword in Java Programming
language.
Syntax:
• class_name object_name = new class_name;
• (or) class_name object_name;
• object_name = new class_name();

8.Define characteristics of an object.


An object has three characteristics.

• State: represents data (value) of an object.


• Behavior: represents the behavior (functionality) of an object such as deposit, withdraw
etc.
• Identity: Object identity is an unique ID used internally by the JVM to identify each
object uniquely.

2
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

• For Example: Pen is an object. Its name is Reynolds, color is white etc. known as its state.
It is used to write, so writing is its behavior

9. Difference between Object and Class


S.NO Object Class

1) Object is an instance of a Class is a blueprint or template


class. from which objects are created.

2) Object is a real world entity Class is a group of similar objects.


such as pen, laptop, mobile,
bed, keyboard, mouse, chair
etc.
3) Object is a physical entity. Class is a logical entity.

4) Object is created through Class is declared using class


new keyword mainly e.g. keyword
Student s1=new Student(); e.g. class Student{}

5) Object is created many Class is declared once.


times as per requirement.

10.Define Polymorphism:
• Polymorphism is a concept by which we can perform a single action by different
ways. It is the ability of an object to take more than one form.
• The word "poly" means many and "morphs" means forms. So polymorphism
means many forms.
• Two types of polymorphism:
1. Compile time polymorphism / Method Overloading: - In this method, object is
bound to the function call at the compile time itself.
2. Runtime polymorphism / Method Overriding: - In this method, object is bound to
the function call only at the run time.
• In java, we use method overloading and method overriding to achieve
polymorphism.
• Example:
1. draw(int x, int y, int z)
2. draw(int l, int b)
3. draw(int r)

3
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

11.Define Abstraction:
• Abstraction refers to the act of representing essential features without including
the background details or explanations. i.e., Abstraction means hiding lower-
level details and exposing only the essential and relevant details to the users.
• For Example: - Consider an ATM Machine; All are performing operations on the
ATM machine like cash withdrawal, money transfer, retrieve mini-
statement…etc. but we can't know internal details about ATM.
• Abstraction provides advantage of code reuse.
• Abstraction enables program open for extension.
• In java, abstract classes and interfaces are used to achieve Abstraction.

12.Define Inheritance:

Inheritance is a process of deriving a new class from existing class, also called as
“extending a class”. When an existing class is extended, the new (inherited) class has all the
properties and methods of the existing class and also possesses its own characteristics.
The class whose property is being inherited by another class is called “base class” (or)
“parent class” (or) “super class”.

The class that inherits a particular property or a set of properties from the base class is called
“derived class” (or) “child class” (or) “sub class”.

• For example:- In a child and parent relationship, all the properties of a father are
inherited by his son.
• Syntax of Java Inheritance

class Subclass-name extends Superclass-name


{
//methods and fields }

13.What are the features of the Java language?(JAVA BUZZ Words)


The following are the features of the Java language:
1. Object Oriented s
2. Simple
3. Secure
4. Platform Independent .
6. Portable
7. Architecture Neutral
8. Dynamic
9. Interpreted
10. High Performance
11. Multithreaded 12. Distributed

4
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

14. Why java is Platform Independent?


• Unlike C, C++, when Java program is compiled, it is not compiled into
platform-specific machine code, rather it is converted into platform independent
code called bytecode.
• The Java bytecodes are not specific to any processor. They can be
executed in any computer without any error.
• Because of the bytecode, Java is called as Platform Independent.

15. Define Byte code.


Byte code is an intermediate code generated from the source code by java compiler
and it is platform independent.
▪ Unlike C, C++, when Java program is compiled, it is not compiled into platform-
specific machine code, rather it is converted into platform independent code called
bytecode.
• The Java bytecodes are not specific to any processor. They can be executed in any
computer without any error.

16.What are the types of Variables?


There are three kinds of variables in Java:
1. Local variables
2. Instance variables
3. Class/static variables

17. Define Operators.


Operators are used to manipulate primitive data types.
Java operators can be classified as unary, binary, or ternary—meaning taking one, two, or three
arguments, respectively
A binary or ternary operator appears between its arguments. Java operators fall into
eight different categories:
1. Assignment
2. Arithmetic
3. Relational
4. Logical
5. Bitwise
6. Compound assignment
7. Conditional
8. Type.

18. Define Control statements.


Java Control statements control the order of execution in a java program, based on data values
and conditional logic.
There are three main categories of control flow statements;
· Selection statements: Decision making statement: if, if-else and switch.
· Loop statements: Iteration statement: while, do-while and for.

5
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

· Transfer statements: Loop Control Statements/ Jump Statements: break, continue, return,
try-catch-finally and assert.
We use control statements when we want to change the default sequential order of execution.

19. Define Enhanced for loop or for- each loop:


As of Java 5, the enhanced for loop was introduced. This is mainly used for Arrays.
• The for-each loop is used to traverse array or collection in java.
• It is easier to use than simple for loop because we don't need to increment value and
use subscript notation.
• It works on elements basis not index.
• It returns element one by one in the defined variable.
Syntax:
for(declaration : expression) {

//Statements }

20. Define Constructor and its types .


Constructor is a special type of method that is used to initialize the object. Constructor
is invoked at the time of object creation. Once defined, the constructor is automatically called
immediately after the object is created, before the new operator completes.

Types of constructors
There are two types of constructors:
1. Default constructor
2. no-arg constructor
3. Parameterized constructor

21. Define Method.


A Java method is a collection of statements that are grouped together to perform an operation.
modifier Return –type method_name(parameter_list) throws exception_list
{
// method body }
22. Define Access specifiers.
Access specifiers are used to specify the visibility and accessibility of a class constructors,
member variables and methods.
Access specifiers are used to specify the visibility and accessibility of a class constructors,
member variables and methods.
Java classes, fields, constructors and methods can have one of four different access modifiers:
1. Public
2. Private
3. Protected
4. Default (package)

6
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

23. Define Type Conversion.


Type Conversion is the task of converting one data type into another data type.
Two types of type conversion:
1. Implicit Type Conversion (or) Automatic Conversion
2. Explicit Type Conversion (or) Casitng

UNIT - II
1. Define Method Overloading and its Advantages, way to achieve overloading.
Method Overloading is a feature in Java that allows a class to have more than one methods
having same name, but with different signatures (Each method must have different number of
parameters or parameters having different types and orders).
Advantage:
Method Overloading increases the readability of the program.
Provides the flexibility to use similar method with different parameters.
Three ways to overload a method
1. Number of parameters. (Different number of parameters in argument list)
For example: This is a valid case of overloading
add(int, int)
add(int, int, int)
2. Data type of parameters. (Difference in data type of parameters)
For example:
add(int, int)
add(int, float)
3. Sequence of Data type of parameters.
For example:
add(int, float)
add(float, int)

2. Define Inner Class and Benefits.


An inner class is a class that is defined inside another class.
Inner classes let you make one class a member of another class. Just as
classes have member variables and methods, a class can also have member classes.
Benefits:
1. Name control
2. Access control
3. Code becomes more readable and maintainable because it locally group related
classes in one place.

7
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

3. What are the Advantage of java inner classes ?


There are basically three advantages of inner classes in java. They are as follows:
1) Nested class can access all the members (data members and methods) of outer class
including private.
2) Nested classes are used to develop more readable and maintainable code.
3) Code Optimization: It requires less code to write.

4. What are the Types of Nested classes ?


There are two types of nested classes non-static and static nested classes. The non-static nested
classes are also known as inner classes.
Non-static nested class (inner class)
1. Member inner class
2. Anonymous inner class
3. Local inner class
4. Static nested class

5. What are the advantages of inheritance.


Reusability of Code:
Inheritance is mainly used for code reusability (Code reusability means that we can add extra
features to an existing class without modifying it).
Effort and Time Saving:
The advantage of reusability saves the programmer time and effort. Since the main code
written can be reused in various situations as needed.
Increased Reliability:
The program with inheritance becomes more understandable and easily maintainable as the
sub classes are created from the existing reliably working classes.

6. Define "extends” KEYWORD.


Inheriting a class means creating a new class as an extension of another class.
The extends keyword is used to inherit a class from existing class.
The general form of a class declaration that inherits a superclass is shown here:
Syntax:
[access_specifier] class subclass_name extends superclass_name

{
// body of class }

7.What are the types of inheritance?


1. Single Inheritance
2. Multilevel Inheritance
3. Multiple Inheritance (not support)

8
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

4. Hierarchical Inheritance
5. Hybrid Inheritance (not support)

8.Define Super Keyword.


Super is a special keyword that directs the compiler to invoke the superclass members. It is used
to refer to the parent class of the class in which the keyword is used.
super keyword is used for the following three purposes:
1. To invoke superclass constructor.
2. To invoke superclass members variables.
3. To invoke superclass methods

9. Define Method Overriding and its advantages.


The process of a subclass redefining a method contained in the superclass (with the same
method signature) is called Method Overriding.
When a method in a subclass has the same name and type signature as a method in its
superclass, then the method in subclass is said to override a method in the superclass.
Advantages:
Method Overriding is used to provide specific implementation of a method that is already
provided by its super class.
Method Overriding is used for Runtime Polymorphism.

10. Define Dynamic Method Dispatch.


Dynamic method dispatch is the mechanism by which a call to an overridden method is
resolved at run time, rather than compile time. Dynamic method dispatch is important because
this is how Java implements run-time polymorphism.

11.What is final keyword in Java?


Final is a keyword or reserved word in java used for restricting some functionality. It can be
applied to member variables, methods, class and local variables in Java.
final keyword has three uses:
1. For declaring variable – to create a named constant. A final variable cannot be changed
once it is initialized.
2. For declaring the methods – to prevent method overriding. A final method cannot be
overridden by subclasses.
3. For declaring the class – to prevent a class from inheritance. A final class cannot be
inherited.

12. Define Packages.


A Package can be defined as a collection of classes, interfaces, enumerations and annotations,
providing access protection and name space management.

Package can be categorized in two form:


1. Built-in package 2. user-defined package

9
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

13. What are the Advantage of Package?


• Package is used to categorize the classes and interfaces so that they can be easily
maintained.
• Package provides access protection.
• Package removes naming collision.
• To bundle classes and interface
• The classes of one package are isolated from the classes of another package
• Provides reusability of code
• We can create our own package or extend already available package

UNIT - III
1. Define Exception.
An Exception is an event that occurs during program execution which disrupts the normal flow of
a program. It is an object which is thrown at runtime.
Occurrence of any kind of exception in java applications may result in an abrupt termination of
the JVM or simply the JVM crashes.

2. DIFFERENCE BETWEEN EXCEPTION AND ERROR.

S.No. Exception Error


Exceptions can be recovered Errors cannot be recovered
1.

Exceptions are of type java.lang.Exception Errors are of type java.lang.Error


2.

Exceptions can be classified into two types: There is no such classification for
3. a) Checked Exceptions errors. Errors are always unchecked.
b) Unchecked Exceptions

In case of Checked Exceptions, compiler In case of Errors, compiler won’t have


4. will have knowledge of checked exceptions knowledge of errors. Because they
and force to keep try…catch block. happen at run time.
Unchecked Exceptions are not known to
compiler because they occur at run time.
Exceptions are mainly caused by the Errors are mostly caused by the
5. application itself. environment in which application is
running.

10
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

3. What are the java exception handling keywords?


Exception handling in java is managed using the following five keywords

:S.No Keyword Description


1 try A block of code that is to be monitored for exception.
2 catch The catch block handles the specific type of exception along with the try
block. For each corresponding try block there exists the catch block.
3 finally It specifies the code that must be executed even though exception may or
may not occur.
4 throw This keyword is used to explicitly throw specific exception from the
program code.
5 throws It specifies the exceptions that can be thrown by a particular method.

4. Difference between throw and throws

throw keyword throws keyword


1) throw is used to explicitly throw an throws is used to declare an exception.
exception.
2) checked exception cannot be propagated checked exception can be propagated with throws.
without throws.
3) throw is followed by an instance. throws is followed by class.
4) throw is used within the method. throws is used with the method signature.
5)You cannot throw multiple exception You can declare multiple exception
e.g. public void method()throws
IOException,SQLException.

5. What are the types of Exceptions?

1. User-Defined Exception
2. Built - in - Exception
i)Checked Exceptions: ii)Unchecked Exceptions(RunTimeException

1. ClassNotFoundException 1. ArrayIndexOutOfBoundsException
2. CloneNotSupportedException 2. ArithmeticException
3. IllegalAccessException 3. NullPointerException.
4. MalformedURLException.
5. NoSuchFileException
6. NoSuchMethodException
7. IOException

11
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

6. Differentiate final, finally, and finalize keyword>

comparison final finally finalize


Basic Final is a "Keyword" and Finally is a "block" in Finalize is a "method"
"access modifier" in Java. Java. in Java.
Applicable Final is a keyword applicable Finally is a block that is finalize() is a method
to classes, variables and always associated with try applicable to objects.
methods. and catch block.
Working (1) Final variable becomes A "finally" block, clean up Finalize method
constant, and it can't be the resources used in "try" performs cleans up
reassigned. (2) A final method block. activities related to the
can't be overridden by the object before its
child class. (3) Final Class can destruction.
not be extended.
Execution Final method is executed "Finally" block executes finalize() method
upon its call. just after the execution executes just before
of"try-catch" block. the destruction of the
object.

7. Define Thread.
A thread is a lightweight sub-process that defines a separate path of execution. It is the smallest
unit of processing that can run concurrently with the other parts (other threads) of the same
process.
Threads are independent.
If there occurs exception in one thread, it doesn't affect other threads.
It uses a shared memory area.

8.Define Multithreading.
Multithreading is a technique of executing more than one thread, performing different tasks,
simultaneously.
Multithreading enables programs to have more than one execution paths which executes
concurrently. Each such execution path is a thread. For example, one thread is writing
content on a file at the same time another thread is performing spelling check.

9. Define Autoboxing and Unboxing .


The automatic conversion of primitive data type into its corresponding wrapper class is
known as autoboxing, for example, byte to Byte, char to Character, int to Integer, long to Long,
float to Float, boolean to Boolean, double to Double, and short to Short.
Unboxing
The automatic conversion of wrapper type into its corresponding primitive type is known as
unboxing. It is the reverse process of autoboxing.

10.Define a Stack Trace.


A Stack Trace is a list of method calls from the point when the application was started
to the current location of execution within the program. A Stack Trace is produced automatically

12
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

by the Java Virtual Machine when an exception is thrown to indicate the location and
progression of the program up to the point of the exception. They are displayed whenever a Java
program terminates with an uncaught exception

11. Define assert keyword.


Java assert keyword is used to create assertions in Java, which enables us to test the
assumptions about our program. For example, an assertion may be to make sure that an
employee’s age is positive number.
Syntax of using Assertion:
There are two ways to use assertion.
First way:
1. assert expression;
Second way:
2. assert expression1 : expression2;

12. Define Wrapper classes and its use.


Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.
Use of Wrapper classes
• Change the value in Method
• Serialization
• Synchronization
• java.util package
• Collection Framework

13.What are the types of thread synchronization?


There are two types of thread synchronization mutual exclusive and inter-thread communication.
1. Mutual Exclusive
1. Synchronized method.
2. Synchronized block.
3. static synchronization.
2. Cooperation (Inter-thread communication in java)

14. Define Inter-Thread Communication


Inter-thread communication is a mechanism in which a thread is paused running in its critical
section and another thread is allowed to enter (or lock) in the same critical section to be
executed.

15. Define the functions of Suspending, Resuming and Stopping threads


The functions of Suspend, Resume and Stop a thread is performed using Boolean-type flags in a
multithreading program. These flags are used to store the current status of the thread.
1. If the suspend flag is set to true, then run() will suspend the execution of the currently running
thread.
2. If the resume flag is set to true, then run() will resume the execution of the suspended thread.
3. If the stop flag is set to true, then a thread will get terminated.

13
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

UNIT - IV
1. Define Java I/O.
Java I/O (Input and Output) is used to process the input and produce the output.
• Java uses the concept of stream to make I/O operation fast.
• These streams support all the types of objects, data-types, characters, files etc to fully
execute the I/O operations.
• The java.io package contains all the classes required for input and output operations.
• Then, we will create an object of Scanner class which will be used to get input from the
user.

JAVA INPUT
import java.util.Scanner;
Scanner input = new Scanner (System.in);
int number = input.nextInt();
JAVA OUTPUT
Simply use System.out.println(), System.out.print() or System.out.printf() to send output
to standard output (screen).system is a class and out is a public static field which accepts
output data.

2.What's the difference between println (), print () and printf ()?
• print () - prints string inside the quotes.
• println () - prints string inside the quotes similar like print() method. Then the cursor
moves to the beginning of the next line.
• printf () - it provides string formatting

3. Define Stream.
A Stream is a sequence of data or it is an abstraction that either produces or consumes
information. In other simple words it is a flow of data from which you can read or write data
to it. It’s called a stream because it's like a stream of water that continues to flow.

4. Define predefined streams


In java, 3 streams are created for us automatically. All these streams are attached with
console.
1) System.in: This is used to feed the data to user's program and usually a keyboard is used as
standard input stream and represented as System.in. – It is an object of type InputStream.
2) System.out: This is used to output the data produced by the user's program and usually a
computer screen is used to standard output stream and represented as System.out. - It is an
object of type PrintStream.
3) System.err: This is used to output the error data produced by the user's program and
usually a computer screen is used to standard error stream and represented as System.err. - It
is an object of type PrintStream.

5. What are the types of streams?


1. Byte Stream – Byte Streams provide a convenient means of handling input and output in
terms of bytes. Byte streams are used when reading or writing binary data.

14
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

2. Character Stream – Character streams provide a convenient means of handling input or


output in terms of characters. In some cases, character streams are more efficient than byte
streams.

6. Define reading and writing console .


It is a predefined class to get input from user.
3 Ways to read input from console in Java
1. Using Buffered Reader Class
2. Using Scanner Class
3. Using Console Class

7. What is File Handling in Java? Write down the File Operations in Java.
• File handling in Java implies reading from and writing data to a file.
• The File class from the java.io package, allows us to work with different formats of
files.
• In order to use the File class, you need to create an object of the class and specify the
filename or directory name.
Basically, you can perform four operations on a file. They are as follows:
1) Create a File
2) Get File Information
3) Write To a File
4) Read from a File

8. Define Genetic programming.


Generic programming is a style of computer programming in which algorithms are written in
terms of “to-be-specified-later” types that are then instantiated when needed for specific types
provided as parameters.
Generic programming refers to writing code that will work for many types of data.

9. Define StringBuffer Class


The StringBuffer class is used to created mutable (modifiable) string. The StringBuffer class
is same as String except it is mutable i.e. it can be changed.
StringBuffer can be changed dynamically. String buffers are preferred when heavy modification
of character strings is involved (appending, inserting, deleting, modifying etc).

UNIT - V
1. What is JavaFX?
JavaFX is a set of graphics and media packages that enable developers to design, create, test,
debug, and deploy desktop applications and Rich Internet Applications (RIA) that operate
consistently across diverse platforms. The applications built in JavaFX can run on multiple
platforms including Web, Mobile, and Desktops.

15
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

2. Define JavaFX Application Structure.


A JavaFX application will have three major components namely
1) Stage
2) Scene and 3) Nodes
as shown in the following diagram.

Figure: JavaFX App.lication Structure

Figure: Scene Graph and Nodes

3. What are the types of stages available in JavaFX?


There are five types of stages available −
o Decorated
o Undecorated
o Transparent
o Unified
o Utility

16
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

4. Draw the Lifecycle of a JavaFX Application.


The JavaFX Application class has three life cycle methods, which are –
1) launch() - to launch JavaFX application.
2) init() − An empty method which can be overridden, but you cannot create a stage or scene in
this method.
3) start() − The entry point method where the JavaFX graphics code is to be written.
4) stop() − An empty method which can be overridden, here we can write the logic to stop the
application.

5.What are the three properties of event in JavaFX?


Every event in JavaFX has three properties:
1. Event source
2. Event target
3. Event type

6. Define the Phases of Event Handling in JavaFX.


Whenever an event is generated, JavaFX undergoes the following phases:
1. Target Selection – Depends on the particular event type.
2. Route Construction – Specified by the event target.
3. Event Capturing – Event travels from the stage to the event target.
4. Event Bubbling – Event travel back from the target to the stage.

7. Define the method for event handling.


Three methods for Event Handling:
1. Convenience Methods:
setOnKeyPressed(eventHandler);
setOnMouseClicked(eventHandler);
2. Event Handler/Filter Registration Methods:
addEventHandler(eventType, eventHandler);
addEventFilter(eventType, eventFilter);
3. Event Dispatcher Property (lambda expression).

17
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

8. Define Key event and its types.


Key Event − It is an input event that indicates the key stroke occurred on a node.
• It is represented by the class named KeyEvent.
• This event includes actions like key pressed, key released and key typed.

Types of Key Event in Java


1. KEY_PRESSED – When a key on the keyboard is pressed, this event will be triggered.
2. KEY_RELEASED – When the pressed key on the keyboard is released, this event will be
executed.
3. KEY_TYPED – This event will be triggered when a Unicode character is entered

9. What are the Types of Mouse Events in JavaFX?


• MOUSE_PRESSED – When you press a mouse button, this event is triggered. The
MouseButton enum defines three constants that represent a mouse button: NONE,
PRIMARY, and SECONDARY. The MouseEvent class’s getButton() method returns
the mouse button that is responsible for the event.
• MOUSE_RELEASED – The event is triggered if you pressed and released a mouse
button in the same node.
• MOUSE_CLICKED – This event will occur when you pressed and released a node.
• MOUSE_MOVED – Simply move your mouse without pressing any mouse buttons to
generate this type of mouse event.
• MOUSE_ENTERED – This event occurs when the mouse or cursor enters the target
node.
• MOUSE_EXITED – This event occurs when the mouse or cursor leaves or moved
outside the target node.
• MOUSE_DRAGGED – This event occurs when you move the mouse with a pressed
mouse button to a target node.

10. What are the layouts available in Java FX?


JavaFX provides various built-in Layouts that are
1. Pane
2. VBox
3. HBox
4. BorderPane
5. FlowPane
6. GridPane
7. StackPane.

18
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE

11. Define JavaFX Menus, MenuItem and MenuBar and its constructors.
Menu is a popup menu that contains several menu items that are displayed when the
user clicks a menu. The user can select a menu item after which the menu goes into a hidden
state.
MenuBar is usually placed at the top of the screen which contains several menus. JavaFX
MenuBar is typically an implementation of a menu bar.
Constructor of the MenuBar class are:
1. MenuBar(): creates a new empty menubar.
2. MenuBar(Menu... m): creates a new menubar with the given set of menu.

Constructor of the Menu class are:


1. Menu(): creates an empty menu
2. Menu(String s): creates a menu with a string as its label
3. Menu(String s, Node n):Constructs a Menu and sets the display text with the specified text
and sets the graphic Node to the given node.
4. Menu(String s, Node n, MenuItem... i):Constructs a Menu and sets the display text with the
specified text, the graphic Node to the given node, and inserts the given items into the items list.

19
Mrs. B.Pandiselvi , AP/CSE - RVCE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy