You are on page 1of 20

Medicaps University

Oral Examination May 2021


Paper Code: CS3CO08
Paper Name: Computer Programming-II (Java)

From Each Unit: Minimum 60 questions and as many as possible, if it is 240 questions and more it will be well and good.

Sl No Unit Question No Question Answer Remark


1 1 What is java ? Java is a programming language and a
platform. Java is a high level, robust,
object-oriented and secure programming
language.
2 2 What are features of java Programming Simple,Object-Oriented,Portable,
Language? Platform Independent,Secured,Robust,
Multithreaded,Distributed
3 3 Explain JVM? Java Virtual Machne is a virtual machine
that enables the computer to run the
Java program. JVM acts like a run-time
engine which calls the main method
present in the Java code.
4 4 What do you mean by JDK? It stands for Java Development Kit.It is
the tool necessary to compile, document
and package Java programs.It contains
JRE + development tools.
5 5 What do you understand by JRE? It stands for Java Runtime Environment.
JRE refers to a runtime environment in
which Java bytecode can be executed.t’s
an implementation of the JVM which
physically exists.
6 6 What is JIT compiler? Just-In-Time(JIT) compiler: It is used to
improve the performance.JIT compiles
parts of the bytecode that have similar
functionality at the same time, and hence
reduces the amount of time needed for
compilation.
7 7 What gives Java its 'write once and run The bytecode. Java compiler converts the
anywhere' nature? Java programs into the class file (Byte
Code) which is the intermediate language
between source code and machine code.
This bytecode is not platform specific and
can be executed on any computer.
8 8 What is the platform? A platform is the hardware or software
environment in which a piece of software
is executed. There are two types of
platforms, software-based and hardware-
based. Java provides the software-based
platform.
9 9 Why Java is platform independent? Java is called platform independent
because of its byte codes which can run
on any system irrespective of its
underlying operating system.
10 10 Why Java is not 100% Object-oriented? Java is not 100% Object-oriented because
it makes use of eight primitive data types
such as boolean, byte, char, int, float,
double, long, short which are not objects.
11 11 What's the purpose of Static methods When there is a requirement to share a
and static variables? method or a variable between multiple
objects of a class instead of creating
separate copies for each object, we use
static keyword to make a method or
variable shared for all objects.
12 12 What is the difference between break and continue are two important
continue and break statement? keywords used in Loops. When a break
keyword is used in a loop, loop is broken
instantly while when continue keyword is
used, current iteration is broken and loop
continues with next iteration.
13 13 What is the difference between double In java, float takes 4 bytes in memory
and float variables in Java? while Double takes 8 bytes in memory.
Float is single precision floating point
decimal number while Double is double
precision decimal number.
14 14 What is Final Keyword in Java? In java, a constant is declared using the
keyword Final. Value can be assigned only
once and after assignment, value of a
constant can't be changed.
15 15 What is ternary operator? Ternary operator , also called conditional
operator is used to decide which value to
assign to a variable based on a Boolean
value evaluation.
16 16 Can main() method in Java can return In java, main() method can't return any
any data? data and hence, it's always declared with
a void return type.
17 17 Can we declare the main method of our In java, main method must be public
class as private? static in order to run any application
correctly. If main method is declared as
private, developer won't get any
compilation error however, it will not get
executed and will give a runtime error.
18 18 Is String a data type in java? String is not a primitive data type in java.
When a string is created in java, it's
actually an object of Java.Lang.String
class that gets created. After creation of
this string object, all built-in methods of
String class can be used on the string
object.
19 19 How garbage collection is done in Java? In java, when an object is not referenced
any more, garbage collection takes place
and the object is destroyed automatically.
For automatic garbage collection java
calls either System.gc() method or
Runtime.gc() method.
20 20 How we can execute any code even If we want to execute any statements
before main method? before even creation of objects at load
time of class, we can use a static block of
code in the class. Any statements inside
this static block of code will get executed
once at the time of loading the class even
before creation of objects in the main
method.
21 21 How can we use primitive data types as Primitive data types like int can be
objects? handled as objects by the use of their
respective wrapper classes. For example,
Integer is a wrapper class for primitive
data type int. We can apply different
methods to a wrapper class, just like any
other object.
22 22 A person says that he compiled a java main method is an entry point of Java
class successfully without even having a class and is required for execution of the
main method in it? Is it possible? program however; a class gets compiled
successfully even if it doesn't have a main
method. It can't be run though.
23 23 Can we call a non-static method from Non-Static methods are owned by
inside a static method? objects of a class and have object level
scope and in order to call the non-Static
methods from a static block (like from a
static main method), an object of the
class needs to be created first. Then using
object reference, these methods can be
invoked.
24 24 Can we use goto in Java to go to a In Java, there is not goto keyword and
particular line? java doesn't support this feature of going
to a particular labeled line.
25 25 Is JDK required on each machine to run JDK is development Kit of Java and is
a Java program? required for development only and to run
a Java program on a machine, JDK isn't
required. Only JRE is required.
26 26 Can a variable be local and static at the No a variable can't be static as well as
same time? local at the same time. Defining a local
variable as static gives compilation error.
27 27 Is it correct to say that due to garbage Even though automatic garbage
collection feature in Java, a java collection is provided by Java, it doesn't
program never goes out of memory? ensure that a Java program will not go
out of memory as there is a possibility
that creation of Java objects is being done
at a faster pace compared to garbage
collection resulting in filling of all the
available memory resources.

So, garbage collection helps in reducing


the chances of a program going out of
memory but it doesn't ensure that.
28 28 Can we have any other return type than No, Java class main method can have only
void for main method? void return type for the program to get
successfully executed.
29 29 Is there a way to increase the size of an Arrays are static and once we have
array after its declaration? specified its size, we can't change it. If we
want to use such collections where we
may require a change of size ( no of
items), we should prefer vector over
array.

I
30 30 If an application has multiple classes in If there is main method in more than one
it, is it okay to have a main method in classes in a java application, it won't
more than one class? cause any issue as entry point for any
application will be a specific class and
I code will start from the main method of
that particular class only.
31 31 Can we cast any other type to Boolean No, we can neither cast any other
Type with type casting? primitive type to Boolean data type nor
can cast Boolean data type to any other
primitive data type.
32 32 What is this keyword in Java? this() represents the current instance of a
class
33 33 What is super keyword in Java? super() represents the current instance of
a parent/base class
34 34 What is static method in Java? The static keyword must be used before
the method name It is called using the
class (className.methodName) They can’
t access any non-static instance variables
or methods
35 35 What is nonstatic method in Java? No need to use the static keyword before
the method nameIt is can be called like
any general methodIt can access any
static method and any static variable
without creating an instance of the class
36 36 What is the default value of the local The local variables are not initialized to
variables? any default value, neither primitives nor
object references.
37 37 What is the static variable? The static variable is used to refer to the
common property of all objects (that is
not unique for each object), e.g., The
company name of employees, college
name of students, etc.
38 38 What are the restrictions that are Two main restrictions are applied to the
applied to the Java static methods? static methods.

The static method can not use non-static


data member or call the non-static
method directly.
this and super cannot be used in static
context as they are non-static.
39 39 Why is the main method static? Because the object is not required to call
the static method. If we make the main
method non-static, JVM will have to
create its object first and then call main()
method which will lead to the extra
memory allocation.
40 40 Can we override the static methods? No, we can't override static methods.
41 41 How does Java enable high Java uses Just In Time compiler to enable
performance? high performance. It is used to convert
the instructions into bytecodes.
42 42 What is meant by the Instance Instance variable is defined inside the
variable? class and outside the method and the
scope of the variables exists throughout
the class.
43 43 What happens if you remove static Program compiles successfully. But at
modifier from the main method? runtime throws an error
“NoSuchMethodError”.
44 44 What is Unicode? Java uses Unicode to represent the
characters. Unicode defines a fully
international character set that can
represent all of the characters found in
human languages.
45 45 What are Literals? Any constant value that is assigned to a
variable is called literal in Java. For
example –
46 46 What is Type casting in Java? When we assign a value of one data type
to the different data type then these two
data types may not be compatible and
needs a conversion. If the data types are
compatible (for example assigning int
value to long) then java does automatic
conversion and does not require casting.
However if the data types are not
compatible then they need to be casted
for conversion.
47 47 What is an Array? An array is a collection (group) of fixed
number of items. Array is a homogeneous
data structure which means we can store
multiple values of same type in an array
but it can’t contain multiple values of
different types. For example an array of
int type can only hold integer values.
48 48 What is the base class for all the java.lang.Object is base class for the
classes? objects.
49 49 Why does Java not support pointers? The pointer is a variable that refers to the
memory address. They are not used in
Java because they are unsafe(unsecured)
and complex to understand.
50 50 Can we overload the main() method? Yes, we can have any number of main
methods in a Java program by using
method overloading.
51 51 What are the Data Types supported by The eight primitive data types supported
Java ? by the Java programming language are:
• byte
• short
• int
• long
• float
• double
• boolean
• char
52 52 What is the difference between In declaration we just mention the type
declaring a variable and defining a of the variable and it's name. We do not
variable? initialize it. But defining means
declaration + initialization.
53 53 What is the Java API? The Java API is a large collection of ready-
made software components that provide
many useful capabilities, such as
graphical user interface (GUI) widgets.
54 54 What is variables and then types? Variables is an identifier that denotes a
storage location used to store a data
values.unlike constants that remain
unchanged during the execution of a
program, a variable may takes different
values at different times during the
execution of the program.
Instance variables
Class variables
Local variable
Parameters
55 55 What are different types of access Access specifiers are keywords that
modifiers? determine the type of access to the
member a class.
Public
Protected
Private
Default
56 56 What is an instanceof operator? Instanceof is an object reference
operator and returns true if the object on
the left-hand side is an instance of the
glass given to the right hand side.This
operator allows to determine whether
the object belongs to a particular class or
not.
57 57 What is Byte Code? All Java programs are compiled into class
files that contain bytecodes. These byte
codes can be run in any platform and
hence java is said to be platform
independent.
58 58 What is the difference between java and Java is a true object - oriented language
c++? while c++ is basically c with object-
oriented extension.
C++ supports multiple inheritence but
Java provides interfaces in case of
multiple inheritence.
Java does not support operator
overloading.
Java does not have template classes as in
c++.
java does not use pointers.
59 59 What are PATH and CLASSPATH? PATH and CLASSPATH are two
environment variables which need to be
set in order to compile and run the java
programs.
60 60 How does Garbage Collection prevent a ava Garbage Collector does not prevent a
Java application from going out of Java application from going out of
memory? memory. It simply cleans the unused
memory when an object is out of scope
and no longer needed. As a result,
garbage collection is not guaranteed to
prevent a Java app from going out of
memory.
61 1 What is Inheritance in Java? Inheritance is an Object oriented feature
which allows a class to inherit behavior
and data from other class.
62 2 What are different types of Inheritance Java supports single Inheritance, multi-
supported by Java? level inheritance and at some extent
multiple inheritances because Java allows
a class to only extend another class, but
an interface in Java can extend multiple
inheritances.
63 3 Why multiple Inheritance is not Java is introduced after C++ and Java
supported by Java? designer didn't want to take some C++
feature which is confusing and not
essential. They think multiple
inheritances is one of them which doesn't
justify complexity and confusion it
introduces.
64 4 Why Inheritance is used by Java Inheritance is used for code reuse and
Programmers? leveraging Polymorphism by creating a
type hierarchy.
65 5 How to use Inheritance in Java? You can use Inheritance in Java by
extending classesJava provides keyword
extends.
66 6 What is the difference between Inheritance is an object oriented concept
Inheritance and Encapsulation? which creates a parent-child relationship.
It is one of the ways to reuse the code
written for parent class but it also forms
the basis of Polymorphism. On the other
hand, Encapsulation is an object oriented
concept which is used to hide the internal
details of a class e.g. HashMap
encapsulate how to store elements and
how to calculate hash values.
67 7 What is the difference between Abstraction is an object oriented concept
Inheritance and Abstraction? which is used to simply things by
abstracting details. It helps in the
designing system. On the other hand,
Inheritance allows code reuse. You can
reuse the functionality you have already
coded by using Inheritance.
68 8 What is the difference between Polymorphism allows flexibility, you can
Polymorphism and Inheritance? choose which code to run at runtime by
overriding. On the other hand,
Inheritance allows code reuse.
69 9 Can we override static method in Java? No
70 10 Can we overload a static method in Yes
Java?
71 11 Can we override a private method in No
Java?
72 12 What is method hiding in Java? Since the static method cannot be
overridden in Java, but if you declare the
same static method in subclass then that
would hide the method from the
superclass. It means, if you call that
method from subclass then the one in the
subclass will be invoked but if you call the
same method from superclass then the
one in superclass will be invoked. This is
known as method hiding in Java.
73 13 Can a class extends more than one class No, a class can only extend just one more
in Java? class in Java. Though Every class also, by
default extend the java.lang.Object class
in Java.
74 14 Can an interface extends more than one Yes, unlike classes, an interface can
interface in Java? extend more than one interface in Java.
75 15 What will happen if a class extends two In this case, a conflict will arise because
interfaces and they both have a method the compiler will not able to link a
with same name and signature? method call due to ambiguity. You will
get a compile time error in Java.
76 16 Can we declare a class as Abstract Yes we can create an abstract class by
without having any abstract method? using abstract keyword before class name
even if it doesn't have any abstract
method. However, if a class has even one
abstract method, it must be declared as
abstract otherwise it will give an error.
77 17 What are Java Packages? What's the In Java, package is a collection of classes
significance of packages? and interfaces which are bundled
together as they are related to each
other. Use of packages helps developers
to modularize the code and group the
code for proper re-use. Once code has
been packaged in Packages, it can be
imported in other classes and used.
78 18 What's the difference between an Key difference in the use of abstract
Abstract Class and Interface in Java? classes and interfaces is that a class which
implements an interface must implement
all the methods of the interface while a
class which inherits from an abstract class
doesn't require implementation of all the
methods of its super class.A class can
implement multiple interfaces but it can
extend only one abstract class
79 19 What are the performance implications Interfaces are slower in performance as
of Interfaces over abstract classes? compared to abstract classes as extra
indirections are required for interfaces.
Another key factor for developers to take
into consideration is that any class can
extend only one abstract class while a
class can implement many interfaces.
80 20 Does Importing a package imports its In java, when a package is imported, its
sub-packages as well in Java? sub-packages aren't imported and
developer needs to import them
separately if required.
81 21 Can we pass argument to a function by In java, we can pass argument to a
reference instead of pass by value? function only by value and not by
reference.
82 22 Can a class have multiple constructors? Yes, a class can have multiple
constructors with different parameters.
Which constructor gets used for object
creation depends on the arguments
passed while creating the objects.
83 23 Abstract class must have only abstract False. Abstract methods can also have
methods. True or false? concrete methods.
84 24 Is it compulsory for a class which is Not necessarily. Abstract class may or
declared as abstract to have at least one may not have abstract methods.
abstract method?
85 25 Why final and abstract can not be used Because, final and abstract are totally
at a time? opposite in nature. A final class or
method can not be modified further
where as abstract class or method must
be modified further. “final” keyword is
used to denote that a class or method
does not need further improvements.
“abstract” keyword is used to denote that
a class or method needs further
improvements.
86 26 Can we declare abstract methods as No. Abstract methods can not be private.
private? Justify your answer? If abstract methods are allowed to be
private, then they will not be inherited to
sub class and will not get enhanced.
87 27 What is interface in java? Java interface is a blueprint of a class and
it is used to achieve fully abstraction and
it is a collection of abstract methods.
88 28 Can we achieve multiple inheritance by Yes, we can achieve multiple inheritance
using interface? through the interface in java but it is not
possible through class because java
doesn't support multiple inheritance
through class.
89 29 Can we create an object of an interface? No, we cannot create an object of
II interface.
90 30 Can an interface extend another Yes, an interface can extend another
interface? interface.
91 31 Which keyword java compiler add In an interface, Java compiler adds public,
before interface fields and methods? static and final keywords before fields or
data members and add public abstract
keywords before methods. In other
words, all the fields are public, static and
final and all the methods are public and
abstract by default in an interface.
92 32 What is Polymorphism in Java OOPs? Polymorphism in java is one of the core
concepts of object-oriented programming
system. Polymorphism means “many
forms” in Greek. That is one thing that
can take many forms.
93 33 What are the types of Polymorphism in There are two types of polymorphism in
Java? java. They are: Static polymorphism
(Compile time Polymorphism) and
Dynamic polymorphism (Runtime
Polymorphism)
94 34 How is Inheritance useful to achieve Inheritance represents the parent-child
Polymorphism in Java? relationship between two classes and
polymorphism take the advantage of that
relationship to add dynamic behavior in
the code (or to make the program more
dynamic).
95 35 What are the advantages of Using polymorphism, we can achieve
Polymorphism? flexibility in our code because we can
perform various operations by using
methods with the same names according
to requirements. And the main benefit of
using polymorphism is when we can
provide implementation to an abstract
base class or an interface.
96 36 What are the differences between Inheritance represents the parent-child
Polymorphism and Inheritance in Java? relationship between two classes. On the
other hand, polymorphism takes the
advantage of that relationship to make
the program more dynamic.Inheritance
helps in code reusability in child class
while polymorphism enables child class to
redefine already defined behavior inside
parent class
97 37 What is Compile time polymorphism A polymorphism where object binding
(Static polymorphism)? with methods happens at compile time is
called static polymorphism or compile-
time polymorphism.
98 38 What is Runtime Polymorphism A polymorphism where object binding
(Dynamic Polymorphism)? with methods happens at runtime is
called runtime polymorphism. In runtime
polymorphism, the behavior of a method
is decided at runtime.
99 39 How to achieve/implement dynamic Dynamic or runtime polymorphism can
polymorphism in Java? be achieved or implemented via method
overriding in java.
100 40 How to achieve/implement static Static polymorphism can be achieved or
polymorphism in Java? implemented via method overloading in
java.
101 41 What is method overriding in Java with Declaring a method in sub class which is
example? already present in parent class is known
as method overriding. Overriding is done
so that a child class can give its own
implementation to a method which is
already provided by the parent class.
102 42 What do you mean by method Method overloading allows a class to
overloading? define multiple methods with the same
name, but different signatures.
103 43 What is the difference between The difference between
multilevel inheritance and multiple Multiple and Multilevel inheritances is
inheritance? that Multiple Inheritance is when a
class inherits from many base classes
while Multilevel Inheritance is when a
class inherits from a derived class, making
that derived class a base class for a new
class
104 44 What is single inheritance in Java with Single Level inheritance - A
example? class inherits properties from
a single class. For example, Class
B inherits Class A
105 45 What is multiple inheritance in Java? Multiple Inheritance is a feature of object
oriented concept, where a class
can inherit properties of more than one
parent class.
106 46 Which part of the memory is involved in Heap
Garbage Collection? Stack or Heap?
107 47 What is responsiblity of Garbage Garbage collector frees the memory
Collector? occupied by the unreachable objects
during the java program by deleting these
unreachable objects.It ensures that the
available memory will be used efficiently.
108 48 Is garbage collector a daemon thread? Yes GC is a daemon thread. A daemon
thread runs behind the application. It is
started by JVM.
109 49 When does an object become eligible An object becomes eligible for Garbage
for garbage collection? Collection when no live thread can access
it.
110 50 What is the purpose of overriding The finalize() method should be
finalize() method? overridden for an object to include the
clean up code or to dispose of the system
resources that should to be done before
the object is garbage collected.
111 51 How many times does the garbage Only once.
collector calls the finalize() method for
an object?
112 52 What are different ways to call garbage Garbage collection can be invoked
collector? using System.gc() or Runtime.
getRuntime().gc().
113 53 Which package is imported, by default? By default, the ‘Java.lang’ the package is
imported, even without a package
declaration.
114 54 Can a class declare as private be No. once declared as private, it is not
accessed outside its package? possible to access the class outside its
package
115 55 What are the types of packages in Java? There are two types of packages in Java 1
Standard or Built-in packages and 2 User-
defined packages.
116 56 What is a user-defined package in Java? The packages which are created by the
users in the Java application development
are known as “user-defined package”.
117 57 Can we have a class with no Constructor Yes, we can have a class with no
in it ? What will happen during object constructor, When the compiler
creation ? encounters a class with no constructor
then it will automatically create a default
constructor for you.
118 58 Define Constructor? Java constructor is a unique method that
initializes the objects, which is called
when an instance of the class is created.
The memory for the object is allocated
when we call the constructor.
119 59 Can constructors be inherited in Java? No, constructors cannot be
inherited in Java.
120 60 What is the difference between actual The key difference between Acutal
parameter and formal parameter in Parameters and Formal Parameters is
Java? that Actual Parameters are the values
that are passed to the function when it is
invoked while Formal Parameters are the
variables defined by the function that
receives values when the function is
called.
121 1 What is String in Java? In Java, string is basically an object that
represents sequence of char values. An
array of characters works same as Java
string. For example:

char[] ch={'j','a','v','a','t','p','o','i','n','t'};
String s=new String(ch);
is same as:

String s="javatpoint";
122 2 Is String a data type in java? String is not a primitive data type in java.
When a string is created in java, it's
actually an object of Java.Lang.String
class that gets created. After creation of
this string object, all built-in methods of
String class can be used on the string
object.
123 3 In the below example, how many String In the above example, two objects of
Objects are created? Java.Lang.String class are created. s1 and
String s1="I am Java Expert"; s3 are references to same object.
String s2="I am C Expert";
String s3="I am Java Expert";
124 4 Why Strings in Java are called as In java, string objects are called
Immutable? immutable as once value has been
assigned to a string, it can't be changed
and if changed, a new object is created.

In below example, reference str refers to


a string object having value "Value one".

String str="Value One";


When a new value is assigned to it, a new
String object gets created and the
reference is moved to the new object.

str="New Value";
125 5 How to create a string object? There are two ways to create String
object:
1. By string literal
2. By new keyword
126 6 Is String a keyword in Java? No. String is not a keyword in Java. String
is a final class in java.lang package which
is used to represent the set of characters
in Java.
127 7 What is string constant pool? String objects are most used data objects
in Java. Hence, Java has a special
arrangement to store the string objects.
String Constant Pool is one such
arrangement. String Constant Pool is the
memory space in the heap memory
specially allocated to store the string
objects created using string literals. In
String Constant Pool, there will be no two
string objects having the same content.
Whenever you create a string object
using string literal, JVM first checks the
content of the object to be created. If
there exist an object in the string
constant pool with the same content,
then it returns the reference of that
object. It doesn’t create a new object. If
the content is different from the existing
objects then only it creates new object.
128 8 What is special about string objects as One special thing about string objects is
compared to objects of other derived that you can create string objects without
types? using new operator i.e using string
literals. This is not possible with other
derived types (except wrapper classes).
One more special thing about strings is
that you can concatenate two string
objects using ‘+’. This is the relaxation
Java gives to string objects as they will be
used most of the time while coding. And
also Java provides string constant pool to
store the string objects.
129 9 What do you mean by mutable and Immutable objects are like constants. You
immutable objects? can’t modify them once they are created.
They are final in nature. Where as
mutable objects are concerned, you can
perform modifications to them.
130 10 Which is the final class in these three All three are final.
classes – String, StringBuffer and
StringBuilder?
131 11 What is the difference between String, String vs StringBuilder vs StringBuffer in
StringBuffer and StringBuilder? Java
The differences between String,
StringBuffer, and StringBuilder are based
on the following two parameters:
1. Mutability
2. Performance
132 12 Why StringBuffer and StringBuilder The objects of String class are immutable
classes are introduced in Java when in nature. i.e you can’t modify them once
there already exist String class to they are created. If you try to modify
represent the set of characters? them, a new object will be created with
modified content. This may cause
memory and performance issues if you
are performing lots of string
modifications in your code. To overcome
these issues, StingBuffer and
StringBuilder classes are introduced in
Java.
133 13 How do you create mutable string Using StringBuffer and StringBuilder
objects? classes. These classes provide mutable
string objects
134 14 Which one will you prefer among “==” I prefer equals() method because it
and equals() method to compare two compares two string objects based on
string objects? their content. That provides more logical
comparison of two string objects. If you
use “==” operator, it checks only
references of two objects are equal or
not. It may not be suitable in all
situations. So, rather stick to equals()
method to compare two string objects.
135 15 Which class do you recommend among StringBuffer
String, StringBuffer and StringBuilder
classes if I want mutable and thread
safe objects?
136 16 How do you convert given string to char Using toCharArray() method.
array?
137 17 What is the main difference between In C and C++, strings are terminated with
Java strings and C, C++ strings? null character. But in Java, strings are not
terminated with null character. Strings
are treated as objects in Java.
138 18 Can we call String class methods usingYes, we can call String class methods
string literals? using string literals. Here are some
examples,
1. "abc".charAt(0)
2. "abc".compareTo("abc")
3. "abc".indexOf('c')
139 19 do you have any idea why strings have 1. Immutable strings increase security. As
been made immutable in Java? they can’t be modified once they are
created, so we can use them to store
sensitive data like username, password
etc.
2. Immutable strings are thread safe. So,
we can use them in a multi threaded
code without synchronization.
3. String objects are used in class loading.
If strings are mutable, it is possible that
wrong class is being loaded as mutable
objects are modifiable.
140 20 Write a java program to reverse a String str = "MyJava";
string? char[] strArray = str.toCharArray();
for (int i = strArray.length - 1; i >= 0; i--)
{
System.out.print(strArray[i]);
//Output : avaJyM
}
and have many more methods for
reverse of string
141 21 How Can We Split a String in Java? The String class itself provides us with the
String split method, which accepts a
regular expression delimiter. It returns us
a String[] array:
String[] parts = "john,peter,mary".split
(",");
assertEquals(new String[] { "john",
"peter", "mary" }, parts);
One tricky thing about split is that when
splitting an empty string, we may get a
non-empty array:
assertEquals(new String[] { "" }, "".split
(","));
142 22 How Can We Convert String to Integer The most straightforward approach to
and Integer to String in Java? convert a String to an Integer is by using
Integer parseInt:
int num = Integer.parseInt("22");
To do the reverse, we can use
Integer#toString:
String s = Integer.toString(num);
143 23 How Can We Convert a String to String implicitly provides String
Uppercase and Lowercase? toUpperCase to change the casing to
uppercase.
Though, the Javadocs remind us that we
need to specify the user's Locale to
ensure correctness:
String s = "Welcome to Baeldung!";
assertEquals("WELCOME TO
BAELDUNG!", s.toUpperCase(Locale.US));
Similarly, to convert to lowercase, we
have String toLowerCase:
String s = "Welcome to Baeldung!";
assertEquals("welcome to baeldung!", s.
toLowerCase(Locale.UK));
144 24 How Can We Get a Character Array from String provides toCharArray, which
String? returns a copy of its internal char array
pre-JDK9 (and converts the String to a
new char array in JDK9+):
char[] hello = "hello".toCharArray();
assertArrayEquals(new String[] { 'h', 'e',
'l', 'l', 'o' }, hello);
145 25 How Would We Convert a Java String By default, the method String getBytes()
into a Byte Array? encodes a String into a byte array using
the platform’s default charset.
And while the API doesn't require that we
specify a charset, we should in order to
ensure security and portability:
byte[] byteArray2 = "efgh".getBytes
(StandardCharsets.US_ASCII);
byte[] byteArray3 = "ijkl".getBytes("UTF-
8");
146 26 In what way can you perform String Concatenation is an operation used to
concatenation? merge two Strings into a new one. Basic
Strings can be concatenated simply by
using the + operator or by using .concat()
method, while StringBuffers and
StringBuilders achieve concatenation by
using .append() method.
147 27 How do you find the value of a The String class provides a method .
character at a specific position? charAt(int position) which returns a single
character. Which character will the
method return depends on the specified
argument 'position'.
148 28 Checking if String Contains Only Digits The easiest approach to check if the
String contains only digits is using the .
matches() method and providing a String
argument - "[0-9]+". The expected
argument should be a regex (Regular
Expression) to which the String is to be
matched - in our case regex represents
the numeric characters from 0 to 9!

String str = "09";

if (str.matches("[0-9]+")) {
System.out.println("String contains
only numbers.");
} else {
System.out.println("String doesn't
contain only numbers!");
}
149 29 Counting the Number of Words in a To accomplish this we should divide our
String String in smaller pieces (words) and use a
space character as a delimiter:

String str = "Java is an awesome


programming language!";
str = str.trim().replaceAll("\\s{2,}", " ");
String splitStr[] = str.split(" ");
System.out.println("The provided string '"
+ str + "' contains " + splitStr.length + "
words!");
150 30 What is the use of the substring() The substring() method in Java returns a
method? ‘substring’ of the specified string.
III
The creation of the substring depends on
the parameter passed to the substring()
method.

There are two variants of the Substring


method.

substring(int beginIndex)
substring(int beginIndex, int endIndex)
151 31 What are the ways to compare string? We can compare strings using the
equals() method, == operator and
compareTo() method.

When we compare strings using the


equals() method, we are comparing the
content of the strings, whether these
strings have the same content or not.

When we compare strings using the ==


operator, we are comparing the
reference of the string, whether these
variables are pointing to the same string
object or not.
152 32 How to check if the String is empty? Java String class has a special method to
check if the string is empty or not.

isEmpty() method internally checks if the


length of the string is zero. If it is zero,
that means the string is empty, and the
isEmpty() method will return true.

If the length of the string is not zero, then


the isEmpty() method will return false.
153 33 Can we use a string in switch case in Yes, from Java 7 we can use String in
java? switch case.

Below, I have given a program that shows


the use of the string in switch case.

Java
/*
* A Java program showing the use of
* String in switch case.
*/
public class StringInSwitchExample
{
public static void main(String[] args)
{
String str = "two";
switch(str)
{
case "one":
System.out.println("January");
break;
case "two":
System.out.println("February");
break;
case "three":
System.out.println("March");
break;
default:
System.out.println("Invalid
month number");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
* A Java program showing the use of
* String in switch case.
*/
public class StringInSwitchExample
{
public static void main(String[] args)
{
String str = "two";
switch(str)
{
case "one":
System.out.println("January");
break;
case "two":
System.out.println("February");
break;
case "three":
System.out.println("March");
break;
default:
System.out.println("Invalid
month number");
}
}
}
154 34 How to convert String to double in Java? Similar to Integer.parseInt() method
which is used to convert String to double,
you can use the Double.parseDouble()
method to convert a String to double
primitive value. If you want to learn
fundamentals like this, I also suggest
picking one of the Java Programming
courses for beginners from this list.
155 35 How to remove white space from String You can use the trim() method to remove
in Java? white space from String in Java.
156 36 How to remove or replace characters To replace or remove characters, use
from String? String.replace() or String.replaceAll().
These methods take two arguments. First
argument is character to be replaced, and
second argument is new character which
will be placed in string.
157 37 How to delete white space from You can use the deleteCharAt() method
StringBuffer in Java? to remove white space from StringBuffer
in Java.
158 38 How to delete string from StringBuffer You can use the delete(int,int) method to
in Java? remove string from StringBuffer in Java.
159 39 To print index of a char in string? using indexOf() method to print index of
a char
160 40 To print last index of a char in string? using lastIndexOf() method to print last
index of a char
161 41 How to compare two string on the basis You can use compareTo() method to
of unicode (DICTIONARY ORDER ) compare two string on the basis of
unicode (DICTIONARY ORDER )
162 42 What are the use of valueOf() method in valueOf() method is used to convert in-
java build datatytpe in string
163 43 How to check any string is end with a you can use endsWith() method to check
specific string any string is end with a specific string
164 44 How to check any string is start with a you can use startsWith() method to check
specific string any string is start with a specific string
165 45 How to return the current capacity of capacity() method is used to return the
StringBuffer current capacity of StringBuffer
166 46 How to ensure the capacity at least ensureCapacity(int minimumCapacity)
equal to the given minimum of method is used to ensure the capacity at
StringBuffer least equal to the given minimum of
StringBuffer
167 47 How to append the specified string with append() method is used to append the
this string specified string with this string
168 48 How to insert the specified string with insert(int offset, String s) method is used
this StringBuffer at the specified to insert the specified string with this
position StringBuffer at the specified position
169 49 To replace the StringBuffer from replace(int startIndex, int endIndex,
specified startIndex and endIndex. String str) method is used to replace the
StringBuffer from specified startIndex and
endIndex.
170 50 How to creates an empty string Builder StringBuilder() creates an empty string
with the initial capacity of 16. Builder with the initial capacity of 16.
171 51 How to creates a string Builder with the StringBuilder(String str) creates a string
specified string. Builder with the specified string.
172 52 How to creates an empty string Builder StringBuilder(int length) creates an empty
with the specified capacity as length. string Builder with the specified capacity
as length.
173 53 String[] split(String regex, int limit) String[] split(String regex, int limit)
method is used to? method is used to returns a split string
matching regex and limit.
174 54 compareTo() return 0 (zero) when? compareTo() return 0 (zero) when both
strings lexicographically (Unicode) are
equal
175 55 What will be the output of following H
program?
class StringBufferExample4{
public static void main(String args[]){
StringBuffer sb=new StringBuffer
("Hello");
sb.delete(1,6);
System.out.println(sb);
}
}
176 56 What will be the output of following Hello
program?
public class Main
{
public static void main(String[] args) {
String sb=new String("Hello");
sb.concat(" User");
System.out.println(sb);
}
}
177 57 What will be the output of following HELLO
program?
public class Main
{
public static void main(String[] args) {
String sb=new String("Hello");
sb=sb.toUpperCase();
System.out.println(sb);
}
}
178 58 What is the Output Of the following java
Program java programming
class demo1 {
public static void main(String args[])
{
String str1 = "java";
char arr[] = { 'j', 'a', 'v', 'a', ' ', 'p',
'r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g' };
String str2 = new String(arr);
System.out.println(str1);
System.out.println(str2);
}
}
179 59 What is the Output Of the following abcde
Program
class demo3 {
public static void main(String args[])
{
byte[] arr = { 97, 98, 99, 100, 101 };
String str2 = new String(arr);

System.out.println(str2);
}
}
180 60 What is the Output Of the following Java
Program
class demo5 {
public static void main(String args[])
{
String str = "Java Programming";
char arr[] = new char[10];
str.getChars(0, 4, arr, 0);
System.out.println(arr);
}
}
181 1 What Is an Exception? An exception is an abnormal event that
occurs during the execution of a program
and disrupts the normal flow of the
program's instructions.
182 2 What Is the Purpose of the Throw and The throws keyword is used to specify
Throws Keywords? that a method may raise an exception
during its execution. It enforces explicit
exception handling when callinf method.
The throw keyword allows us to throw an
exception object to interrupt the normal
flow of the program.
183 3 How Can You Handle an Exception? By using a try-catch-finally statement:
184 4 How Can You Catch Multiple A try block can be followed by one or
Exceptions? more catch blocks. Each catch block must
contain a different exception handler. So,
if you have to perform different tasks at
the occurrence of different exceptions,
use java multi-catch block.
185 5 What Is the Difference Between a A checked exception must be handled
Checked and an Unchecked Exception? within a try-catch block or declared in
a throws clause; whereas an unchecked
exception is not required to be handled
nor declared.
186 6 What Is the Difference Between an An exception is an event that represents
Exception and Error? a condition from which is possible to
recover, whereas error represents an
external situation usually impossible to
recover from
187 7 Is it possible to keep other statements It is not recommended to include any
in between ‘try’, ‘catch’, and ‘finally’ statements between the sections of ‘try’,
blocks? ‘catch’, and ‘finally’ blocks, since they
form one whole unit of the exception
handling mechanism.
188 8 Will it be possible to only include a ‘try’ This would give a compilation error. It is
block without the ‘catch’ and ‘finally’ necessary for the ‘try’ block to be
blocks? followed with either a ‘catch’ block or a
‘finally’ block, if not both. Either one of
‘catch’ or ‘finally’ blocks is needed so that
the flow of exception handling is
undisrupted.
189 9 Define OutOfMemoryError in Java. It is the sub class of java.lang.Error which
is encountered when the JVM runs out of
memory.
190 10 Does the ‘finally’ block get executed if The ‘finally’ block is always executed
either of ‘try’ or ‘catch’ blocks return irrespective of whether try or catch
the control? blocks are returning the control or not.
191 11 Is it possible to throw an exception It is possible to throw an exception
manually? If yes, explain how. manually. It is done using the ‘throw’
keyword.
192 12 What are some examples of checked ClassNotFoundException, SQLException,
exceptions? and IOException.
193 13 What are some examples of unchecked ullPointerException,
exceptions? ArrayIndexOutOfBoundsException and
NumberFormatException.
194 14 What is the difference between final, By declaring a variable as final, the value
finally and finalize in java? of final variable cannot be changed.
finally:
Used after try or try-catch block, will get
executed after the try and catch blocks
without considering whether an
exception is thrown or not. finalize:
Finalize method is the method that
Garbage Collector always calls just before
the deletion/destroying the object which
is no longer in use in the code.
195 15 What is a SQLException in Exception An exception that provides information
Handling? related to database access error or other
errors is called SQL Exception.
196 16 What is FileNotFound Exception in java It is compile time exception and it occurs
? when file to be read does not exist in
system.
197 17 What is NumberFormatException in NumberFormatException is thrown when
java? you try to convert a String into a number.
198 18 What is ArrayIndexOutOfBoundsException arises
ArrayIndexOutOfBoundsException in while trying to access an index of the
java? array that does not exist or out of the
bound of this array.
199 19 What will happen if an exception is When an exception is thrown by the main
thrown by the main method? method then JVM terminates the
program. As a result, you will find the
exception message and stack trace in the
system console.
200 20 What are the advantages of using Separating "regular" code from error
Exceptions in your programs? handling code. The ability to propagate
errors reporting up the call stack of
methods. Differentiating and grouping
error types.
201 21 What is exception propagation in java? Whenever methods are called stack is
formed and an exception is first thrown
from the top of the stack and if it is not
caught, it starts coming down the stack to
previous methods until it is not caught. If
exception remains uncaught even after
reaching bottom of the stack it is
propagated to JVM and program is
terminated in java.
202 22 What exception may occur by using Null Pointer Exception
following code?
String s=null;
System.out.println(s.length());
203 23 What exception may occur by using Number Format Exception
following code?
String s="abc";
IV int i= Integer.parseint(s);
204 24 What exception may occur by using ArrayIndexOutOfBoundsException
code-
int a[]=new int[5];
a[10]=50;
205 25 What is Thread in java? Thread are light weight process.
206 26 What is difference between Process and One process can have multiple Threads,
Thread in java? Thread are subdivision of Process
207 27 How to create Threads in java? by extending thread class or
implementing runnable interface.
208 28 How many method does runnable only one i.e run() method.
interface has?
209 29 We should implement Runnable Multiple inheritance in not allowed in
interface or extend Thread class. What java
are differences between implementing
Runnable and extending Thread?
210 30 What is difference between starting When you call start() method, main
thread with run() and start() method? thread internally calls run() method to
start newly created Thread, so run()
method is ultimately called by newly
created thread. When you call run()
method main thread rather than starting
run() method with newly thread it start
run() method by itself.
211 31 Can you again start Thread? o, we cannot start Thread again, doing so
will throw runtimeException java.lang.
IllegalThreadStateException. The reason
is once run() method is executed by
Thread, it goes into dead state.
212 32 What is life cycle of Thread New --> Runnable--> Running --> Waiting
---> Terminate
213 33 What are daemon threads? are low priority threads which runs
intermittently in background for doing
garbage collection.
214 34 What is significance of sleep() method in sleep() methods causes current thread to
detail, what statedoes it put thread in ? sleep for specified number of
milliseconds
215 35 What do you understand by inter- The process of communication between
thread communication? synchronized threads is termed as inter-
thread communication.
216 36 What are the advantages of Multithreading allows an
multithreading? application/program to be always
reactive for input, even already running
with some background tasks
217 37 What is context switching? In Context switching the state of the
process (or thread) is stored so that it can
be restored and execution can be
resumed from the same point later.
Context switching enables the multiple
processes to share the same CPU.
218 38 Differentiate between the Thread class By extending the Thread class, we cannot
and Runnable interface for creating a extend any other class, as Java does not
Thread? allow multiple inheritances while
implementing the Runnable interface; we
can also extend other base class
219 39 What does join() method? The join() method waits for a thread to
die. In other words, it causes the
currently running threads to stop
executing until the thread it joins with
completes its task.
220 40 Can we make the user thread as No, if you do so, it will throw
daemon thread if the thread is started? IllegalThreadStateException
221 41 What is Thread Scheduler in java? It selects the priority of the thread. It
determines the waiting time for a thread
222 42 How is the safety of a thread achieved? Synchronization , Using a lock based
mechanism
223 43 How we can set priority of thread By calling thread priority method
224 44 what does MIN_PRIORITY means? 1 as integer
225 45 What does MAX_PRIORITY means? 10
226 46 NORM_PRIORITY? 5
227 47 What is the default name given to Thread_0
threads by JVM
228 48 How can we set the name of threads? Thread.currentThrea().setName();
229 49 How can we find that current thread by using Thread.currentThread().
running is daemon thread or not? isDaemon();
230 50 How can we achieve multitasking? Process based Multitasking
(Multiprocessing) and thread based
multitasking i.e multithreading
231 51 The built-in base class in Java, which is Throwable
used to handle all exceptions is
232 52 In which package does exception class java.lang package
exist?
233 53 Which exception is thrown when a Arithmetic Exception
number is divided by zero?
234 54 What is synchronization? It is a technique of granting access to the
shared resources in multithread
environment to avoid inconsistencies in
the results.
235 55 What will happen if two thread of the It is dependent on the operating system
same priority are called to be processed
simultaneously?
236 56 Which method is used to wait for child Join ()
threads to finish in Java?
237 57 Thread synchronization in a process will All threads sharing the same address
be required when space, All threads sharing the same global
variables, All threads sharing the same
files
238 58 When does Exceptions in Java arises in Run Time
code sequence?
239 59 Which method restarts the thread A thread cant be restarted.
240 60 A thread can acquire a lock by using synchronized
which reserved keyword?
241 1 What is Stream? A stream is a sequence of objects that
supports various methods which can be
pipelined to produce the desired result.
242 2 Define Input Stream. The InputStream is used to read data
from a source.
243 3 Define Output Stream. The OutputStream is used for writing
data to a destination.
244 4 What are the types of I / O streams? There are two types of I / O streams: byte
and character.
245 5 What are the main ancestors of I/O java.io.InputStream,java.io.OutputStream
Streams?
246 6 What do you understand by an IO The stream is a sequence of data that
stream? flows from source to destination. It is
composed of bytes. In Java, three streams
are created for us automatically.

System.out: standard output stream


System.in: standard input stream
System.err: standard error stream
247 7 What are the FileInputStream and FileInputStream obtains input bytes from
FileOutputStream? a file in a file system.FileOutputStream is
an output stream used for writing data to
a file.
248 8 What is the purpose of using Java BufferedOutputStream class is used
BufferedInputStream and for buffering an output stream. It
BufferedOutputStream classes? internally uses a buffer to store data. It
adds more efficiency than to write data
directly into a stream. So, it makes the
performance fast. Whereas, Java
BufferedInputStream class is used to read
information from the stream. It internally
uses the buffer mechanism to make the
performance fast.
249 9 What is an applet? An applet is a small java program that
runs inside the browser and generates
dynamic content. It is embedded in the
webpage and runs on the client side.
250 10 What is the difference between InputStream is used to read data from
InputStream and OutputStream in Java? sources like File, Socket, or Console, while
OutputStream is used to write data into a
destination like a File, Socket, or Conole.

251 11 What is the difference between FileInputStream reads the file byte by
FileInputStream and FileReader in Java byte and FileReader reads the file
IO? character by character.
252 12 What is the difference between BufferedReader is a Decorator that
BufferedReader and FileReader in Java? provides buffering for faster IO, while
FileReader is used to read data from File.
253 13 What is the difference between Scanner is normally used when we know
BufferedReader and Scanner in Java? input is of type string or of primitive
types and BufferReader is used to read
text from character streams while
buffering the characters for efficient
reading of characters.
254 14 What is the use of the PrintStream class PrintStream is used to write data on
in Java IO? Console
255 15 Explain the life cycle of an Applet. init,start,paint,stop,destroy
256 16 What is the difference between an Applets are executed within a java
Applet and a Java Application ? enabled browser, but a Java application is
a standalone Java program that can be
executed outside of a browser.
257 17 What Is The Order Of Method public void init() : Initialization method
Invocation In An Applet? called once by browser.
► public void start() : Method called
after init() and contains code to start
processing. If the user leaves the page
and returns without killing the current
browser session, the start () method is
called without being preceded by init ().
► public void stop() : Stops all processing
started by start (). Done if user moves off
page.
► public void destroy() : Called if current
browser session is being terminated.
Frees all resources used by applet.
258 18 What Are The Applets Life Cycle methods in the life cycle of an Applet:
Methods? Explain Them? ► init() method - called when an applet
is first loaded. This method is called only
once in the entire cycle of an applet. This
method usually intialize the variables to
be used in the applet.
► start( ) method - called each time an
applet is started.
► paint() method - called when the
applet is minimized or refreshed. This
method is used for drawing different
strings, figures, and images on the applet
window.
► stop( ) method - called when the
browser moves off the applet’s page.
► destroy( ) method - called when the
browser is finished with the applet.
259 19 What Is The Sequence For Calling The ► init()
Methods By Awt For Applets? ► start()
► paint()
260 20 When An Applet Is Terminated, what is
the Sequence Of Method Calls Takes ► stop()
Place? ► destroy()
261 21 Can We Pass Parameters To An Applet We can pass parameters to an applet
From Html Page To An Applet? How? using <param> tag in the following way:
► <param name=”param1″ value=”
value1″>
► <param name=”param2″ value=”
value2″>
Access those parameters inside the
applet is done by calling getParameter()
method inside the applet. Note that
getParameter() method returns String
value corresponding to the parameter
name.
262 22 Which Classes And Interfaces Does Applet class consists of a single class, the
Applet Class Consist? Applet class and three interfaces:
AppletContext, AppletStub, and AudioClip
263 23 What Is Appletstub Interface? The applet stub interface provides the
means by which an applet and the
browser communicate. Your code will not
typically implement this interface.
264 24 What Are The Steps Involved In Applet ► Create/Edit a Java source file. This file
Development? must contain a class which extends
Applet class.
► Compile your program using javac
► Execute the appletviewer, specifying
the name of your applet’s source file or
html file. In case the applet information is
stored in html file then Applet can be
invoked using java enabled web browser.
265 25 Which Method Is Used To Output A
String To An Applet? Which Function Is drawString( )
This Method Included In?
266 26 What Is The Difference Between A AWT components re heavy weight,
Swing And Awt Components? whereas Swing components are
lightweight.
Heavy weight components depend on the
local windowing toolkit.
267 27 What Are The Different Types Of Labels, Pushbuttons, Checkboxes, Choice
Controls In Awt? lists, Lists, Scroll bars, Text components
268 28 What Are The Benefits Of Swing Over Swing components are light weight.
V Awt? We can have a pluggable look and feel
feature which shows us how they appear
in other platforms.
We can add images to Swing
components. We have toolbars and
tooltips in Swing.
269 29 What Are The Component And A component is a graphical object.
Container Class? A few examples of components are:
Button
Canvas
Checkbox
Choice etc.
270 30 What Is The Use Of The Window Class? The window class can be used to create a
plain, bare bones window that does not
have a border or menu.
The window class can also be used to
display introduction or welcome screens.
271 31 What Is Clipping? Clipping is the process of confining paint
operations to a limited area or shape.
272 32 What Is The Difference Between The The paint() method supports painting via
Paint() And Repaint() Method? a Graphics object.
The repaint() method is used o cause
paint() to be invoked by the AWT painting
thread.
273 33 What Interface Is Extended By Awt The java.util.EventListener interface is
Event Listener? extended by all the AWT event listeners.
274 34 What Is A Container In A Gui? A Container contains and arranges other
components through the use of layout
managers, which use specific layout
policies to determine where components
should go as a function of the size of the
container.
275 35 What Is The Default Layout For Applet? The default layout manager for an Applet
is FlowLayout, and the FlowLayout
manager attempts to honor the preferred
size of any components.

276 36 Name Components Subclasses That The Canvas


Support Painting? Frame
Panel and
Applet classes support painting
277 37 What Is The Difference Between A The CheckboxMenuItem class extends
Menuitem And A Checkboxmenuitem? the MenuItem class to support a menu
item that may be checked or unchecked.
278 38 How Are The Elements Of Different FlowLayout: The elements of a
Layouts Organized? FlowLayout are organized in a top to
bottom, left to right fashion.

Border Layout: The elements of a


BorderLayout are organized at the
borders and the centre of a container.

CardLayout: The elements of a


CardLayout are stacked, on the top of the
other, like a deck of cards.

GridLayout: The elements of a GridLayout


are equal size and are laid out using the
square of a grid.

GridBagLayout: The elements of a


GridBagLayout are organized according to
a grid.
279 39 What Is The Difference Between Grid Grid layout the size of each grid is
And Gridbaglayout? constant where as in GridbagLayout grid
size can varied.
280 40 What Is A Layout Manager? A layout manager is an object that is used
to organize components in a container.
281 41 Where The Cardlayout Is Used? CardLayout is used where we need to
have a bunch of panel or frames one
laying over another. It is replaced by
TabbedPane in Swing.
282 42 Which Container May Contain A Menu Frame
Bar?
283 43 What Are The Types Of Checkboxes? Exclusive and
Non exclusive
284 44 What Is Paint Method? The AWT uses a Callback mechanism for
painting which is the same for
heavyweight and lightweight
components.
285 45 What Is The Purpose Of Repaint repaint() requests can erase and redraw
Method? (update) after a small time display. When
you invoke repaint().
286 46 Which Containers Use A Border Layout Window Frame and Dialog classes use a
As Their Default Layout? Border Layout as their layout.
287 47 What Is Meant By Controls? Controls are components that allow a
user to interact with your application.
288 48 What Is The Difference Between Choice A choice is displayed in a compact from
And List? that requires you to pull it down to see
the list of available choices and only one
item may be selected from a choice.

A list may be displayed in such a way that


several list items are visible and it
supports the selection of one or more list
items.
289 49 What Is The Difference Between A The Frame class extends Window to
Window And A Frame? define a main application window that
can have a menu bar.
290 50 What Are The Subclasses Of The The container class has three major
Container Class? subclasses.
They are:
Window
Panel
ScrollPane
291 51 Which Method Is Method To Set The setLayout()
Layout Of A Container?
292 52 What Are The Default Layouts For A
Applet, A Frame And A Panel? For an applet and a panel, Flow layout,
and The FlowLayout manager attempts to
honor the preferred size of any
components.
293 53 Which Method Will Cause A Frame To .show()
Be Displayed? .setVisible()
294 54 Which Containers Use A Flowlayout As The Panel and the Applet classes use the
Their Default Layout? Flow Layout as their default layout.
295 55 What Are The Subclass Of TextField & TextArea
Textcomponent Class?
296 56 Define Frame The Frame is the container that contain
title bar and can have menu bars. It can
have other components like button,
textfield etc.
297 57 Difference between Frame and Applet Applets are java program which are
embedded in a website and meant to be
run in a web broswer. ... Applets don't
need a main method as their starting
point unlike frame based applications.
Frames on the other hand is a window
which is decorated that is contains border
, title ,the maximise minimise and close
buttons.
298 58 What Is Print Stream And Print Writer? Functionally both are same but belong to
two different categories – byte streams
and character streams. println() method
exists in both classes.
299 59 Can You Write A Java Class That Could Yes. Add a main() method to the applet.
Be Used Both As An Applet As Well As
An Application?
300 60 What Are The Attributes Of Applet height,width,etc..
Tags?

You might also like