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

Unit 1 2.marks

Uploaded by

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

Unit 1 2.marks

Uploaded by

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

Unit 1

Introduction to oops and java


2marks
1.what is object oriented programming? How does if defer from procedural concepts?
OOP divides a program into small parts and these parts are referred to as objects.
Procedural programming divides a program into small programs and each small program is referred to as
a function. OOP gives importance to data rather than functions or procedures. Procedural programming
does not give importance to data.
2. What are the Concepts of OOPs?
1. Objects
2. Classes
3. Data Abstraction
4. Data Encapusulation
5. Inheritance
6. Polymorphism
7. Message Passing
8. Dynamic Binding

3. What is Polymorphism? What the are the types of Polymorphism?


Polymorphism mean many forms. Types of Polymorphism are
1. Runtime Polymorphism
2. Compile time Polymorphism

What is meant by abstraction?


Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries
relative to the perspective of the viewer. Its the process of focussing on the essential
characteristics of an object. Abstraction is one of the fundamental elements of the object
model.
What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries
relative to the perspective of the viewer. Its the process of focussing on the essential
characteristics of an object. Abstraction is one of the fundamental elements of the object
model.
What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries
relative to the perspective of the viewer. Its the process of focussing on the essential
characteristics of an object. Abstraction is one of the fundamental elements of the object
model.
What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries
relative to the perspective of the viewer. Its the process of focussing on the essential
characteristics of an object. Abstraction is one of the fundamental elements of the object
model.
What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries
relative to the perspective of the viewer. Its the process of focussing on the essential
characteristics of an object. Abstraction is one of the fundamental elements of the object
model.
What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries
relative to the perspective of the viewer. Its the process of focussing on the essential
characteristics of an object. Abstraction is one of the fundamental elements of the object
model.
What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries
relative to the perspective of the viewer. Its the process of focussing on the essential
characteristics of an object. Abstraction is one of the fundamental elements of the object
model.
What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries
relative to the perspective of the viewer. Its the process of focussing on the essential
characteristics of an object. Abstraction is one of the fundamental elements of the object
model.
4.Define an object.
Objects are the basic run time entities in an object oriented system.They may represent a
person, a place or any item that a program has to handle.

5. Define a class.
A class is a collection of objects with similar attributes and operations. Eg. Class – Account
It will create an object savings_account belonging to the class Account

6.Define Inheritance?
Inheritance is the process by which objects of one class acquire the properties of objects ofanother class.
The new derived class inherits the members of the base class and also adds its own.

7.List down the applications of OOPs.


1. Real time system2. Simulation and modeling3. AI and expert system4. Neural network
programming.5. CAD/CAM systems.
8.What are the differences between ‘break’ and ‘continue’ statement.
Break
Break statement takes the control to the outside of loopIt is used in loop and also in switch
statement
continue
Continue statement takes the control to the beginning of loopIt can be used only in loop statement

9. Define Abstraction.
It refers to the act of representing essential features without including the backgrounddetails.
10. Give the syntax of Array Initialization with an example.
Data-type array-name[size] = {list of values separated by comma};(eg.) int mark[5] =
{96,45,66,74,82};

11. What are the 4 access modifiers?


public,
protected,
default, and
private.
12. . Distinguish ‘while’ and ‘do – while’ statements.
While
This is the top tested loop
Loop is not executed if the condition is false
do while
This is the bottom tested loop
Loop is executed at least once even though the condition is false.
13. List down the benefits of OOP?
1. The principle of data hiding helps to build secure programs.
2. Through inheritance, redundant code is eliminated.
3. Software complexity can be easily managed.
14 Write the syntax for declaration of class and creation of objects?
. A class is declared using class keyword. A class contains both data and method
that operate on that data. Thus, the instance variables and methods are known
as class members. When creating an object from a class
Declaration − A variable declaration with a variable name with an object
type.
Instantiation − The 'new' keyword is used to create the object.
Initialization − The 'new' keyword is followed by a call to a constructor. This
call initializes the new object.
class Student
{
String
name; int
rollno; int
age;
}
Student std=new Student();
 std is instance/object of Student class.
 new keyword creates an actual physical copy of the object and assign it to the
std variable.
 The new operator dynamically allocates memory for an object.

15. Explain about Static?


When a member is declared as static it can be accessed before any objects of its
class are created and without any reference to any object. these are global variables, no copy of
these variablescan be made. static can also be declared for methods. and cannot refer to this or
super.

16. What are the control flow statements in java?


A programming language uses control statements to control the flow of execution
of program based on certain conditions. These are used to cause the flow of execution to advance
and branch based on changes to the state of a program.
Java’s Selection statements:
• if
• if-else
• nested-if
• if-else-if
• switch-case
• jump – break, continue, return
These statements allow you to control the flow of your program’s execution based upon
conditions known only during run time.
17. What is static variables in Java?
The static keyword in java is used for memory management mainly. We can apply java
static keyword with variables, methods, blocks and nested class. The static keyword
belongs to the class than instance of the class. If you declare any variable as static, it is
known static variable.
The static variable can be used to refer the common property of all objects (that is not
unique for each object) e.g. company name of employees, college name of students
etc. The static variable gets memory only once in class area at the time of class
loading. Advantage - It makes your
program memory efficient (i.e it saves memory).

Unit 2
Inheritance,packages and interfaces
1. What is meant by Inheritance and what are its advantages?
Inheritance is a relationship among classes, wherein one class shares the
structure or behavior defined in another class. This is called Single Inheritance. If
a class shares the structure or behavior from multiple classes, then it is called
Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which
one subclass inherits from one or more generalized super classes. The advantages
of inheritance are reusability of code and accessibility of variables and
methods of the super class by subclasses.

2. What is an Abstract Class?


Abstract class is a class that has no instances. An abstract class is written with the
expectation that its concrete subclasses will add to its structure and behavior, typically
by implementing its abstract operations.

3. What is an Interface?
Interface is an outside view of a class or object which emphasizes its abstraction
while hiding its structure and secrets of its behavior

4. What is a base class?


Base class is the most generalized class in a class structure. Most applications
have such root classes. In Java, Object is the base class for all classes.

5. What is reflection API? How are they implemented?


Reflection is the process of introspecting the features and state of a class at
runtime and dynamically manipulate at run time. This is supported using Reflection API
with built-in classes like Class, Method, Fields, Constructors etc. Example: Using Java
Reflection API we can get the class name, by using the getName method

6.
What is the difference between abstract class and interface?
ABSTRACT CLASS INTERFA
CE
1. Abstract class must have at All the methods declared
least one abstract method and inside an interface are
others may be abstract
concrete or abstract
2. In abstract class, key word Interface we need not use that
abstract keyword
must be used for the methods for the methods.
3. Abstract class must have Interface can’t have subclasses
subclasses

7. Define Package.
To create a package is quite easy: simply include a package command as the first
statement in a Java source file. Any classes declared within that file will belong to the
specified package. The package statement defines a name space in which classes are
stored. If you omit the package statement, the class names are put into the default
package, which has no name.

8. What is object cloning?


It is the process of duplicating an object so that two identical objects will exist
in the memory at the same time.

9.Define method overloading?


Method overloading in java is a feature that allows a class to have more than
one method with the same name, but with different parameters. Java supports method
overloading through two mechanisms: By changing the number of parameters.

10.Define method overridden?


If subclass (child class) has the same method as declared in the parent class, it is
known as method overriding in Java. In other words, If a subclass provides the specific
implementation of the method that has been declared by one of its parent class, it is known
as method overriding.

11. What is String in Java? Is String is data type?


String in Java is not a primitive data type like int, long or double. String is a class or in
more simple term a user defined type. String is defined in java.lang package and
wrappers its content in a character array. String provides equals() method to compare
two String and provides various other method to operate on String like toUpperCase() to
convert String into upper case, replace() to replace String contents, substring() to get
substring, split() to split long String into multiple String

12. What is interface and state its use?


Interface is similar to a class which may contain method’s signature only but not bodies
and it is a formal set of method and constant declarations that must be defined by the
class that implements it. Interfaces are useful for: a) Declaring methods that one or more
classes are expected to implement b) Capturing similarities between unrelated classes
without forcing a class relationship. c) Determining an object’s programming interface
without revealing the actual body of the class.

13. Brief Inner class in Java with its syntax.


Java inner class or nested class is a class which is declared inside the class or interface.
We use inner classes to logically group classes and interfaces in one place so that it can
be more readable and maintainable.
Additionally, it can access all the members of outer class including private data
members and methods.
Syntax of Inner class
class Java_Outer_class{
//code
class Java_Inner_class{
//code
}
}

Unit 3

Exception Handleing and Multithreading

1.What are the types of errors?


Compile time errors
Run time errors

2. Draw the exception hierarchy.


The top-level exception hierarchy is shown here:

3.
Name any four java built in exceptions.
Excepti Meani
on ng
ArithmeticException Arithmetic error, such as divide-by-zero.
ArrayIndexOutOfBoundsExce Arithmetic Exception Array index is out-of-
ption bounds.
ArrayStoreException Assignment to an array element of an
incompatible type.
ClassCastException Invalid cast

4. Compare throw and throws.


 Throw is used to throw an exception & throws is used to declare an exception.
 Throw is used in method implementation & throws is used in method signature.
Using throw keyword we can throw only 1 exception ata time &
throws can declare multiple exceptions at a time.

5. What is the use of try and catch exception?


Try-catch block is used for exception handling in the progam code. try is the start of
the block and catch is at the end of try block to handle the exceptions. A Program can
have multiple catch blocks with a try and try-catch block can be nested also. catch
block requires a parameter that
should be of type Exception.
6. What is the use of finally exception?
Finally block is optional and can be used only with try-catch block. Since exception
halts the process of execution, we might have some resources open that will not get
closed, so we can use
finally block. finally block gets executed always, whether exception occurrs or not.

7. What is difference between final, finally and finalize in Java?


Final and finally are keywords in java whereas finalize is a method.
Final keyword can be used with class variables so that they can’t be reassigned, with
class to avoid extending by classes and with methods to avoid overriding by
subclasses.
Finally keyword is used with try-catch block to provide statements that will always gets
executed even if some exception arises, usually finally is used to close resources.
finalize() method is executed by Garbage Collector before the object is destroyed,
it’s great way to make sure all the global resources are closed. Out of the three, only
finally is related to
java exception handling.

8. What is OutOfMemoryError in Java?


OutOfMemoryError in Java is a subclass of java.lang.VirtualMachineError and it’s
thrown by JVM when it ran out of heap memory.

9. Can we have an empty catch block?


We can have an empty catch block but it’s the example of worst programming. We
should never have empty catch block because if the exception is caught by that block,
we will have no information about the exception and it will be a nightmare to debug it.

10. Define Thread?


A thread is a single sequential flow of control within program. Sometimes, it is called an
execution context or light weight process. A thread itself is not
a program. A thread cannot run on its own. Rather, it runs within a program. A
program can be divided into a number of packets of code, each representing a thread
having its own separate flow of
control.

11. What is Multi-threading?


Multithreading is a conceptual programming concept where a program(process) is
divided into two or more subprograms(process), which can be implemented at the
same time in parallel. A multithreaded program contains two or more parts that can
run concurrently. Each part of such
a program is called a thread, and each thread defines a separate path of execution

12. What are the various states of a thread?


The following figure shows the states that a thread can be in during its life and
illustrates which method calls cause a transition to another state.

13. What is thread priority?


Every Java thread has a priority that helps the operating system determine the
order in which threads are scheduled. Java priorities are in the range between
MIN_PRIORITY(a constant of 1) and MAX_PRIORITY( a constant of 10). By
default, every thread is given priority NORM_PRIORITY(a constant of 5)
Threads with higher priority are more important to a program and should be
allocated processor time before lower-priority threads. However, thread priorities
cannot guarantee the
order in which threads execute and very much platform independent

14. What is Synchronization thread?


When two or more threads need access to a shared resource, they need some way to
ensure that the resource will be used by only one thread at a time. The process by which
this synchronization is achieved is called thread synchronization.

15. What is Thread Pool?


A thread pool is a managed collection of threads that are available to perform tasks.
Thread pools usually provide:
 Improved performance when executing large numbers of tasks due to reduced
per-task invocation overhead
 A means of bounding the resources, including threads, consumed when
executing a collection of tasks.
16. How Threads are created in Java?
Threads are created in two ways. They are by extending the Thread class and by
implementing Runnable interface

Unit 4
I/O,Generies,String Handling

2Marks

1.Define stream.
A stream can be defined as a sequence of data. There are two kinds of Streams
 InputStream − The InputStream is used to read data from a source.
 OutputStream − The OutputStream is used for writing data to a
destination.

2. What is character stream?


Character streams are used to perform input and output for 16-bit unicode.
Though there are many classes related to character streams but the
most frequently used classes are, FileReader and FileWriter.

3.Short note of print() method?


print() method in Java is used to display a text on the console. This text is passed
as the parameter to this method in the form of String. This method prints the text on
the console and the cursor remains at the end of the text at the console. The next
printing takes place from just here.

4.What are the type of variable?


There are three types of variables in java: local, instance and static. There are
two types of data types in Java: primitive and non-primitive.

5.What is generic programming?


Generic programming is a style of computer programming in which
algorithms are written in terms of data types to-be-specified-later that are then
instantiated when needed for specific types provided as parameters.
6.What are the three different categories of Write() method in byte stream?

.Method Description

void write (int i) writes a single byte to the output stream

void write (byte buffer [] ) writes an array of bytes to the output stream

Void write(bytes buffer[],int writes 'nBytes' bytes to the output stream from the
loc, int nBytes) buffer b starting at buffer [loc]

7.How will you compare two strings?

equals() :In Java, string equals() method compares the two given strings
based on the data/content of the string. If all the contents of both the strings are same
then it returns true. If any character does not match, then it returns false.

8.What is the use of ‘+’operator in string?


The operator “+”, which is used for number addition (in java string
concatenation), which means” together”, then in Java for string, we can use the
same for the addition of strings to create a new string. And the operation is known as
string concatenation.

9.What is generic class?


Generic classes encapsulate operations that are not specific to a particular data
type. The most common use for generic classes is with collections like linked lists,
hash tables, stacks, queues, trees, and so on.

10.How are the type variables bound?


Whenever you want to restrict the type parameter to subtypes of a particular
class you can use the bounded type parameter. If you just specify a type (class) as
bounded parameter, only sub types of that particular class are accepted by the current
generic class. These are known as bounded-types in generics in Java.

11.What are unbounded wildcards?


Wildcards can be used without bounds also.There are known as unbounded
wildcards.Its is useful for very simple operations.

12.Why are wildcard needed?


Wildcards make code simpler and more flexible. We can pass any list and,
additionally, we don't have to worry about type parameters. If a type parameter
appears only once in the method declaration, we should consider replacing it with a
wildcard. The same rule applies to bounded type parameters as well

Unit 5
JAVAFX Event Handling, Controls and Componenets
2marks
1 .What is JavaFX?
JavaFX is a set of graphics and media packages that enables developers to design, create,

test, debug, and deploy rich client applications that operate consistently across diverse

platforms. It can be considered as an alternative to Java Swing.

2. What Is New In Javafx?


JavaFX 2 is the following step inside the evolution of Java as a rich client
platform. It is designed to offer a lightweight, hardware-multiplied Java UI
platform for agency and business applications.
3.Feature of javaFX?
Functionality uncovered through Java API.
New hardware extended images pipeline (Prism).
FXML—a new XML-based totally markup language for outlining
consumerinterfaces.
Over 60 UI controls and charts with CSS styling.
Web component (WebView) to render HTML and JavaScript content internal a
Java utility, with JavaScript to Java bridge.
Support for JavaFX in Swing and SWT programs.
Self-contained utility packaging with platform-specific installers
Multi-touch support
New media engine for solid, constant media playback, consisting of assist for
H.264 video and AAC audio.
JavaFX Scene Builder, a visible UI layout device
4.What are the layouts in javaFX?

JavaFX provides several predefined layouts such as HBox, VBox, Border Pane, Stack Pane,

Text Flow, Anchor Pane, Title Pane, Grid Pane, Flow Panel, etc. Each of the above

mentioned layout is represented by a class and all these classes belongs to the package

javafx.

5.What are controls in JavaFX?

 Accordion.
 Button.
 CheckBox.
 ChoiceBox.
 ColorPicker.
 ComboBox.
 DatePicker.
 Label.

6.What are layouts in java?


FlowLayout, BorderLayout, GridLayout, CardLayout, and GridBagLayout.

7.What is region JavaFX?


The JavaFX Region class is the base class for all JavaFX layout panes, like Pane etc. The
JavaFX Region class has a set of properties and characteristics which are shared by all the
JavaFX layout classes which extend Region.

8.What is region in JavaFX?


Region is the base class for all JavaFX Node-based UI Controls, and all layout containers. It
is a resizable Parent node which can be styled from CSS. It can have multiple backgrounds
and borders. It is designed to support as much of the CSS3 specification for backgrounds and
borders as is relevant to JavaFX.

9.What is flowpane in JavaFX?


FlowPane layout pane organizes the nodes in a flow that are wrapped at the flowpane's
boundary. The horizontal flowpane arranges the nodes in a row and wrap them according to
the flowpane's width. The vertical flowpane arranges the nodes in a column and wrap them
according to the flowpane's height.

10.What is textarea in JavaFX?

The textarea is an input element using for multiple line information in the web
application. It is providing multiple lines of input information from the user and store in the
application. It is interacted between user and application using a textarea object and set in the
database.

11.How to create a menubar in javaFX?


1. ManuBar menubar = new MenuBar(); //creating MenuBar.
2. Menu MenuName = new Menu("Menu Name"); //creating Menu.
3. MenuItem MenuItem1 = new MenuItem("Menu Item 1 Name"); //creating Menu Item.
4. MenuName.getItems().add(MenuItem1); //adding Menu Item to the Menu

12.How do you add a text field in javaFX?

To create a text field, you need to instantiate the TextField class, to the constructor of this
class you can also pass a string value which will be the initial text of the text field.

13.What is Grid pane?


GridPane lays out its children within a flexible grid of rows and columns. If a border
and/or padding is set, then its content will be layed out within those insets. A child may be
placed anywhere within the grid and may span multiple rows/columns.

14.What are 3 components in JavaFX applications?

 Stage. A stage (a window) contains all the objects of a JavaFX application. ...
 Scene graph.
 Nodes.

15.What is pane in JavaFX?


The JavaFX Pane class is a layout container which can contain other JavaFX
components internally, and lay them out. Actually, the JavaFX Pane class does not actually
provide any layout algorithm. The Pane class simply displays the components it contains at
the locations the components themselves want to be located.

You might also like