SDTL Oral question bank

yoinkscreechedInternet και Εφαρμογές Web

13 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

119 εμφανίσεις


SDTL Oral question bank

1. What is the most important feature of Java?

Java is a platform independent language.

2. What do you mean by platform independence?

Platform independence means that we can write and compile the java code in one platform (eg
Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).

3. What is a JVM?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

4. Are JVM's platform independent?

JVM's are not pla
tform independent. JVM's are platform specific run time implementation
provided by the vendor.

5. What is the difference between a JDK and a JVM?

JDK is Java Development Kit which is for development purpose and it includes execution
environment also. But J
VM is purely a run time environment and hence you will not be able to
compile your source files using a JVM.

6. What is a pointer and does Java support pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to
mem
ory leaks and reliability issues hence Java doesn't support the usage of pointers.

7. What is the base class of all classes?

java.lang.Object

8. Does Java support multiple inheritance?

Java doesn't support multiple inheritance.

9. Is Java a pure object ori
ented language?

Java uses primitive data types and hence is not a pure object oriented language.

10. Are arrays primitive data types?

In Java, Arrays are objects.

11. What is difference between Path and Classpath?

Path and Classpath are operating system le
vel environment variales. Path is used define where
the system can find the executables(.exe) files and classpath is used to specify the location
.class files.

12. What are local variables?

Local varaiables are those which are declared within a block of
code like methods. Local
variables should be initialised before accessing them.

13. What are instance variables?

Instance variables are those which are defined at the class level. Instance variables need not be
initialized before using them as they are aut
omatically initialized to their default values.

14. How to define a constant variable in Java?

The variable should be declared as
static

and
final
. So only one copy of the variable exists for all
instances of the class and the value can't be changed also.

static final int PI = 2.14;

is an example for constant.

15. Should a main() method be compulsorily declared in all java classes?

No not required.
main()

method should be defined only if the source class is a java application.

16. What is the return type of

the main() method?

Main()

method doesn't return anything hence declared
void
.

17. Why is the main() method declared static?

main()

method is called by the JVM even before the instantiation of the class hence it is
declared as
static
.

18. What is the argue
ment of main() method?

main()

method accepts an array of String object as arguement.

19. Can a main() method be overloaded?

Yes. You can have any number of
main()

methods with different method signature and
implementation in the class.

20. Can a main() met
hod be declared final?

Yes. Any inheriting class will not be able to have it's own default
main()

method.

21. Does the order of public and static declaration matter in main() method?

No. It doesn't matter but
void

should always come before
main()
.

22. Can
a source file contain more than one class declaration?

Yes a single source file can contain any number of Class declarations but only one of the class
can be declared as
public
.

23. What is a package?

Package is a collection of related classes and interfac
es. package declaration should be first
statement in a java class.

24. Which package is imported by default?

java.lang package

is imported by default even without a package declaration.

25. Can a class declared as private be accessed outside it's package?

Not possible.

26. Can a class be declared as protected?

A class can't be declared as
protected
. only methods can be declared as
protected
.

27. What is the access scope of a protected method?

A
protected

method can be accessed by the classes within the same

package or by the
subclasses of the class in any package.

28. What is the purpose of declaring a variable as final?

A
final

variable's value can't be changed.
final

variables should be initialized before using them.

29. What is the impact of declaring a m
ethod as final?

A method declared as
final

can't be overridden. A sub
-
class can't have the same method
signature with a different implementation.

30. I don't want my class to be inherited by any other class. What should i do?

You should declared your class

as
final
. But you can't define your class as
final
, if it is an
abstract

class. A class declared as
final

can't be extended by any other class.

31. Can you give few examples of final classes defined in Java API?

java.lang.String, java.lang.Math

are
final

classes.

32. How is final different from finally and finalize()?

final

is a modifier which can be applied to a class or a method or a variable.
final

class can't be
inherited,
final

method can't be overridden and
final

variable can't be changed.


finally
is an exception handling code section which gets executed whether an exception is
raised or not by the try block code segment.


finalize()

is a method of Object class which will be executed by the JVM just before garbage
collecting object to give a final
chance for resource releasing activity.

33. Can a class be declared as static?

We can not declare top level class as static, but only inner class can be declared static.

public class Test

{


static class InnerClass


{


public static void Inn
erMethod()


{ System.out.println("Static Inner Class!"); }


}


public static void main(String args[])


{


Test.InnerClass.InnerMethod();


}

}

//output: Static Inner Class!

34. When will you define a method as static?

When a method needs to be accessed even before the creation of the object of the class then
we should declare the method as
static
.

35. What are the restriction imposed on a static method or a static block of code?

A static method should not refer to insta
nce variables without creating an instance and cannot
use "this" operator to refer the instance.

36. I want to print "Hello" even before main() is executed. How will you acheive that?

Print the statement inside a static block of code. Static blocks get exe
cuted when the class gets
loaded into the memory and even before the creation of an object. Hence it will be executed
before the
main()

method. And it will be executed only once.

37. What is the importance of static variable?

static variables are class lev
el variables where all objects of the class refer to the same variable.
If one object changes the value then the change gets reflected in all the objects.

38. Can we declare a static variable inside a method?

Static varaibles are class level variables and
they can't be declared inside a method. If declared,
the class will not compile.

39. What is an Abstract Class and what is it's purpose?

A Class which doesn't provide complete implementation is defined as an abstract class. Abstract
classes enforce abstrac
tion.

40. Can a abstract class be declared final?

Not possible. An abstract class without being inherited is of no use and hence will result in
compile time error.

41. What is use of a abstract variable?

Variables can't be declared as abstract. only classes and methods can be declared as
abstract
.

42. Can you create an object of an abstract class?

Not possible. Abstract classes can't be instantiated.

43. Can a abstract class be defined without any abstract

methods?

Yes it's possible. This is basically to avoid instance creation of the class.

44. Class C implements Interface I containing method m1 and m2 declarations. Class C has
provided implementation for method m2. Can i create an object of Class C?

No no
t possible.
Class C

should provide implementation for all the methods in the
Interface I
.
Since
Class C

didn't provide implementation for
m1

method, it has to be declared as
abstract
.
Abstract classes can't be instantiated.

45. Can a method inside a
Interface be declared as final?

No not possible. Doing so will result in compilation error.
public

and
abstract

are the only
applicable modifiers for method declaration in an
interface
.

46. Can an Interface implement another Interface?

Intefaces doesn't pr
ovide implementation hence a interface cannot implement another
interface.

47. Can an Interface extend another Interface?

Yes an Interface can inherit another Interface, for that matter an Interface can extend more
than one Interface.

48. Can a Class exten
d more than one Class?

Not possible. A Class can extend only one class but can implement any number of Interfaces.

49. Why is an Interface be able to extend more than one Interface but a Class can't extend
more than one Class?

Basically Java doesn't allow
multiple inheritance, so a Class is restricted to extend only one
Class. But an Interface is a pure abstraction model and doesn't have inheritance hierarchy like
classes(do remember that the base class of all classes is Object). So an Interface is allowed
to
extend more than one Interface.

50. Can an Interface be final?

Not possible. Doing so so will result in compilation error.

51. Can a class be defined inside an Interface?

Yes it's possible.

52. Can an Interface be defined inside a class?

Yes it's possib
le.

53. What is a Marker Interface?

An Interface which doesn't have any declaration inside but still enforces a mechanism.

54. Which object oriented Concept is achieved by using overloading and overriding?

Polymorphism.

55. Why does Java not support
operator overloading?

Operator overloading makes the code very difficult to read and maintain. To maintain code
simplicity, Java doesn't support operator overloading.

56. Can we define private and protected modifiers for variables in interfaces?

No.

57. Wh
at is Externalizable?

Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in
Compressed Format. It has two methods,
writeExternal(ObjectOuput out)

and
readExternal(ObjectInput in)

58. What modifiers are allowed f
or methods in an Interface?

Only
public

and
abstract

modifiers are allowed for methods in interfaces.

59. What is a local, member and a class variable?

Variables declared within a method are "local" variables.

Variables declared within the class i.e not wi
thin any methods are "member" variables (global
variables).

Variables declared within the class i.e not within any methods and are defined as "static" are
class variables.

60. What is an abstract method?

An abstract method is a method whose implementation
is deferred to a subclass.

61. What value does read() return when it has reached the end of a file?

The
read()

method returns
-
1

when it has reached the end of a file.

62. Can a Byte object be cast to a double value?

No, an object cannot be cast to a primi
tive value.

63. What is the difference between a static and a non
-
static inner class?

A non
-
static inner class may have object instances that are associated with instances of the
class's outer class. A static inner class does not have any object instances.

64. What is an object's lock and which object's have locks?

An object's lock is a mechanism that is used by multiple threads to obtain synchronized access
to the object. A thread may execute a synchronized method of an object only after it has
acquired th
e object's lock. All objects and classes have locks. A class's lock is acquired on the
class's Class object.

65. What is the % operator?

It is referred to as the modulo or remainder operator. It returns the remainder of dividing the
first operand by the se
cond operand.

66. When can an object reference be cast to an interface reference?

An object reference be cast to an interface reference when the object implements the
referenced interface.

67. Which class is extended by all other classes?

The Object class
is extended by all other classes.

68. Which non
-
Unicode letter characters may be used as the first character of an identifier?

The non
-
Unicode letter characters
$

and
_

may appear as the first character of an identifier

69. What restrictions are placed on
method overloading?

Two methods may not have the same name and argument list but different return types.

70. What is casting?

There are two types of casting, casting between primitive numeric types and casting between
object references. Casting between num
eric types is used to convert larger values, such as
double values, to smaller values, such as byte values. Casting between object references is used
to refer to an object by a compatible class, interface, or array type reference.

71. What is the return ty
pe of a program's main() method?

void.

72. If a variable is declared as private, where may the variable be accessed?

A private variable may only be accessed within the class in which it is declared.

73. What do you understand by private, protected and publ
ic?

These are accessibility modifiers.
Private

is the most restrictive, while
public

is the least
restrictive. There is no real difference between
protected

and the default type (also known as
package protected) within the context of the same package, howe
ver the protected keyword
allows visibility to a derived class in a different package.

74. What is Downcasting ?

Downcasting is the casting from a general to a more specific type, i.e. casting down the
hierarchy

75. What modifiers may be used with an inner

class that is a member of an outer class?

A (non
-
local) inner class may be declared as public, protected, private, static, final, or abstract.

76. How many bits are used to represent Unicode, ASCII, UTF
-
16, and UTF
-
8 characters?

Unicode requires 16 bits a
nd ASCII require 7 bits Although the ASCII character set uses only 7
bits, it is usually represented as 8 bits.

UTF
-
8 represents characters using 8, 16, and 18 bit patterns.

UTF
-
16 uses 16
-
bit and larger bit patterns.

77. What restrictions are placed on th
e location of a package statement within a source code
file?

A package statement must appear as the first line in a source code file (excluding blank lines
and comments).

78. What is a native method?

A native method is a method that is implemented in a lan
guage other than Java.

79. What are order of precedence and associativity, and how are they used?

Order of precedence determines the order in which operators are evaluated in expressions.
Associatity determines whether an expression is evaluated
left
-
to
-
right or right
-
to
-
left.

80. Can an anonymous class be declared as implementing an interface and extending a class?

An anonymous class may implement an interface or extend a superclass, but may not be
declared to do both.

81. What is the range of th
e char type?

The range of the
char

type is 0 to 2
16

-

1 (i.e. 0 to 65535.)

82. What is the range of the short type?

The range of the
short

type is
-
(2
15
) to 2
15

-

1. (i.e.
-
32,768 to 32,767)

83. Why isn't there operator overloading?

Because C++ has proven
by example that operator overloading makes code almost impossible
to maintain.

84. What does it mean that a method or field is "static"?

Static variables and methods are instantiated only once per class. In other words they are class
variables, not instanc
e variables. If you change the value of a static variable in a particular
object, the value of that variable changes for all instances of that class. Static methods can be
referenced with the name of the class rather than the name of a particular object of

the class
(though that works too). That's how library methods like
System.out.println()

work
. out is a
static field in the
java.lang.System class
.

85
. Is null a keyword?

The null value is not a keyword.

86. Which characters may be used as the second character of an identifier, but not as the first
character of an identifier?

The digits 0 through 9 may not be used as the first character of an identifier

but they may be
used after the first character of an identifier.

87. Is the ternary operator written x : y ? z or x ? y : z ?

It is written
x ? y : z
.

88. How is rounding performed under integer division?

The fractional part of the result is truncated. Th
is is known as rounding toward zero.

89. If a class is declared without any access modifiers, where may the class be accessed?

A class that is declared without any access modifiers is said to have package access. This means
that the class can only be acces
sed by other classes and interfaces that are defined within the
same package.

90. Does a class inherit the constructors of its superclass?

A class does not inherit constructors from any of its superclasses.

91. Name the eight primitive Java types.

The eigh
t primitive types are byte, char, short, int, long, float, double, and boolean.

92. What restrictions are placed on the values of each case of a switch statement?

During compilation, the values of each case of a
switch

statement must evaluate to a value that
can be promoted to an
int

value.

93. What is the difference between a while statement and a do while statement?

A
while

statement checks at the beginning of a loop to see whether the next loop iteration
should occur
. A
do while

statement checks at the end of a loop to see whether the next
iteration of a loop should occur. The
do while
statement will always execute the body of a loop
at least once.

94. What modifiers can be used with a local inner class?

A local inner
class may be
final

or
abstract
.

95. When does the compiler supply a default constructor for a class?

The compiler supplies a default constructor for a class if no other constructors are provided.

96. If a method is declared as protected, where may the meth
od be accessed?

A protected method may only be accessed by classes or interfaces of the same package or by
subclasses of the class in which it is declared.

97.What is the difference between method overriding and overloading?

Overriding is a method with the

same name and arguments as in a parent, whereas overloading
is the same method name but different arguments

98. To what value is a variable of the String type automatically initialized?

The default value of an String type is null.

99. What is the differen
ce between a field variable and a local variable?

A field variable is a variable that is declared as a member of a class. A local variable is a variable
that is declared local to a method.

100. How are this() and super() used with constructors?

this()

is u
sed to invoke a constructor of the same class.
super()

is used to invoke a superclass
constructor.

101. What does it mean that a class or member is final?

A final class cannot be inherited. A final method cannot be overridden in a subclass. A final field
c
annot be changed after it's initialized, and it must include an initializer statement where it's
declared.

102. What does it mean that a method or class is abstract?

An abstract class cannot be instantiated. Abstract methods may only be included in abstrac
t
classes. However, an abstract class is not required to have any abstract methods, though most
of them do. Each subclass of an abstract class must override the abstract methods of its
superclasses or it also should be declared abstract.

103. What is a tra
nsient variable?

Transient variable is a variable that may not be serialized.


Q:

Explain the life cycle methods of a Servlet.

A:

The javax.servlet.Servlet interface defines the three methods known as life
-
cycle method.

public void init(ServletConfig
config) throws ServletException

public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException

public void destroy()

First the servlet is constructed, then initialized wih the
init()

method.

Any request from client are h
andled initially by the
service()

method before delegating to the
doXxx()

methods
in the case of HttpServlet.


The servlet is removed from service, destroyed with the
destroy()

methid, then garbaged collected and
finalized.




TOP


Q:

What is the difference between the getRequestDispatcher(String path) method of
javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?

A:

The
getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface accepts parameter the
path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet.
If the path begins with a "/" it is i
nterpreted as relative to the current context root.


The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative
paths. All path must sart with a "/" and are interpreted as relative to curent context root.




TOP


Q:

Explain the directory structure of a web application.

A:

The directory structure of a web application consists of two parts.

A private
directory called WEB
-
INF

A public resource directory which contains public resource folder.


WEB
-
INF folder consists of

1. web.xml

2. classes directory

3. lib directory




TOP


Q:

What are the common mechanisms used for session tracking?

A:

Cookies

SSL sessions

URL
-

rewriting




TOP


Q:

Explain
ServletContext.

A:

ServletContext interface is a window for a servlet to view it's environment. A servlet can use this interface to
get information such as initialization parameters for the web applicationor servlet container's version. Every
web
application has one and only one ServletContext and is accessible to all active resource of that application.




TOP


Q:

What is preinitialization of
a servlet?

A:

A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when it receives a
request for that servlet first time. This is called lazy loading. The servlet specification defines the <load
-
on
-
startup> eleme
nt, which can be specified in the deployment descriptor to make the servlet container load and
initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is
called preloading or preinitializing a servlet.



[ Received from Amit Bhoir ]


TOP


Q:

What is the difference between Difference between doGet() and doPost()?

A:

A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation. A
request string for doGet() looks like the following:

http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN

doPost() method call doesn't need a long
text tail after a servlet name in a request. All parameters are stored in
a request itself, not in a request string, and it's impossible to guess the data transmitted to a servlet only
looking at a request string.



[ Received from Amit Bhoir ]


TOP


Q:

What is the difference between HttpServlet and GenericServlet?

A:

A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and
adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(),
doTrace() methods (HTTP 1.1).

Both these classe
s are abstract.



[ Received from Amit Bhoir ]


TOP


Q:

What is the difference between ServletContext and ServletConfig?

A:

ServletContext:
Defines a

set of methods that a servlet uses to communicate with its servlet container, for
example, to get the MIME type of a file, dispatch requests, or write to a log file.The ServletContext object is
contained within the ServletConfig object, which the Web serv
er provides the servlet when the servlet is
initialized



ServletConfig:

The object created after a servlet is instantiated and its default constructor is read. It is created
to pass initialization information to the servlet.



[ Received from Sivagopal
Balivada ]



1

Q

What is the difference between JSP and Servlets ?


A


JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only
supported protocol in JSP is HTTP. But a servlet can
support any protocol like HTTP, FTP, SMTP
etc.



2

Q

What is difference between custom JSP tags and beans?


A


Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body a
re
interpreted, and then group your tags into collections called tag libraries that can be used in
any number of JSP files. To use custom JSP tags, you need to define three separate
components: the tag handler class that defines the tag's behavior ,the tag

library descriptor file
that maps the XML element names to the tag implementations and the JSP file that uses the tag
library


JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes.
You use tags


Custom tags and bea
ns accomplish the same goals
--

encapsulating complex behavior into
simple and accessible forms. There are several differences:


Custom tags can manipulate JSP content; beans cannot. Complex operations can be reduced to
a significantly simpler form with cu
stom tags than with beans. Custom tags require quite a bit
more work to set up than do beans. Custom tags usually define relatively self
-
contained
behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP
page. Custom
tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x
versions.



3

Q

What are the different ways for session tracking?


A


Cookies, URL rewriting, HttpSession, Hidden fo
rm fields



4

Q

What mechanisms are used by a Servlet Container to maintain session
information?


A


Cookies, URL rewriting, and HTTPS protocol information are used to maintain session
information




5

Q

Difference between GET and POST


A


In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query
length is limited to 255 characters, not secure, faster, quick and e
asy. The data is submitted as
part of URL.


In POST data is submitted inside body of the HTTP request. The data is not visible on the URL
and it is more secure.




6

Q

What is session?


A


The
session is an object used by a servlet to track a user's interaction with a Web application
across multiple HTTP requests. The session is stored on the server.



7

Q

What is servlet mapping?


A


The
servlet mapping defines an association between a URL pattern and a servlet. The mapping
is used to map requests to Servlets.



8

Q

What is servlet context ?


A


The servlet context is an object that
contains a information about the Web application and
container.

Using the context, a servlet can log events, obtain URL references to resources, and
set and store attributes that other servlets in the context can use.



9

Q


What is a servlet ?


A


servlet is a java program that runs inside a web container.



10

Q

Can we use the constructor, instead of init(), to initialize servlet?


A


Yes. But y
ou will not get the servlet specific things from constructor. The original reason for
init() was that ancient versions of Java couldn’t dynamically invoke constructors with
arguments, so there was no way to give the constructor a ServletConfig. That no lon
ger applies,
but servlet containers still will only call your no
-
arg constructor. So you won’t have access to a
ServletConfig or ServletContext.



12

Q

How many JSP scripting elements are there and what are they?



A


There are three scripting language elements: declarations, scriptlets, expressions.



13

Q

How do I include static files within a JSP page?


A


Static resources should always be include
d using the JSP include directive. This way, the
inclusion is performed just once during the translation phase.




14

Q

How can I implement a thread
-
safe JSP page?


A


You can make your JSPs
thread
-
safe adding the directive <%@ page isThreadSafe="false" % >
within your JSP page.



15

Q

What is the difference in using request.getRequestDispatcher() and
context.getRequestDispatcher()?


A


In

request.getRequestDispatcher(path) in order to create it we need to give the relative path of
the resource. But in

context.getRequestDispatcher(path) in order to create it we need to give
the absolute path of the resource.



16


Q

What are the lifecycle of JSP?


A


When presented with JSP page the JSP engine does the following 7 phases.


Page translation:
-
page is parsed, and a java file which is a servlet is created.


Page compilation: page is compil
ed into a class file


Page loading : This class file is loaded.


Create an instance :
-

Instance of servlet is created


jspInit() method is called


_jspService is called to handle service calls


_jspDestroy is called to destroy it when the servlet is not re
quired.



17

Q

What are context initialization parameters?


A


Context initialization parameters are specified by the <context
-
param> in the web.xml file,
these are initialization parameter for the
whole application.


Q

How to get the context parameters and servlet init parameters?

To get the context param:

ServletContext application = getServletConfig().getServletContext();

String xxx = application.getInitParameter(“xxx”);


To get the servle
t init parameter:

Enumeration

enumeration

=

getServletConfig().getInitParameterNames();


while
(enumeration.hasMoreElements()){


pw.print(enumeration.nextElement()

+

"

"
);


}



18

Q

What is a Expression?


A


Expressions are act as place holders for language expression, expression is evaluated each time
the page is accessed. This will be included in the service method of the generated servlet.



19

Q

Wh
at is a Declaration?


A


It declares one or more variables or methods for use later in the JSP source file. A declaration
must contain at least one complete declarative statement. You can declare any number of
variables or methods within
one declaration tag, as long as semicolons separate them. The
declaration must be valid in the scripting language used in the JSP file. This will be included in
the declaration section of the generated servlet.



20

Q

W
hat is a Scriptlet?


A


A scriptlet can contain any number of language statements, variable or expressions that are
valid in the page scripting language. Within scriptlet tags, you can declare variables to use later
in the file, write exp
ressions valid in the page scripting language, use any of the JSP implicit
objects or any object declared with a <jsp:useBean>.

Generally a scriptlet can contain any java
code that are valid inside a normal java method. This will become the part of genera
ted
servlet's service method.

21

Q

What are the implicit objects?

A


Certain objects that are available for the use in JSP documents without being declared first.
These objects are parsed by the JSP engine and inserted into the genera
ted servlet. The implicit
objects are: request, response, pageContext, session, application, out, config, page, exception

22

Q

What's the difference between forward and sendRedirect?

A


forward is server side redirect and sendRedirect

is client side redirect. When you invoke a
forward request, the request is sent to another resource on the server, without the client being
informed that a different resource is going to process the request. This process occurs
completely with in the web
container And then returns to the calling method. When a
sendRedirect method is invoked, it causes the web container to return to the browser
indicating that a new URL should be requested. Because the browser issues a completely new
request any object that

are stored as request attributes before the redirect occurs will be lost.
This extra round trip a redirect is slower than forward. Client can disable sendRedirect.

23

Q

What are the different scopes available ?

A

page, request,
session, application

24

Q

Is JSP extensible ?

A


Yes, it is. JSP technology is extensible through the development of custom actions, or tags,
which are encapsulated in tag libraries.

25

Q

What's the Servlet Interface?

A


The central abstraction in the Servlet API is the Servlet interface. All servlets implement this
interface, either directly or, more commonly, by extending a class that implements it such as
HttpServlet.

26

Q

What are two different
types of Servlets ?

A


GenericServlet and HttpServlet. HttpServlet is used to implement HTTP protocol, where as
Generic servlet can implement any protocol.

27

Q

What is the life cycle of servlet?

A


Each servlet has the same li
fe cycle: first, the server loads and initializes the servlet by calling
the init method. This init() method will be executed only once during the life time of a servlet.
Then when a client makes a request, it executes the service method. finally it execut
es the
destroy() method when server removes the servlet.

28

Q

Can we call destroy() method on servlets from service method ?

A

Yes.

29

Q

What is the need of super.init (config) in servlets ?

A


Then only we will

be able to access the ServletConfig from our servlet. If there is no
ServletConfig our servlet will not have any servlet nature.

32

Q

Can we write a constructor for servlet ?

Yes. But the container will always call the default constructor o
nly. If default constructor is not
present , the container will throw an exception.

33

Q

What is the difference between <%@ include ...> (directive include) and
<jsp:include> ?

A


@ include is static include. It is inline inclusion. T
he contents of the file will get included on
Translation phase. It is something like inline inclusion. We cannot have a dynamic filename for
directive include. <jsp:include> is dynamic include. Here the included file will be processed as a
separate file an
d the response will be included. We can have a dynamic filename for
<jsp:include>. We can aslo pass parameters to <jsp:include

34

Q

Can I just abort processing a JSP?

A


Yes. You can put a return statement to abort JSP processing.

35


Q

What are the parameters for service method ?

A

ServletRequest and ServletResponse

36

Q

What are cookies ?

A


Cookies are small textual information that are stored on client computer. Cookies are used for
session tracking.

37

Q

How do I prevent the output of my JSP or Servlet pages from being cached by
the browser?

A


By setting appropriate HTTP header attributes we can prevent caching by the browser

<%

response.setHeader("Cache
-
Contro
l","no
-
store"); //HTTP 1.1

response.setHeader("Pragma","no
-
cache"); //HTTP 1.0

response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

38

Q

How to refer the "this" variable within a JSP page?

A


Under JSP 1.0, th
e page implicit object page is equivalent to "this", and returns a reference to
the servlet generated by the JSP page.

39

Q

How many JSP scripting elements and what are they?

A


There are three scripting elements in JSP . They are dec
larations, scriptlets, expressions.

40

Q

Can we implement an interface in JSP ?

A

No.


41

Q

What is the meaning of response has already been committed error?



A


You will get this error only w
hen you try to redirect a page after you already have flushed the
output buffer. This happens because HTTP specification force the header to be set up before
the lay out of the page can be shown. When you try to send a redirect status, your HTTP server
can
not send it right now if it hasn't finished to set up the header. Simply it is giving the error
due to the specification of HTTP 1.0 and 1.1




42

Q

How do I use a scriptlet to initialize a newly instanti
ated bean?



A


A jsp:useBean action may optionally have a body. If the body is specified, its contents will be
automatically invoked when the specified bean is instantiated (Only at the time of
instantiation.) Typically, the body will

contain scriptlets or jsp:setProperty tags to initialize the
newly instantiated bean, although you are not restricted to using those alone.




43

Q

What is JSP?



A


JSP is

a server side scripting technology. JSP allows Java as well as a few special tags to be
embedded into a web file (HTML/XML, etc). The suffix must ends with .jsp.




44

Q

What are JSP Actions?



A


JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can
dynamically insert a file, reuse JavaBeans components, forward the user to another page, or
generate HTML for the Java plugin. Available actions i
nclude:

jsp:include, jsp:useBean,
jsp:setProperty, jsp:getProperty, jsp:forward and Jsp: plugin




45

Q

What is the difference between ServletContext and ServletConfig?



A


The Se
rvletConfig gives the information about the servlet initialization parameters. The servlet
engine implements the ServletConfig interface in order to pass configuration information to a
servlet. The server passes an object that implements the ServletConfig
interface to the servlet's
init() method.

The ServletContext gives information about the container. The ServletContext interface
provides information to servlets regarding the environment in which they are running. It also
provides standard way for servlet
s to write events to a log file.




46

Q

How can a servlet refresh automatically?



A

We can use a client
-
side Refresh or Server Push







47

Q

What is Server side push?



A


Server Side push is useful when data needs to change regularly on the clients application or
browser, without intervention from client. The mechanism used is, when client fi
rst connects to
Server, then Server keeps the TCP/IP connection open.




48

Q

What is client side refresh?



A


The standard HTTP protocols ways of refreshing the page, which
is normally supported by all
browsers. <META HTTP
-
EQUIV="Refresh" CONTENT="5; URL=/servlet/MyServlet/"> This will
refresh the page in the browser automatically and loads the new data every 5 seconds.




49

Q


What is the Max amount of information that can be saved in a Session Object
?



A


There is no such limit on the amount of information that can be saved in a Session Object.

The
only limit is the Session ID length , wh
ich should not exceed more than 4K.




50

Q

Why should we go for inter servlet communication?



A


The three major reasons to use inter servlet communication are: a) Direct

servlet manipulation
-

allows to gain access to the other currently loaded servlets and perform certain tasks (through
the ServletContext object) b) Servlet reuse
-

allows the servlet to reuse the public methods of
another servlet. c) Servlet collaboratio
n
-

requires to communicate with each other by sharing
specific information (through method invocation)




51

Q

What is a output comment?



A


A comment that is sent to the c
lient in the viewable page source. The JSP engine handles an
output comment as un interpreted HTML text, returning the comment in the HTML output sent
to the client. You can see the comment by viewing the page source from your Web
browser.





52

Q

What is a Hidden Comment



A


Hidden Comments are JSP comments. A comments that documents the JSP page but is not sent
to the client. The JSP engine ignores a hidden comment, and does n
ot process any code within
hidden comment tags.



53

Q

What are the differences between a session and a cookie?



A


Session is stored in server but cookie stored in client. Session
should work regardless of the
settings on the client browser. There is no limit on the amount of data that can be stored on
session. But it is limited in cookie. Session can store objects and cookies can store only strings.
Cookies are faster than session.




54

Q

What is HttpTunneling?



A


HTTP tunneling is used to encapsulate other protocols within the HTTP or HTTPS protocols.
Normally the intranet is blocked by a firewal
l and the network is exposed to the outer world
only through a specific web server port, that listens for only HTTP requests. To use any other
protocol, that by passes the firewall, the protocol is embedded in HTTP and send as
HttpRequest.





55

Q

How to pass information from JSP to included JSP?



A

By using <jsp:param> tag.




56

Q

What is the better way to enable thread
-
s
afe servlets and JSPs?
SingleThreadModel Synchronization?



A


The better approach is to use synchronization. Because SingleThreadModel is not scalable.
SingleThreadModel is pretty resource intensive from web server's perspective. T
he most
serious issue is when the number of concurrent requests exhaust the servlet instance pool. In
that case, all the un serviced requests are queued until something becomes free
-

which results
in poor performance.





57

Q

What is the difference between ServletContext and PageContext?



A


ServletContext gives the information about the container and PageContext gives the
information about the Request




58

Q

Why in Servlet 2.4 specification SingleThreadModel has been deprecated?



A


SingleThreadModel is pretty resource intensive from web server's perspective. When the
number of co
ncurrent requests exhaust the servlet instance pool, all the un serviced requests
are queued until something becomes free
-

which results in poor performance.




59

Q

How do you pass data (including JavaBe
ans) to a JSP from a servlet?



A


By forwarding the request to the servlet ( the data must be there in the request scope) we can
pass the data from a JSP to servlet. Also we can use a session to pass the data.





60

Q

How can I set a cookie?



A

Cookie c = new Cookie("name","value");


response.addCookie(c);

61

Q

How will you delete a cookie?



A

Cookie c = new Cookie

("name", null);

c.setMaxAge(0);

response.addCookie(killCookie);




62

Q

What is the difference between Context init parameter and Servlet init
parameter?



A


Servlet init
parameters are for a single servlet only. No body out side that servlet can access
that. It is declared inside the <servlet> tag inside Deployment Descriptor, where as context init
parameter is for the entire web application. Any servlet or JSP in that web

application can
access context init parameter. Context parameters are declared in a tag <context
-
param>
directly inside the <web
-
app> tag. The methods for accessing context init parameter is
getServletContext ().getInitParamter (“name”) where as method fo
r accessing servlet init
parameter is getServletConfig ().getInitParamter (“name”);




63

Q

What are the different ways for getting a servlet context?



A


We will get ServletCont
ext by calling getServletConfig ().getServletContext (). This is because a
ServletConfig always hold a reference to ServletContext. By calling this.getServletContext () also
we will get a ServletContext object.




64

Q

What is the difference between an attribute and a parameter?



A


The return type of attribute is object, where the return type of parameter is String. The method
to retrieve attribute is getAttribute () where as
for parameter is getParamter (). We have a
method setAttribute to set an attribute. But there is no setters available for setting a
parameter.



65

Q

How to make a context thread safe?



A



Synchronizing the ServletContext is the only solution to make a ServletContext thread safe.

Eg: synchronized (getServletContext ()) {


// do whatever you want with thread safe context.

}




66

Q



What is the difference between setting the session time out in deployment descriptor and
setting the time out programmatically?



A


In DD time out is specified in terms of minutes only. But in programmatically it is specified

in
seconds. A session time out value of zero or less in DD means that the session will never expire.
To specify session will never expire programmatically it must be negative value.





67

Q

What JSP lifecycl
e methods we can override?



A


You cannot override the _jspService() method within a JSP page. You can however, override the
jspInit() and jspDestroy() methods within a JSP page.




68

Q


How will you include a static file in a JSP page?



A

You can include a static resource to a JSP using <jsp:directive > or <%@ inlcude
>.




69

Q

How you can perfo
rm browser redirection?



A


We can use the method sendRedirect of HttpServletResponse or forward method of
RequestDispatcher.




70

Q

Can we use

ServletOutputStream
object from a JSP page?



A


No. You are supposed to use JSPWriter object (given to you in the form of the implicit object
out) only for replying to clients.




71

Q

How can

you stop JSP execution in the middle of processing a request?



A


We can use the return statement to stop the processing of JSP. Because JSP is compiled to
servlet and all the statements will go inside service method, any tim
e you can stop the
processing using return statement.




72

Q


How can I invoke a JSP error page from a servlet?



A


You can invoke the JSP error page and pass the exception object to

it from within a servlet. For
that you need to create a request dispatcher for the JSP error page, and pass the exception
object as a javax.servlet.jsp.jspException request attribute.




73

Q

How w
ill you pass information from JSP to included JSP?



A

By using <%jsp:param> tag.




74

Q

How does JSP handle runtime exceptions?



A


Using errorPage att
ribute of page directive JSP handles runtime exceptions. We need to specify
isErrorPage=true if the current page is intended to use as a JSP error page.




75

Q


How can I enable session tracking for JSP

pages if the browser has disabled cookies?



A


By default session tracking uses cookies to associate a session identifier with a user. If the
browser does not support cookies, or if cookies are disabled, you can still use session track
ing
using URL rewriting. For URL rewriting to be effective, you need to append the session ID for
each and every link that is part of your servlet response. By using the methods
response.encodeURL() and response.encodeRedirectURL() we can achieve this.





76

Q

How can you declare methods in your JSP page?



A


You can declare methods as declarations in your JSP page. The methods can then be invoked
within any other methods yo
u declare, or within JSP scriptlets and expressions.




77

Q

How can we set the inactivity period on a per
-
session basis?



A


We can set the session time out programmatically
by using the method
setMaxInactiveInterval() of HttpSession.



78

Q

How do you pass an init parameter to a JSP?



A


You need to configure the DD for passing init parameter to a JSP. You
can configure the DD as
follows.

<servlet>


<servlet
-
name>test.jsp</servlet
-
name>


<jsp
-
file>test.jsp</jsp
-
name>


<init
-
param>


<param
-
name>Abc</param
-
name>


<param
-
value>Xyz</param
-
value>


</init
-
param
>

</servlet>




79

Q

How can my application get to know when a HttpSession is removed?


A


You can define a class which implements HttpSessionBindingListener and override the
valueUn
bound() method.




80

Q


How many cookies can one set in the response object of the servlet? Also, are there any
restrictions on the size of cookies?



A


If the client
is using Netscape, the browser can receive and store 300 total cookies and 4
kilobytes per cookie. And the no of cookie is restricted to 20 cookies per server or domain

81

Q


When a session object gets added or removed to the session, which e
vent will get notified
?



A


HttpSessionBindingListener will get notified When an object is added and/or removed from the
session object, or when the session is invalidated, in which case the objects are first removed
from the
session, whether the session is invalidated manually or automatically (timeout).




82

Q

What is URL Encoding and URL Decoding ?



A


URL encoding is the method of replacing all th
e spaces and other extra characters into their
corresponding Hex Characters and Decoding is the process of converting all Hex Characters
back to their normal form.




83

Q

What is the difference
between an applet and a servlet?


A


Servlets run inside a web server and applets run inside web browsers. Applets must have
graphical user interfaces whereas servlets have no graphical user interfaces.





84

Q

What are the different web servers available name few of them?


A

Tomcat, Java Web Server, JRun




85

Q

What is a Java Bean?



A


A Java Bean is a software component that has been designed to be reusable in a variety of
different environments.




86

Q

What are the different types of ServletEngines?



A


The d
ifferent types of ServletEngines available are:
-

Standalone ServletEngine: This is a server
that includes built
-
in support for servlets. Add
-
on ServletEngine: It is a plug
-
in to an existing
server. It adds servlet support to a server that was not originall
y designed with servlets in
mind.






87

Q

What is a Session Id?



A


It is a unique id assigned by the server to the user when a user starts a session.





88

Q

What is use of parseQueryString ?



A


It parses a query string and builds a Hashtable of key
-
value pairs, where the values are arrays of
strings. The query string should have the form of a string
packaged by the GET or POST
method.




89

Q

When init() and Distroy() will be called.


A


init() is called whenever the servlet is loaded for the first time into the web server.
Destroy will
be called whenever the servlet is removed from the web server.




90

Q

What is the use of setComment and getComment methods in Cookies ?


A


setComment: If a web brows
er presents this cookie to a user, the cookie's purpose will be
described using this comment. This is not supported by version zero cookies.

getComment: Returns the comment describing the purpose of this cookie, or null if no such
comment has been defined.




91

Q

Why we are used setMaxAge() and getMaxAge() in Cookies ?


A


setMaxAge : Sets the maximum age of the cookie. The cookie will expire after that many
seconds have passed. Negative v
alues indicate the default behavior, and will be deleted when
the browser closes.

getMaxAge : Returns the maximum specified age of the cookie. If none was specified, a
negative value is returned, indicating the default behavior described with setMaxAge.





92

Q

What is the use of setSecure() and getSecure() in Cookies ?



A


setSecure method indicates to the web browser that the cookie should only be sent using a
secure protoco
l (https). getSecure method returns the value of the 'secure' flag.



93

Q

How do you communicate between the servlets?



A


We can communicate between servlets by using RequestDes
patcher interface and servlet
chaining.




94

Q

What is Servlet chaining?



A


Servlet chaining is a technique in which two or more servlets can cooperate in servicing a sing
le
request. In servlet chaining, one servlet’s output is the input of next servlet. This process
continues until the last servlet is reached. Its output is then sent back to the client. We are
achieving Servlet Chaining with the help of RequestDispatcher.





95

Q


How will you communicate from an applet to servlet?



A


There are three ways to communicate from an applet to servlet and they are: HTTP
Communication (Text
-
based and
object
-
based) , Socket Communication and RMI
Communication




96

Q

Can we call a servlet with parameters in the URL?



A

Yes. You can call a servlet with parameters in the UR
L like ?param=value




97

Q

How do servlets handle multiple simultaneous requests?


A


When a request comes in, the web server will start a new thread and the request is assigned to
a thread, which calls a service method of the servlet.




98

Q

Explain the directory structure of a web application?



A


The directory structure of a web application consists of two
parts. A private directory called
WEB
-
INF and a public resource directory which contains files server to public. WEB
-
INF folder
consists of web.xml (the deployment descriptor), classes directory (where we keeps all our
classes and servlets) and lib directo
ry (where we keeps all our jar files). The public folder
contains the static resources of the web application.




99

Q

What is pre initialization of a servlet?



A


A container

doesn't initialize the servlets when it starts up. It initializes a servlet when it
receives a request for that servlet first time. This is called lazy loading. The servlet specification
defines the <load
-
on
-
startup> element, which can be specified in the

deployment descriptor to
make the servlet container load and initialize the servlet as soon as it starts up. The process of
loading a servlet before any request comes in is called preloading or pre initializing a servlet.





100

Q

What are the uses of ServletRequest?



A


The ServletRequest gives information such as the names of the parameters passed by the client,
the protocol (scheme) being used by the client, and the names of the re
mote host that made
the request and the server that received it. The input stream, ServletInputStream.

103

Q

Is HTML page a web component?


A

No. Static HTML pages and applets are not considered as web components by J2EE
spe
cification. Even the server
-
side utility classes are not considered web components.



104

Q

What is the container?


A

A container is a runtime support of a system
-
level entity. Containers provide
compon
ents with services such as lifecycle management, security, deployment, and threading.



105

Q

What is the web container?


A

Servlet and JSP containers are collectively referred to as Web containers.



106

Q

What is deployment descriptor?


A


A deployment descriptor is an XML based file which describes a web application's

deployment
settings. The name of deployment descriptor of a web application is

web.xml.




107

Q


How can I print the stack trace of an exception from a

JSP page?


A


By creating an object of PrintWriter we can print the stack trace in JSP page. Eg:

PrintWriter pw = response.getWr
iter();

exception.printStackTrace(pw);



108

Q

Do objects stored in a HTTP Session need to be serializable? Or can it store any
object?


A


No, the objects need not to be serializable. We can store any t
ype of objects in session.



109

Q

What is the differecnce between JspWriter and PrintWriter?


A

JspWriter is buffered.



110

Q


How can you implement singleton pattern

in servlets ?


A


All servlets are singleton only , if the servlet is not implementing SingleThreadModel.



111

Q

What is the difference between an application server and a web server?


A


Everything in web server must be achieved programmatically. But application server provides a
lot of services like security, transaction , scalability. Application server will be having EJB
support where web server don't have an EJB s
upport.



112

Q

What is servlet exception?


A

It indicates that there is an exception occurred in the servlet.



113

Q

Can we implement Runnable interface from within
our servlet?


A

Our servlet can implement the Runnable interface.



114

Q

What is a WAR file?


A


WAR stands for Web Archive. It is a compressed version of your web application. You ca
n use
this WAR file to deploy your web application.



115

Q

What is a servlet filter?


A


Servlet filters are pluggable Web components that allow us to implement pre
-
processing and
post
-
processing logic
in our Web applications.




1

Q








Why threads block or enters to waiting state on I/O?


A

Threads enters to waiting state or block on I/O because other threads can
execute while the I/O operations are performed
.




2

Q

What are transient variables in java?


A


Transient variables are variable that cannot be serialized.




3


Q

How Observer and Observable are used?


A


Subclass of Observable class maintain a list of observers. Whenever an Observable object is
updated, it invokes the update() method of each of its observers to notify
the observers that it
has a changed state. An observer is

any object that implements the interface Observer.





4

Q

What is synchronization


A


Synchronization is

the ability to control the access of multiple threads to shared resources.
Synchronization stops multithreading. With synchronization , at

a time only one thread will be
able to access a shared resource.




5


Q

What is List interface ?


A

List is an ordered collection of objects.




6

Q

What is a Vector


A

Vector is a grow

able array of objects.




7

Q

What is the difference between yield() and sleep()?


A


When a object invokes yield() it returns to ready state. But when an object i
nvokes sleep()
method enters to not ready state.




8

Q

What are Wrapper Classes ?


A

They are wrappers to primitive data types. They allow us to access
primitives

as objects.




9

Q

Can we call finalize() method ?


A

Yes.

Nobody will stop us to call any method , if it is accessible in our class.
But a garbage collector can
not call an object's finalize method if that object is reachable.




10

Q


What is the difference between

time slicing and

preemptive scheduling ?


A


In preemptive
scheduling, highest priority task continues execution till it enters a not running
state or a higher priority task comes into existence. In time slicing, the task continues its
execution for a predefined period of time and reenters the pool of ready tasks.





11

Q

What is the initial state of a thread when it is created and started?


A

The thread is in ready state.




12

Q

Can we declare an anonymous class as both extending a class and
implementing an interface?


A


No. An anonymous class can extend a class or implement an interface, but it cannot be declared
to d
o both




13

Q

What are the differences between boolean && operator and

& operator


A


When an expression containing the & operator is evaluated, both operands are e
valuated. And
the & operator is applied to the operand. When an expression containing && operator is
evaluated, the first operand is evaluated. If the first operand returns a value of true then only
the second operand is evaluated otherwise the second part

will not get executed.

&& is also
called short cut and.




14

Q

What is the use of the finally block?


A


Finally is the block of code that executes always. The cod
e in finally block will execute even if an
exception is occurred. finally will not execute when the user calls System.exit().




15

Q

What is an abstract method ?


A


An abstract method is a method that don't have a body. It is declared with modifier abstract.

16

Q

what is a the difference between System.err and System.out


A


We can redirect System.out to another file but w
e cannot redirect System.err stream




17

Q

What are

the differences between an abstract class and an interface?


A


An abstract class can have concrete method, whic
h is not allowed in an interface. Abstract class
can have private or protected methods and variables and only public methods and variables are
allowed in interface. We can implement more than one interface , but we can extend only one
abstract class. Inter
faces provides loose coupling where as abstract class provides tight
coupling.




18

Q

What is the difference between synchronized block and synchronized
method ?


A


Synchronized blocks place locks for the specified block where as
synchronized methods place locks for the entire method.




19

Q

How can you force garbage collection in java?


A


You cannot force Garbage Collection, but you can request for it by calling the method
System.gc().

But it doesn't mean that Garbage Collection will start immediately. The garbage
collection is a low priority thread of JVM
.




20

Q

How can you call a constructor from another constructor ?


A

By using this() reference.




21

Q


How can you call the constructor of super class ?


A

By using super() syntax. 22

Q

What's the difference between normal
methods and constructors?


A


Constructors must have the sam
e name of the class and can not have a return type. They are
called only once,

while regular methods can be called whenever required. We cannot explicitly
call a constructor.




23

Q

What is the
use of packages in java ?


A


Packages are a way to organize files in java when a project consists of more than one module. It
helps in resolving name conflicts when different modules have classes with the same names.





24

Q

What must be the order of catch blocks when catching more than one
exception?


A


The sub classes must come first. Otherwise it will give a compile time error.





25

Q


How can we call a method or variable of the super class from child class ?


A


We can use super.method() or super.variable syntax for this purpose.





26

Q

If you are overriding equals() method of a class, what other methods you
might need to override ?


A

hashCode




27

Q

How can you create your own exception ?


A


Our class must extend either Exception or its sub class




28

Q

What is serialization ?



A


Serialization is the process of saving the state of an object.




29

Q

What is de
-
serialization?


A

De
-
serialization is the process o
f restoring the state of an object.




30

Q

What is externalizable ?


A


It is an interface that extends Serializable. It is having two different methods writeExterna
l() and
readExternal. This interface allows us to customize the output.


Does garbage collection guarantee that a program will not run out of memory?


A


Garbage collection does not guarantee that a program will not

run out of memory. It is also
possible for programs to create objects that are not subject to garbage collection. And there is
no guarantee that Garbage Collection thread will be executed.




32

Q


What is a native method?


A


A native method is a method that is implemented in a language other than Java.




33

Q

What are different type of exceptions in Java?



A


There are two types of exceptions in java. Checked exceptions and Unchecked exceptions. Any
exception that is is derived from Throwable and Exception is called checked exception except
RuntimeException and its sub classes.
The compiler will check whether the exception is caught
or not at compile time. We need to catch the checked exception or declare in the throws
clause.

Any exception that is derived from Error and RuntimeException is called unchecked
exception. We don't n
eed to explicitly catch a unchecked exception.


















































34

Q

Can we catch an error in our java program ?


A


Yes. We can . We can catch anything that is
derived from Throwable. Since Error is a sub class of
Throwable we can catch an error also.




35

Q

What is thread priority?


A


Thread Priority is an integer value t
hat identifies the relative order in which it should be
executed with respect to others. The thread priority values ranging from 1
-

10 and the default
value is 5. But if a thread have higher priority doesn't means that it will execute first. The thread
sch
eduling depends on the OS.