Verified Jobs Live
Question 1 of 10
00:00

Self-Rating:
\n\n\n\n\n\n\t

\n\n\t\t28 Comments\t\t\t\t\t so far »\n\t\t\t

\n\n\t
    \n\n\t\n\t\t
  1. \n\t\t

    Dhananjay said,

    \n\t\t\t\t

    Any application developed in JAVA and using native code will be plateform independent ?

    \n\n
    \n\t\t
  2. \n\n\t\t\n\t\n\t\t
  3. \n\t\t

    dhinesh said,

    \n\t\t\t\t

    Actually in java no operator overloading.but we are using increment(++) and
    \ndecrement(–) operator.this also operator overloading. why that contradiction?

    \n
    \n\t\t
  4. \n\n\t\t\n\t\n\t\t
  5. \n\t\t

    dhinesh said,

    \n\t\t\t\t

    Actually in java no operator overloading.but we are using increment(++) and
    \ndecrement(–-) operator.this also operator overloading. why that contradiction?

    \n
    \n\t\t
  6. \n\n\t\t\n\t\n\t\t
  7. \n\n\t\t

    KOtresh said,

    \n\t\t\t\t

    There is no operator overloading in JAVA, but operator + is used as arithmetic addition and concatination operator. why ? pls clarify this

    \n
    \n\t\t
  8. \n\n\t\t\n\t\n\t\t
  9. \n\t\t

    srinivasulu said,

    \n\t\t\t\t

    difference ServletContext and PageContext

    \n\n
    \n\t\t
  10. \n\n\t\t\n\t\n\t\t
  11. \n\t\t

    Kotresh said,

    \n\t\t\t\t

    Default Layout for Jframe(swings)?

    \n
    \n\t\t
  12. \n\n\t\t\n\t\n\t\t
  13. \n\n\t\t

    Ajay said,

    \n\t\t\t\t

    difference between Directive and action

    \n
    \n\t\t
  14. \n\n\t\t\n\t\n\t\t
  15. \n\t\t

    Siya said,

    \n\t\t\t\t

    I don’t know where this site has been all my life!!!It has clear answers to almost every question revolving around Java.Keep it up!

    \n\n
    \n\t\t
  16. \n\n\t\t\n\t\n\t\t
  17. \n\t\t

    Prabhakar Peri said,

    \n\t\t\t\t

    Hi all, this is the reply to questions 2,3, and 4.

    \n

    “Operator overloading is not available in Java” does not mean that there is no operator overloading in Java. It mean that the programmer cannot implement operator overloading. It is in built available in the language.

    \n

    Actually you cannot find any programming language without operator overloading. Strictly no programming language is excempted. Have a look at the following example.

    \n\n

    3 + 2
    \n2.5 + 3.0

    \n

    These two expressions can be processed by any language. The same + symbol is used to add two integral numbers as well as to add two real numbers. Is it not overloading? The + operator is overloaded to operate on integrals and real numbers. This applies to all languages.

    \n

    Hence, operator overloading is there in Java, but in built. It cannot be extended by the programmer as you can do in C++.

    ","explanation_html":"Key interviewer evaluation criteria: Accuracy of syntax, architectural trade-offs, and clarity of practical examples in Java.","code_snippet":"","code_language":"text","difficulty":"Advanced","views_count":260,"likes_count":15,"last_reviewed":"2026-10-16 20:40:36","status":"published","meta_title":null,"meta_desc":null,"created_at":"2026-10-17 00:00:00","updated_at":"2026-10-17 07:25:49","summary":"What is the difference between procedural and object-oriented programs? - a) In procedural program, programming logic follows certain procedures and the instructions are execute...","reading_time_mins":39,"evaluation_points":"[\"Explain trade-offs between memory, CPU, and network latency.\",\"Identify failure modes, boundary conditions, and scalability bottlenecks.\",\"Discuss caching strategies, data consistency models, and recovery.\"]","original_legacy_answer":"
      \n
    1. What is the difference between procedural and object-oriented programs?- a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code. b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in tu\n assures the security of the code.
    2. \n
    3. What are Encapsulation, Inheritance and Polymorphism?- Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.
    4. \n
    5. What is the difference between Assignment and Initialization?- Assignment can be done as many times as desired whereas initialization can be done only once.
    6. \n\n

      \n
    7. What is OOPs?- Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.
    8. \n
    9. What are Class, Constructor and Primitive data types?- Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
    10. \n
    11. What is an Object and how do you allocate memory to it?- Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.
    12. \n
    13. What is the difference between constructor and method?- Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.
    14. \n
    15. What are methods and how are they defined?- Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method retu\ns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.
    16. \n\n
    17. What is the use of bin and lib in JDK?- Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.
    18. \n
    19. What is casting?- Casting is used to convert the value of one type to another.
    20. \n
    21. How many ways can an argument be passed to a subroutine and explain them?- An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.
    22. \n
    23. What is the difference between an argument and a parameter?- While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.
    24. \n
    25. What are different types of access modifiers?- public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.
    26. \n
    27. What is final, finalize() and finally?- final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.
    28. \n\n
    29. What is UNICODE?- Unicode is used for inte\nal representation of characters and strings and it uses 16 bits to represent each other.
    30. \n
    31. What is Garbage Collection and how to call it explicitly?- When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.
    32. \n
    33. What is finalize() method?- finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.
    34. \n
    35. What are Transient and Volatile Modifiers?- Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
    36. \n
    37. What is method overloading and method overriding?- Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.
    38. \n
    39. What is difference between overloading and overriding?- a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method. b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass. c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass. d) Overloading must have different method signatures whereas overriding must have same signature.
    40. \n\n
    41. What is meant by Inheritance and what are its advantages?- Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.
    42. \n
    43. What is the difference between this() and super()?- this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.
    44. \n
    45. What is the difference between superclass and subclass?- A super class is a class that is inherited whereas sub class is a class that does the inheriting.
    46. \n
    47. What modifiers may be used with top-level class?- public, abstract and final can be used for top-level class.
    48. \n
    49. What are inner class and anonymous class?- Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.
    50. \n
    51. What is a package?- A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.
    52. \n\n
    53. What is a reflection package?- java. lang. reflect package has the ability to analyze itself in runtime.
    54. \n
    55. What is interface and its use?- Interface is similar to a class which may contain method’s signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for: a)Declaring methods that one or more classes are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship. c)Determining an object’s programming interface without revealing the actual body of the class.
    56. \n
    57. What is an abstract class?- An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.
    58. \n
    59. What is the difference between Integer and int?- a) Integer is a class defined in the java. lang package, whereas int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other. b) Integer can be used as an argument for a method that requires an object, whereas int can be used for calculations.
    60. \n
    61. What is a cloneable interface and how many methods does it contain?- It is not having any method because it is a TAGGED or MARKER interface.
    62. \n\n
    63. What is the difference between abstract class and interface?- a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.
    64. \n
    65. Can you have an inner class inside a method and what variables can you access?- Yes, we can have an inner class inside a method and final variables can be accessed.
    66. \n
    67. What is the difference between String and String Buffer?- a) String objects are constants and immutable whereas StringBuffer objects are not. b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.
    68. \n
    69. What is the difference between Array and vector?- Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.
    70. \n
    71. What is the difference between exception and error?- The exception class defines mild error conditions that your program encounters. Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing. The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.
    72. \n
    73. What is the difference between process and thread?- Process is a program in execution whereas thread is a separate path of execution in a program.
    74. \n\n
    75. What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?- Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class. wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state. notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.
    76. \n
    77. What is the class and interface in java to create thread and which is the most advantageous method?- Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.
    78. \n
    79. What are the states associated in the thread?- Thread contains ready, running, waiting and dead states.
    80. \n
    81. What is synchronization?- Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.
    82. \n
    83. When you will synchronize a piece of your code?- When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.
    84. \n
    85. What is deadlock?- When two threads are waiting each other and can’t precede the program is said to be deadlock.
    86. \n\n
    87. What is daemon thread and which method is used to create the daemon thread?- Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.
    88. \n
    89. Are there any global variables in Java, which can be accessed by other part of your program?- No, it is not the main method in which you define variables. Global variables is not possible because concept of encapsulation is eliminated here.
    90. \n
    91. What is an applet?- Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser.
    92. \n
    93. What is the difference between applications and applets?- a)Application must be run on local machine whereas applet needs no explicit installation on local machine. b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser. d)Application starts execution with its main method whereas applet starts execution with its init method. e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.
    94. \n
    95. How does applet recognize the height and width?- Using getParameters() method.
    96. \n
    97. When do you use codebase in applet?- When the applet class file is not in the same directory, codebase is used.
    98. \n\n
    99. What is the lifecycle of an applet?- init() method - Can be called when an applet is first loaded start() method - Can be called each time an applet is started. paint() method - Can be called when the applet is minimized or maximized. stop() method - Can be used when the browser moves off the applet’s page. destroy() method - Can be called when the browser is finished with the applet.
    100. \n
    101. How do you set security in applets?- using setSecurityManager() method
    102. \n
    103. What is an event and what are the models available for event handling?- An event is an event object that describes a state of change in a source. In other words, event occurs when an action is generated, like pressing button, clicking mouse, selecting a list, etc. There are two types of models for handling events and they are: a) event-inheritance model and b) event-delegation model
    104. \n
    105. What are the advantages of the model over the event-inheritance model?- The event-delegation model has two advantages over the event-inheritance model. They are: a)It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use. b)It performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.
    106. \n
    107. What is source and listener?- source : A source is an object that generates an event. This occurs when the inte\nal state of that object changes in some way. listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications.
    108. \n\n
    109. What is adapter class?- An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested. For example, the MouseMotionAdapter class has two methods, mouseDragged()and mouseMoved(). The signatures of these empty are exactly as defined in the MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged() .
    110. \n
    111. What is meant by controls and what are different types of controls in AWT?- Controls are components that allow a user to interact with your application and the AWT supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components. These controls are subclasses of Component.
    112. \n
    113. What is the difference between choice and list?- A Choice is displayed in a compact form 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.
    114. \n
    115. What is the difference between scrollbar and scrollpane?- A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.
    116. \n
    117. What is a layout manager and what are different types of layout managers available in java AWT?- A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.
    118. \n
    119. How are the elements of different layouts organized?- FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards. GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.
    120. \n\n
    121. Which containers use a Border layout as their default layout?- Window, Frame and Dialog classes use a BorderLayout as their layout.
    122. \n
    123. Which containers use a Flow layout as their default layout?- Panel and Applet classes use the FlowLayout as their default layout.
    124. \n
    125. What are wrapper classes?- Wrapper classes are classes that allow primitive types to be accessed as objects.
    126. \n
    127. What are Vector, Hashtable, LinkedList and Enumeration?- Vector : The Vector class provides the capability to implement a growable array of objects. Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects. LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations. Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this enumeration has more elements and nextElement method retu\ns successive elements of the series.
    128. \n
    129. What is the difference between set and list?- Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.
    130. \n
    131. What is a stream and what are the types of Streams and classes of the Streams?- A Stream is an abstraction that either produces or consumes information. There are two types of Streams and they are: Byte Streams: Provide a convenient means for handling input and output of bytes. Character Streams: Provide a convenient means for handling input & output of characters. Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream. Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.
    132. \n\n
    133. What is the difference between Reader/Writer and InputStream/Output Stream?- The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented.
    134. \n
    135. What is an I/O filter?- An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
    136. \n
    137. What is serialization and deserialization?- Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.
    138. \n
    139. What is JDBC?- JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications.
    140. \n
    141. What are drivers available?- a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver
    142. \n
    143. What is the difference between JDBC and ODBC?- a) OBDC is for Microsoft and JDBC is for Java applications. b) ODBC can’t be directly used with Java because it uses a C interface. c) ODBC makes use of pointers which have been removed totally from Java. d) ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required. e) ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms. f) JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.
    144. \n\n
    145. What are the types of JDBC Driver Models and explain them?- There are two types of JDBC Driver Models and they are: a) Two tier model and b) Three tier model Two tier model: In this model, Java applications interact directly with the database. A JDBC driver is required to communicate with the particular database management system that is being accessed. SQL statements are sent to the database and the results are given to user. This model is referred to as client/server configuration where user is the client and the machine that has the database is called as the server. Three tier model: A middle tier is introduced in this model. The functions of this model are: a) Collection of SQL statements from the client and handing it over to the database, b) Receiving results from database to the client and c) Maintaining control over accessing and updating of the above.
    146. \n
    147. What are the steps involved for making a connection with a database or how do you connect to a database?a) Loading the driver : To load the driver, Class. forName() method is used. Class. forName(”sun. jdbc. odbc. JdbcOdbcDriver”); When the driver is loaded, it registers itself with the java. sql. DriverManager class as an available database driver. b) Making a connection with database: To open a connection to a given database, DriverManager. getConnection() method is used. Connection con = DriverManager. getConnection (”jdbc:odbc:somedb”, “user”, “password”); c) Executing SQL statements : To execute a SQL query, java. sql. statements class is used. createStatement() method of Connection to obtain a new Statement object. Statement stmt = con. createStatement(); A query that retu\ns data can be executed using the executeQuery() method of Statement. This method executes the statement and retu\ns a java. sql. ResultSet that encapsulates the retrieved data: ResultSet rs = stmt. executeQuery(”SELECT * FROM some table”); d) Process the results : ResultSet retu\ns one row at a time. Next() method of ResultSet object can be called to move to the next row. The getString() and getObject() methods are used for retrieving column values: while(rs. next()) { String event = rs. getString(”event”); Object count = (Integer) rs. getObject(”count”);
    148. \n\n
    149. What type of driver did you use in project?- JDBC-ODBC Bridge driver (is a driver that uses native(C language) libraries and makes calls to an existing ODBC driver to access a database engine).
    150. \n
    151. What are the types of statements in JDBC?- Statement: to be used createStatement() method for executing single SQL statement PreparedStatement — To be used preparedStatement() method for executing same SQL statement over and over. CallableStatement — To be used prepareCall() method for multiple SQL statements over and over.
    152. \n
    153. What is stored procedure?- Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters.
    154. \n
    155. How to create and call stored procedures?- To create stored procedures: Create procedure procedurename (specify in, out and in out parameters) BEGIN Any multiple SQL statement; END; To call stored procedures: CallableStatement csmt = con. prepareCall(”{call procedure name(?,?)}”); csmt. registerOutParameter(column no. , data type); csmt. setInt(column no. , column name) csmt. execute();
    156. \n\n
    157. What is servlet?- Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.
    158. \n
    159. What are the classes and interfaces for servlets?- There are two packages in servlets and they are javax. servlet and
    160. \n
    161. What is the difference between an applet and a servlet?- a) Servlets are to servers what applets are to browsers. b) Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.
    162. \n
    163. What is the difference between doPost and doGet methods?- a) doGet() method is used to get information, while doPost() method is used for posting information. b) doGet() requests can’t send large amount of information and is limited to 240-255 characters. However, doPost()requests passes all of its data, of unlimited length. c) A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.
    164. \n
    165. What is the life cycle of a servlet?- Each Servlet has the same life cycle: a) A server loads and initializes the servlet by init () method. b) The servlet handles zero or more client’s requests through service() method. c) The server removes the servlet through destroy() method.
    166. \n\n
    167. Who is loading the init() method of servlet?- Web server
    168. \n
    169. What are the different servers available for developing and deploying Servlets?- a) Java Web Server b) JRun g) Apache Server h) Netscape Information Server i) Web Logic
    170. \n
    171. How many ways can we track client and what are they?- The servlet API provides two ways to track client state and they are: a) Using Session tracking and b) Using Cookies.
    172. \n
    173. What is session tracking and how do you track a user session in servlets?- Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are: a) User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized use\name and password. b) Hidden form fields - fields are added to an HTML form that are not displayed in the client’s browser. When the form containing the fields is submitted, the fields are sent back to the server. c) URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change. d) Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser. e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session. maxresidents property.
    174. \n
    175. What is Server-Side Includes (SSI)?- Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special inte\nal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include server-side includes must be stored with an . shtml extension.
    176. \n
    177. What are cookies and how will you use them?- Cookies are a mechanism that a servlet uses to have a client hold a small amount of state-information associated with the user. a) Create a cookie with the Cookie constructor: public Cookie(String name, String value) b) A servlet can send a cookie to the client by passing a Cookie object to the addCookie() method of HttpServletResponse: public void HttpServletResponse. addCookie(Cookie cookie) c) A servlet retrieves cookies by calling the getCookies() method of HttpServletRequest: public Cookie[ ] HttpServletRequest. getCookie().
    178. \n\n
    179. Is it possible to communicate from an applet to servlet and how many ways and how?- Yes, there are three ways to communicate from an applet to servlet and they are: a) HTTP Communication(Text-based and object-based) b) Socket Communication c) RMI Communication
    180. \n
    181. What is connection pooling?- With servlets, opening a database connection is a major bottleneck because we are creating and tearing down a new connection for every page request and the time taken to create connection will be more. Creating a connection pool is an ideal approach for a complicated servlet. With a connection pool, we can duplicate only the resources we need to duplicate rather than the entire servlet. A connection pool can also intelligently manage the size of the pool and make sure each connection remains valid. A number of connection pool packages are currently available. Some like DbConnectionBroker are freely available from Java Exchange Works by creating an object that dispenses connections and connection Ids on request. The ConnectionPool class maintains a Hastable, using Connection objects as keys and Boolean values as stored values. The Boolean value indicates whether a connection is in use or not. A program calls getConnection() method of the ConnectionPool for getting Connection object it can use; it calls retu\nConnection() to give the connection back to the pool.
    182. \n
    183. Why should we go for interservlet communication?- Servlets running together in the same server communicate with each other in several ways. The three major reasons to use interservlet 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 collaboration - requires to communicate with each other by sharing specific information (through method invocation)
    184. \n
    185. Is it possible to call servlet with parameters in the URL?- Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).
    186. \n
    187. What is Servlet chaining?- Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request. In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.
    188. \n\n
    189. How do servlets handle multiple simultaneous requests?- The server has multiple threads that are available to handle requests. When a request comes in, it is assigned to a thread, which calls a service method (for example: doGet(), doPost() and service()) of the servlet. For this reason, a single servlet object can have its service methods called by many threads at once.
    190. \n
    191. What is the difference between TCP/IP and UDP?- TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call. UDP is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.
    192. \n
    193. What is Inet address?- Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.
    194. \n
    195. What is Domain Naming Service(DNS)?- It is very difficult to remember a set of numbers(IP address) to connect to the Inte\net. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, www. mascom. com implies com is the domain name reserved for US commercial sites, moscom is the name of the company and www is the name of the specific computer, which is mascom’s server.
    196. \n
    197. What is URL?- URL stands for Uniform Resource Locator and it points to resource files on the Inte\net. URL has four components: http://www. address. com:80/index.html, where http - protocol name, address - IP address or host name, 80 - port number and index.html - file path.
    198. \n
    199. What is RMI and steps involved in developing an RMI object?- Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine. The steps involved in developing an RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the interfaces and their implementations with the java compiler d) Compile the server implementation with RMI compiler e) Run the RMI registry f) Run the application
    200. \n\n
    201. What is RMI architecture?- RMI architecture consists of four layers and each layer performs specific functions: a) Application layer - contains the actual object definition. b) Proxy layer - consists of stub and skeleton. c) Remote Reference layer - gets the stream of bytes from the transport layer and sends it to the proxy layer. d) Transportation layer - responsible for handling the actual machine-to-machine communication.
    202. \n
    203. what is UnicastRemoteObject?- All remote objects must extend UnicastRemoteObject, which provides functionality that is needed to make objects available from remote machines.
    204. \n
    205. Explain the methods, rebind() and lookup() in Naming class?- rebind() of the Naming class(found in java. rmi) is used to update the RMI registry on the server machine. Naming. rebind(”AddSever”, AddServerImpl); lookup() of the Naming class accepts one argument, the rmi URL and retu\ns a reference to an object of type AddServerImpl.
    206. \n
    207. What is a Java Bean?- A Java Bean is a software component that has been designed to be reusable in a variety of different environments.
    208. \n
    209. What is a Jar file?- Jar file allows to efficiently deploying a set of classes and their associated resources. The elements in a jar file are compressed, which makes downloading a Jar file much faster than separately downloading several uncompressed files. The package java. util. zip contains classes that read and write jar files.
    210. \n\n
    211. What is BDK?- BDK, Bean Development Kit is a tool that enables to create, configure and connect a set of set of Beans and it can be used to test Beans without writing a code.
    212. \n
    213. What is JSP?- JSP is a dynamic scripting capability for web pages that allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc). The suffix traditionally ends with .jsp to indicate to the web server that the file is a JSP files. JSP is a server side technology - you can’t do any client side validation with it. The advantages are: a) The JSP assists in making the HTML more functional. Servlets on the other hand allow outputting of HTML but it is a tedious process. b) It is easy to make a change and then let the JSP capability of the web server you are using deal with compiling it into a servlet and running it.
    214. \n
    215. What are JSP scripting elements?- JSP scripting elements lets to insert Java code into the servlet that will be generated from the current JSP page. There are three forms: a) Expressions of the form <%= expression %> that are evaluated and inserted into the output, b) Scriptlets of the form<% code %>that are inserted into the servlet’s service method, and c) Declarations of the form <%! Code %>that are inserted into the body of the servlet class, outside of any existing methods.
    216. \n\n
    217. What are JSP Directives?- A JSP directive affects the overall structure of the servlet class. It usually has the following form:<%@ directive attribute=”value” %> However, you can also combine multiple attribute settings for a single directive, as follows:<%@ directive attribute1=”value1″ attribute 2=”value2″ . . . attributeN =”valueN” %> There are two main types of directive: page, which lets to do things like import classes, customize the servlet superclass, and the like; and include, which lets to insert a file into the servlet class at the time the JSP file is translated into a servlet
    218. \n\n
    219. What are Predefined variables or implicit objects?- To simplify code in JSP expressions and scriptlets, we can use eight automatically defined variables, sometimes called implicit objects. They are request, response, out, session, application, config, pageContext, and page.
    220. \n
    221. What are JSP ACTIONS?- 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 include: jsp:include - Include a file at the time the page is requested. jsp:useBean - Find or instantiate a JavaBean. jsp:setProperty - Set the property of a JavaBean. jsp:getProperty - Insert the property of a JavaBean into the output. jsp:forward - Forward the requester to a newpage. Jsp: plugin - Generate browser-specific code that makes an OBJECT or EMBED
    222. \n
    223. How do you pass data (including JavaBeans) to a JSP from a servlet?- (1) Request Lifetime: Using this technique to pass beans, a request dispatcher (using either “include” or forward”) can be called. This bean will disappear after processing this request has been completed. Servlet: request. setAttribute(”theBean”, myBean); RequestDispatcher rd = getServletContext(). getRequestDispatcher(”thepage. jsp”); rd. forward(request, response); JSP PAGE:(2) Session Lifetime: Using this technique to pass beans that are relevant to a particular session (such as in individual user login) over a number of requests. This bean will disappear when the session is invalidated or it times out, or when you remove it. Servlet: HttpSession session = request. getSession(true); session. putValue(”theBean”, myBean); /* You can do a request dispatcher here, or just let the bean be visible on the next request */ JSP Page: 3) Application Lifetime: Using this technique to pass beans that are relevant to all servlets and JSP pages in a particular app, for all users. For example, I use this to make a JDBC connection pool object available to the various servlets and JSP pages in my apps. This bean will disappear when the servlet engine is shut down, or when you remove it. Servlet: GetServletContext(). setAttribute(”theBean”, myBean); JSP PAGE:
    224. \n\n
    225. How can I set a cookie in JSP?- response. setHeader(”Set-Cookie”, “cookie string”); To give the response-object to a bean, write a method setResponse (HttpServletResponse response) - to the bean, and in jsp-file:<% bean. setResponse (response); %>\n
    226. How can I delete a cookie with JSP?- Say that I have a cookie called “foo, ” that I set a while ago & I want it to go away. I simply: <% Cookie killCookie = new Cookie(”foo”, null); KillCookie. setPath(”/”); killCookie. setMaxAge(0); response. addCookie(killCookie); %>
    227. \n\n
    228. How are Servlets and JSP Pages related?- JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java and then compiled, loaded into the server and executed.
    229. \n
    \n
    \n\n\t\t\n\n\t\t
    \n\t\t\t\n\n\n
    \n\n
    \n\n \n \n \n \n
    \n\n\n\n
    \n\n\n\t

    \n\n\t\t28 Comments\t\t\t\t\t so far »\n\t\t\t

    \n\n\t
      \n\n\t\n\t\t
    1. \n\t\t

      Dhananjay said,

      \n\t\t\t\t

      Any application developed in JAVA and using native code will be plateform independent ?

      \n\n
      \n\t\t
    2. \n\n\t\t\n\t\n\t\t
    3. \n\t\t

      dhinesh said,

      \n\t\t\t\t

      Actually in java no operator overloading.but we are using increment(++) and
      \ndecrement(–) operator.this also operator overloading. why that contradiction?

      \n
      \n\t\t
    4. \n\n\t\t\n\t\n\t\t
    5. \n\t\t

      dhinesh said,

      \n\t\t\t\t

      Actually in java no operator overloading.but we are using increment(++) and
      \ndecrement(–-) operator.this also operator overloading. why that contradiction?

      \n
      \n\t\t
    6. \n\n\t\t\n\t\n\t\t
    7. \n\n\t\t

      KOtresh said,

      \n\t\t\t\t

      There is no operator overloading in JAVA, but operator + is used as arithmetic addition and concatination operator. why ? pls clarify this

      \n
      \n\t\t
    8. \n\n\t\t\n\t\n\t\t
    9. \n\t\t

      srinivasulu said,

      \n\t\t\t\t

      difference ServletContext and PageContext

      \n\n
      \n\t\t
    10. \n\n\t\t\n\t\n\t\t
    11. \n\t\t

      Kotresh said,

      \n\t\t\t\t

      Default Layout for Jframe(swings)?

      \n
      \n\t\t
    12. \n\n\t\t\n\t\n\t\t
    13. \n\n\t\t

      Ajay said,

      \n\t\t\t\t

      difference between Directive and action

      \n
      \n\t\t
    14. \n\n\t\t\n\t\n\t\t
    15. \n\t\t

      Siya said,

      \n\t\t\t\t

      I don’t know where this site has been all my life!!!It has clear answers to almost every question revolving around Java.Keep it up!

      \n\n
      \n\t\t
    16. \n\n\t\t\n\t\n\t\t
    17. \n\t\t

      Prabhakar Peri said,

      \n\t\t\t\t

      Hi all, this is the reply to questions 2,3, and 4.

      \n

      “Operator overloading is not available in Java” does not mean that there is no operator overloading in Java. It mean that the programmer cannot implement operator overloading. It is in built available in the language.

      \n

      Actually you cannot find any programming language without operator overloading. Strictly no programming language is excempted. Have a look at the following example.

      \n\n

      3 + 2
      \n2.5 + 3.0

      \n

      These two expressions can be processed by any language. The same + symbol is used to add two integral numbers as well as to add two real numbers. Is it not overloading? The + operator is overloaded to operate on integrals and real numbers. This applies to all languages.

      \n

      Hence, operator overloading is there in Java, but in built. It cannot be extended by the programmer as you can do in C++.

      ","category_name":"Java","category_slug":"java","answer":"
        \n
      1. What is the difference between procedural and object-oriented programs?- a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code. b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in tu\n assures the security of the code.
      2. \n
      3. What are Encapsulation, Inheritance and Polymorphism?- Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.
      4. \n
      5. What is the difference between Assignment and Initialization?- Assignment can be done as many times as desired whereas initialization can be done only once.
      6. \n\n

        \n
      7. What is OOPs?- Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.
      8. \n
      9. What are Class, Constructor and Primitive data types?- Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
      10. \n
      11. What is an Object and how do you allocate memory to it?- Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.
      12. \n
      13. What is the difference between constructor and method?- Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.
      14. \n
      15. What are methods and how are they defined?- Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method retu\ns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.
      16. \n\n
      17. What is the use of bin and lib in JDK?- Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.
      18. \n
      19. What is casting?- Casting is used to convert the value of one type to another.
      20. \n
      21. How many ways can an argument be passed to a subroutine and explain them?- An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.
      22. \n
      23. What is the difference between an argument and a parameter?- While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.
      24. \n
      25. What are different types of access modifiers?- public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.
      26. \n
      27. What is final, finalize() and finally?- final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.
      28. \n\n
      29. What is UNICODE?- Unicode is used for inte\nal representation of characters and strings and it uses 16 bits to represent each other.
      30. \n
      31. What is Garbage Collection and how to call it explicitly?- When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.
      32. \n
      33. What is finalize() method?- finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.
      34. \n
      35. What are Transient and Volatile Modifiers?- Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
      36. \n
      37. What is method overloading and method overriding?- Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.
      38. \n
      39. What is difference between overloading and overriding?- a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method. b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass. c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass. d) Overloading must have different method signatures whereas overriding must have same signature.
      40. \n\n
      41. What is meant by Inheritance and what are its advantages?- Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.
      42. \n
      43. What is the difference between this() and super()?- this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.
      44. \n
      45. What is the difference between superclass and subclass?- A super class is a class that is inherited whereas sub class is a class that does the inheriting.
      46. \n
      47. What modifiers may be used with top-level class?- public, abstract and final can be used for top-level class.
      48. \n
      49. What are inner class and anonymous class?- Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.
      50. \n
      51. What is a package?- A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.
      52. \n\n
      53. What is a reflection package?- java. lang. reflect package has the ability to analyze itself in runtime.
      54. \n
      55. What is interface and its use?- Interface is similar to a class which may contain method’s signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for: a)Declaring methods that one or more classes are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship. c)Determining an object’s programming interface without revealing the actual body of the class.
      56. \n
      57. What is an abstract class?- An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.
      58. \n
      59. What is the difference between Integer and int?- a) Integer is a class defined in the java. lang package, whereas int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other. b) Integer can be used as an argument for a method that requires an object, whereas int can be used for calculations.
      60. \n
      61. What is a cloneable interface and how many methods does it contain?- It is not having any method because it is a TAGGED or MARKER interface.
      62. \n\n
      63. What is the difference between abstract class and interface?- a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.
      64. \n
      65. Can you have an inner class inside a method and what variables can you access?- Yes, we can have an inner class inside a method and final variables can be accessed.
      66. \n
      67. What is the difference between String and String Buffer?- a) String objects are constants and immutable whereas StringBuffer objects are not. b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.
      68. \n
      69. What is the difference between Array and vector?- Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.
      70. \n
      71. What is the difference between exception and error?- The exception class defines mild error conditions that your program encounters. Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing. The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.
      72. \n
      73. What is the difference between process and thread?- Process is a program in execution whereas thread is a separate path of execution in a program.
      74. \n\n
      75. What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?- Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class. wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state. notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.
      76. \n
      77. What is the class and interface in java to create thread and which is the most advantageous method?- Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.
      78. \n
      79. What are the states associated in the thread?- Thread contains ready, running, waiting and dead states.
      80. \n
      81. What is synchronization?- Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.
      82. \n
      83. When you will synchronize a piece of your code?- When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.
      84. \n
      85. What is deadlock?- When two threads are waiting each other and can’t precede the program is said to be deadlock.
      86. \n\n
      87. What is daemon thread and which method is used to create the daemon thread?- Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.
      88. \n
      89. Are there any global variables in Java, which can be accessed by other part of your program?- No, it is not the main method in which you define variables. Global variables is not possible because concept of encapsulation is eliminated here.
      90. \n
      91. What is an applet?- Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser.
      92. \n
      93. What is the difference between applications and applets?- a)Application must be run on local machine whereas applet needs no explicit installation on local machine. b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser. d)Application starts execution with its main method whereas applet starts execution with its init method. e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.
      94. \n
      95. How does applet recognize the height and width?- Using getParameters() method.
      96. \n
      97. When do you use codebase in applet?- When the applet class file is not in the same directory, codebase is used.
      98. \n\n
      99. What is the lifecycle of an applet?- init() method - Can be called when an applet is first loaded start() method - Can be called each time an applet is started. paint() method - Can be called when the applet is minimized or maximized. stop() method - Can be used when the browser moves off the applet’s page. destroy() method - Can be called when the browser is finished with the applet.
      100. \n
      101. How do you set security in applets?- using setSecurityManager() method
      102. \n
      103. What is an event and what are the models available for event handling?- An event is an event object that describes a state of change in a source. In other words, event occurs when an action is generated, like pressing button, clicking mouse, selecting a list, etc. There are two types of models for handling events and they are: a) event-inheritance model and b) event-delegation model
      104. \n
      105. What are the advantages of the model over the event-inheritance model?- The event-delegation model has two advantages over the event-inheritance model. They are: a)It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use. b)It performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.
      106. \n
      107. What is source and listener?- source : A source is an object that generates an event. This occurs when the inte\nal state of that object changes in some way. listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications.
      108. \n\n
      109. What is adapter class?- An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested. For example, the MouseMotionAdapter class has two methods, mouseDragged()and mouseMoved(). The signatures of these empty are exactly as defined in the MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged() .
      110. \n
      111. What is meant by controls and what are different types of controls in AWT?- Controls are components that allow a user to interact with your application and the AWT supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components. These controls are subclasses of Component.
      112. \n
      113. What is the difference between choice and list?- A Choice is displayed in a compact form 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.
      114. \n
      115. What is the difference between scrollbar and scrollpane?- A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.
      116. \n
      117. What is a layout manager and what are different types of layout managers available in java AWT?- A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.
      118. \n
      119. How are the elements of different layouts organized?- FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards. GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.
      120. \n\n
      121. Which containers use a Border layout as their default layout?- Window, Frame and Dialog classes use a BorderLayout as their layout.
      122. \n
      123. Which containers use a Flow layout as their default layout?- Panel and Applet classes use the FlowLayout as their default layout.
      124. \n
      125. What are wrapper classes?- Wrapper classes are classes that allow primitive types to be accessed as objects.
      126. \n
      127. What are Vector, Hashtable, LinkedList and Enumeration?- Vector : The Vector class provides the capability to implement a growable array of objects. Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects. LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations. Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this enumeration has more elements and nextElement method retu\ns successive elements of the series.
      128. \n
      129. What is the difference between set and list?- Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.
      130. \n
      131. What is a stream and what are the types of Streams and classes of the Streams?- A Stream is an abstraction that either produces or consumes information. There are two types of Streams and they are: Byte Streams: Provide a convenient means for handling input and output of bytes. Character Streams: Provide a convenient means for handling input & output of characters. Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream. Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.
      132. \n\n
      133. What is the difference between Reader/Writer and InputStream/Output Stream?- The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented.
      134. \n
      135. What is an I/O filter?- An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
      136. \n
      137. What is serialization and deserialization?- Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.
      138. \n
      139. What is JDBC?- JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications.
      140. \n
      141. What are drivers available?- a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver
      142. \n
      143. What is the difference between JDBC and ODBC?- a) OBDC is for Microsoft and JDBC is for Java applications. b) ODBC can’t be directly used with Java because it uses a C interface. c) ODBC makes use of pointers which have been removed totally from Java. d) ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required. e) ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms. f) JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.
      144. \n\n
      145. What are the types of JDBC Driver Models and explain them?- There are two types of JDBC Driver Models and they are: a) Two tier model and b) Three tier model Two tier model: In this model, Java applications interact directly with the database. A JDBC driver is required to communicate with the particular database management system that is being accessed. SQL statements are sent to the database and the results are given to user. This model is referred to as client/server configuration where user is the client and the machine that has the database is called as the server. Three tier model: A middle tier is introduced in this model. The functions of this model are: a) Collection of SQL statements from the client and handing it over to the database, b) Receiving results from database to the client and c) Maintaining control over accessing and updating of the above.
      146. \n
      147. What are the steps involved for making a connection with a database or how do you connect to a database?a) Loading the driver : To load the driver, Class. forName() method is used. Class. forName(”sun. jdbc. odbc. JdbcOdbcDriver”); When the driver is loaded, it registers itself with the java. sql. DriverManager class as an available database driver. b) Making a connection with database: To open a connection to a given database, DriverManager. getConnection() method is used. Connection con = DriverManager. getConnection (”jdbc:odbc:somedb”, “user”, “password”); c) Executing SQL statements : To execute a SQL query, java. sql. statements class is used. createStatement() method of Connection to obtain a new Statement object. Statement stmt = con. createStatement(); A query that retu\ns data can be executed using the executeQuery() method of Statement. This method executes the statement and retu\ns a java. sql. ResultSet that encapsulates the retrieved data: ResultSet rs = stmt. executeQuery(”SELECT * FROM some table”); d) Process the results : ResultSet retu\ns one row at a time. Next() method of ResultSet object can be called to move to the next row. The getString() and getObject() methods are used for retrieving column values: while(rs. next()) { String event = rs. getString(”event”); Object count = (Integer) rs. getObject(”count”);
      148. \n\n
      149. What type of driver did you use in project?- JDBC-ODBC Bridge driver (is a driver that uses native(C language) libraries and makes calls to an existing ODBC driver to access a database engine).
      150. \n
      151. What are the types of statements in JDBC?- Statement: to be used createStatement() method for executing single SQL statement PreparedStatement — To be used preparedStatement() method for executing same SQL statement over and over. CallableStatement — To be used prepareCall() method for multiple SQL statements over and over.
      152. \n
      153. What is stored procedure?- Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters.
      154. \n
      155. How to create and call stored procedures?- To create stored procedures: Create procedure procedurename (specify in, out and in out parameters) BEGIN Any multiple SQL statement; END; To call stored procedures: CallableStatement csmt = con. prepareCall(”{call procedure name(?,?)}”); csmt. registerOutParameter(column no. , data type); csmt. setInt(column no. , column name) csmt. execute();
      156. \n\n
      157. What is servlet?- Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.
      158. \n
      159. What are the classes and interfaces for servlets?- There are two packages in servlets and they are javax. servlet and
      160. \n
      161. What is the difference between an applet and a servlet?- a) Servlets are to servers what applets are to browsers. b) Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.
      162. \n
      163. What is the difference between doPost and doGet methods?- a) doGet() method is used to get information, while doPost() method is used for posting information. b) doGet() requests can’t send large amount of information and is limited to 240-255 characters. However, doPost()requests passes all of its data, of unlimited length. c) A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.
      164. \n
      165. What is the life cycle of a servlet?- Each Servlet has the same life cycle: a) A server loads and initializes the servlet by init () method. b) The servlet handles zero or more client’s requests through service() method. c) The server removes the servlet through destroy() method.
      166. \n\n
      167. Who is loading the init() method of servlet?- Web server
      168. \n
      169. What are the different servers available for developing and deploying Servlets?- a) Java Web Server b) JRun g) Apache Server h) Netscape Information Server i) Web Logic
      170. \n
      171. How many ways can we track client and what are they?- The servlet API provides two ways to track client state and they are: a) Using Session tracking and b) Using Cookies.
      172. \n
      173. What is session tracking and how do you track a user session in servlets?- Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are: a) User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized use\name and password. b) Hidden form fields - fields are added to an HTML form that are not displayed in the client’s browser. When the form containing the fields is submitted, the fields are sent back to the server. c) URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change. d) Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser. e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session. maxresidents property.
      174. \n
      175. What is Server-Side Includes (SSI)?- Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special inte\nal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include server-side includes must be stored with an . shtml extension.
      176. \n
      177. What are cookies and how will you use them?- Cookies are a mechanism that a servlet uses to have a client hold a small amount of state-information associated with the user. a) Create a cookie with the Cookie constructor: public Cookie(String name, String value) b) A servlet can send a cookie to the client by passing a Cookie object to the addCookie() method of HttpServletResponse: public void HttpServletResponse. addCookie(Cookie cookie) c) A servlet retrieves cookies by calling the getCookies() method of HttpServletRequest: public Cookie[ ] HttpServletRequest. getCookie().
      178. \n\n
      179. Is it possible to communicate from an applet to servlet and how many ways and how?- Yes, there are three ways to communicate from an applet to servlet and they are: a) HTTP Communication(Text-based and object-based) b) Socket Communication c) RMI Communication
      180. \n
      181. What is connection pooling?- With servlets, opening a database connection is a major bottleneck because we are creating and tearing down a new connection for every page request and the time taken to create connection will be more. Creating a connection pool is an ideal approach for a complicated servlet. With a connection pool, we can duplicate only the resources we need to duplicate rather than the entire servlet. A connection pool can also intelligently manage the size of the pool and make sure each connection remains valid. A number of connection pool packages are currently available. Some like DbConnectionBroker are freely available from Java Exchange Works by creating an object that dispenses connections and connection Ids on request. The ConnectionPool class maintains a Hastable, using Connection objects as keys and Boolean values as stored values. The Boolean value indicates whether a connection is in use or not. A program calls getConnection() method of the ConnectionPool for getting Connection object it can use; it calls retu\nConnection() to give the connection back to the pool.
      182. \n
      183. Why should we go for interservlet communication?- Servlets running together in the same server communicate with each other in several ways. The three major reasons to use interservlet 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 collaboration - requires to communicate with each other by sharing specific information (through method invocation)
      184. \n
      185. Is it possible to call servlet with parameters in the URL?- Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).
      186. \n
      187. What is Servlet chaining?- Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request. In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.
      188. \n\n
      189. How do servlets handle multiple simultaneous requests?- The server has multiple threads that are available to handle requests. When a request comes in, it is assigned to a thread, which calls a service method (for example: doGet(), doPost() and service()) of the servlet. For this reason, a single servlet object can have its service methods called by many threads at once.
      190. \n
      191. What is the difference between TCP/IP and UDP?- TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call. UDP is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.
      192. \n
      193. What is Inet address?- Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.
      194. \n
      195. What is Domain Naming Service(DNS)?- It is very difficult to remember a set of numbers(IP address) to connect to the Inte\net. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, www. mascom. com implies com is the domain name reserved for US commercial sites, moscom is the name of the company and www is the name of the specific computer, which is mascom’s server.
      196. \n
      197. What is URL?- URL stands for Uniform Resource Locator and it points to resource files on the Inte\net. URL has four components: http://www. address. com:80/index.html, where http - protocol name, address - IP address or host name, 80 - port number and index.html - file path.
      198. \n
      199. What is RMI and steps involved in developing an RMI object?- Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine. The steps involved in developing an RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the interfaces and their implementations with the java compiler d) Compile the server implementation with RMI compiler e) Run the RMI registry f) Run the application
      200. \n\n
      201. What is RMI architecture?- RMI architecture consists of four layers and each layer performs specific functions: a) Application layer - contains the actual object definition. b) Proxy layer - consists of stub and skeleton. c) Remote Reference layer - gets the stream of bytes from the transport layer and sends it to the proxy layer. d) Transportation layer - responsible for handling the actual machine-to-machine communication.
      202. \n
      203. what is UnicastRemoteObject?- All remote objects must extend UnicastRemoteObject, which provides functionality that is needed to make objects available from remote machines.
      204. \n
      205. Explain the methods, rebind() and lookup() in Naming class?- rebind() of the Naming class(found in java. rmi) is used to update the RMI registry on the server machine. Naming. rebind(”AddSever”, AddServerImpl); lookup() of the Naming class accepts one argument, the rmi URL and retu\ns a reference to an object of type AddServerImpl.
      206. \n
      207. What is a Java Bean?- A Java Bean is a software component that has been designed to be reusable in a variety of different environments.
      208. \n
      209. What is a Jar file?- Jar file allows to efficiently deploying a set of classes and their associated resources. The elements in a jar file are compressed, which makes downloading a Jar file much faster than separately downloading several uncompressed files. The package java. util. zip contains classes that read and write jar files.
      210. \n\n
      211. What is BDK?- BDK, Bean Development Kit is a tool that enables to create, configure and connect a set of set of Beans and it can be used to test Beans without writing a code.
      212. \n
      213. What is JSP?- JSP is a dynamic scripting capability for web pages that allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc). The suffix traditionally ends with .jsp to indicate to the web server that the file is a JSP files. JSP is a server side technology - you can’t do any client side validation with it. The advantages are: a) The JSP assists in making the HTML more functional. Servlets on the other hand allow outputting of HTML but it is a tedious process. b) It is easy to make a change and then let the JSP capability of the web server you are using deal with compiling it into a servlet and running it.
      214. \n
      215. What are JSP scripting elements?- JSP scripting elements lets to insert Java code into the servlet that will be generated from the current JSP page. There are three forms: a) Expressions of the form <%= expression %> that are evaluated and inserted into the output, b) Scriptlets of the form<% code %>that are inserted into the servlet’s service method, and c) Declarations of the form <%! Code %>that are inserted into the body of the servlet class, outside of any existing methods.
      216. \n\n
      217. What are JSP Directives?- A JSP directive affects the overall structure of the servlet class. It usually has the following form:<%@ directive attribute=”value” %> However, you can also combine multiple attribute settings for a single directive, as follows:<%@ directive attribute1=”value1″ attribute 2=”value2″ . . . attributeN =”valueN” %> There are two main types of directive: page, which lets to do things like import classes, customize the servlet superclass, and the like; and include, which lets to insert a file into the servlet class at the time the JSP file is translated into a servlet
      218. \n\n
      219. What are Predefined variables or implicit objects?- To simplify code in JSP expressions and scriptlets, we can use eight automatically defined variables, sometimes called implicit objects. They are request, response, out, session, application, config, pageContext, and page.
      220. \n
      221. What are JSP ACTIONS?- 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 include: jsp:include - Include a file at the time the page is requested. jsp:useBean - Find or instantiate a JavaBean. jsp:setProperty - Set the property of a JavaBean. jsp:getProperty - Insert the property of a JavaBean into the output. jsp:forward - Forward the requester to a newpage. Jsp: plugin - Generate browser-specific code that makes an OBJECT or EMBED
      222. \n
      223. How do you pass data (including JavaBeans) to a JSP from a servlet?- (1) Request Lifetime: Using this technique to pass beans, a request dispatcher (using either “include” or forward”) can be called. This bean will disappear after processing this request has been completed. Servlet: request. setAttribute(”theBean”, myBean); RequestDispatcher rd = getServletContext(). getRequestDispatcher(”thepage. jsp”); rd. forward(request, response); JSP PAGE:(2) Session Lifetime: Using this technique to pass beans that are relevant to a particular session (such as in individual user login) over a number of requests. This bean will disappear when the session is invalidated or it times out, or when you remove it. Servlet: HttpSession session = request. getSession(true); session. putValue(”theBean”, myBean); /* You can do a request dispatcher here, or just let the bean be visible on the next request */ JSP Page: 3) Application Lifetime: Using this technique to pass beans that are relevant to all servlets and JSP pages in a particular app, for all users. For example, I use this to make a JDBC connection pool object available to the various servlets and JSP pages in my apps. This bean will disappear when the servlet engine is shut down, or when you remove it. Servlet: GetServletContext(). setAttribute(”theBean”, myBean); JSP PAGE:
      224. \n\n
      225. How can I set a cookie in JSP?- response. setHeader(”Set-Cookie”, “cookie string”); To give the response-object to a bean, write a method setResponse (HttpServletResponse response) - to the bean, and in jsp-file:<% bean. setResponse (response); %>\n
      226. How can I delete a cookie with JSP?- Say that I have a cookie called “foo, ” that I set a while ago & I want it to go away. I simply: <% Cookie killCookie = new Cookie(”foo”, null); KillCookie. setPath(”/”); killCookie. setMaxAge(0); response. addCookie(killCookie); %>
      227. \n\n
      228. How are Servlets and JSP Pages related?- JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java and then compiled, loaded into the server and executed.
      229. \n
      \n
      \n\n\t\t
    \n\n\t\t
    \n\t\t\t\n\n\n
    \n\n
    \n\n \n \n \n \n
    \n\n\n\n
    \n\n\n\t

    \n\n\t\t28 Comments\t\t\t\t\t so far »\n\t\t\t

    \n\n\t
      \n\n\t\n\t\t
    1. \n\t\t

      Dhananjay said,

      \n\t\t\t\t

      Any application developed in JAVA and using native code will be plateform independent ?

      \n\n
      \n\t\t
    2. \n\n\t\t\n\t\n\t\t
    3. \n\t\t

      dhinesh said,

      \n\t\t\t\t

      Actually in java no operator overloading.but we are using increment(++) and
      \ndecrement(–) operator.this also operator overloading. why that contradiction?

      \n
      \n\t\t
    4. \n\n\t\t\n\t\n\t\t
    5. \n\t\t

      dhinesh said,

      \n\t\t\t\t

      Actually in java no operator overloading.but we are using increment(++) and
      \ndecrement(–-) operator.this also operator overloading. why that contradiction?

      \n
      \n\t\t
    6. \n\n\t\t\n\t\n\t\t
    7. \n\n\t\t

      KOtresh said,

      \n\t\t\t\t

      There is no operator overloading in JAVA, but operator + is used as arithmetic addition and concatination operator. why ? pls clarify this

      \n
      \n\t\t
    8. \n\n\t\t\n\t\n\t\t
    9. \n\t\t

      srinivasulu said,

      \n\t\t\t\t

      difference ServletContext and PageContext

      \n\n
      \n\t\t
    10. \n\n\t\t\n\t\n\t\t
    11. \n\t\t

      Kotresh said,

      \n\t\t\t\t

      Default Layout for Jframe(swings)?

      \n
      \n\t\t
    12. \n\n\t\t\n\t\n\t\t
    13. \n\n\t\t

      Ajay said,

      \n\t\t\t\t

      difference between Directive and action

      \n
      \n\t\t
    14. \n\n\t\t\n\t\n\t\t
    15. \n\t\t

      Siya said,

      \n\t\t\t\t

      I don’t know where this site has been all my life!!!It has clear answers to almost every question revolving around Java.Keep it up!

      \n\n
      \n\t\t
    16. \n\n\t\t\n\t\n\t\t
    17. \n\t\t

      Prabhakar Peri said,

      \n\t\t\t\t

      Hi all, this is the reply to questions 2,3, and 4.

      \n

      “Operator overloading is not available in Java” does not mean that there is no operator overloading in Java. It mean that the programmer cannot implement operator overloading. It is in built available in the language.

      \n

      Actually you cannot find any programming language without operator overloading. Strictly no programming language is excempted. Have a look at the following example.

      \n\n

      3 + 2
      \n2.5 + 3.0

      \n

      These two expressions can be processed by any language. The same + symbol is used to add two integral numbers as well as to add two real numbers. Is it not overloading? The + operator is overloaded to operate on integrals and real numbers. This applies to all languages.

      \n

      Hence, operator overloading is there in Java, but in built. It cannot be extended by the programmer as you can do in C++.

      "},{"id":186,"category_id":5,"question":"Explain JVM Memory Architecture and the Evolution of Java Garbage Collectors (G1, ZGC, Parallel).","slug":"explain-jvm-memory-architecture-and-the-evolution-of-java-garbage-collectors-g1-zgc-parallel","answer_html":"

      The JVM Memory Structure is divided into:

      • Heap Memory: Shared among all threads, storing object instances. Divided into Young Generation (Eden space, Survivor spaces S0/S1) and Old Generation (Tenured).
      • Metaspace (Native Memory): Stores class metadata, bytecode, and method signatures (replaced PermGen in Java 8).
      • JVM Stacks: Thread-private, stores stack frames (local variables, operand stack).

      Garbage Collector Evolution:

      • Parallel GC: Multi-threaded collector focused on maximum application throughput; incurs Stop-The-World (STW) pauses.
      • G1 GC (Garbage-First): Default since Java 9. Divides heap into thousands of equal-sized regions. Prioritizes collecting regions with the most garbage to meet a target maximum pause time (-XX:MaxGCPauseMillis).
      • ZGC (Z Garbage Collector): Low-latency concurrent GC designed for multi-terabyte heaps with pause times consistently below 1 millisecond.
      ","explanation_html":"

      The Generational Hypothesis observes that most objects die young. Therefore, minor GC on Eden space is fast and reclaims the vast majority of ephemeral objects.

      ","code_snippet":"// Common JVM GC flags\n// java -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xms4g -Xmx4g MyApp\n// java -XX:+UseZGC -Xmx16g -jar myapp.jar","code_language":"bash","difficulty":"Advanced","views_count":120,"likes_count":0,"last_reviewed":"2026-10-17 12:12:09","status":"published","meta_title":null,"meta_desc":null,"created_at":"2026-10-17 12:12:09","updated_at":"2026-10-17 12:12:09","summary":"JVM separates heap into Young and Old generations based on weak generational hypothesis. G1 balances throughput with bounded pause times, while ZGC achieves sub-millisecond latency.","reading_time_mins":4,"evaluation_points":"1. Outlines Heap vs Metaspace vs Stack. 2. Explains Young/Old generation rationale. 3. Compares Parallel, G1, and ultra-low latency ZGC.","original_legacy_answer":null,"category_name":"Java","category_slug":"java","answer":"

      The JVM Memory Structure is divided into:

      • Heap Memory: Shared among all threads, storing object instances. Divided into Young Generation (Eden space, Survivor spaces S0/S1) and Old Generation (Tenured).
      • Metaspace (Native Memory): Stores class metadata, bytecode, and method signatures (replaced PermGen in Java 8).
      • JVM Stacks: Thread-private, stores stack frames (local variables, operand stack).

      Garbage Collector Evolution:

      • Parallel GC: Multi-threaded collector focused on maximum application throughput; incurs Stop-The-World (STW) pauses.
      • G1 GC (Garbage-First): Default since Java 9. Divides heap into thousands of equal-sized regions. Prioritizes collecting regions with the most garbage to meet a target maximum pause time (-XX:MaxGCPauseMillis).
      • ZGC (Z Garbage Collector): Low-latency concurrent GC designed for multi-terabyte heaps with pause times consistently below 1 millisecond.
      "},{"id":137,"category_id":5,"question":"Advanced Java Interview Questions and Answers","slug":"java-interview-questions-2","answer_html":"
      \"Java
      Java Interview Questions
      \n

      Please go through important Java Interview Questions, solve them if you can, share it with your friends and save as bookmark for future reference!

      \n

      Java Interview Questions:

      \nWhat is difference between JDK,JRE and JVM?\nJVM\nJVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the run-time environment in which java bytecode can be executed. It is a specification.\nJVMs are available for many hardware and software platforms (so JVM is platform dependent).\n\nJRE\nJRE stands for Java Runtime Environment. It is the implementation of JVM.\n\nJDK\nJDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools.\n\nWhat is JIT compiler?\nJust-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.\n\nWhy is Java Architectural Neutral?\nIts compiler generates an architecture-neutral object file format, which makes the compiled code to be executable on many processors, with the presence of Java runtime system\n\nMention some Java Keywords?\nSome Java Keywords are Import, Super, Finally etc.\n\nHow do you define a class?\nA Java class is a blue print from which individual objects are created. A class can contain fields and methods to describe the behavior of an object.\n\nWhat is a Local Variable, Instance Variable and Class variable?\nLocal Variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and it will be destroyed when the method has completed.\nInstance Variables: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded.\nClass Variables: These variables declared with in a class, outside any method, with the static keyword.\n\nDefault Byte type value in java?\nDefault value is 0.\n\nWhat is a static Variable?\nClass variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.\n\nWhat is a Classloader?\nA Class Loader is a subsystem of JVM that is used to load classes and interfaces. eg.: Bootstrap classloader, Extension classloader, System classloader, plugin classloader etc.\n\nExplain Runtume Polymorphism?\nRun time (Dynamic) polymorphism is the polymorphism existed at run-time. Here, Java compiler does not understand which method is called at compilation time. Only JVM decides which method is called at run-time. Method overloading and method overriding using instance methods are the examples for dynamic polymorphism.\n\nExplain static binding and dynamic binding?\nThe compiler only knows that the type of \"a\" is Animal ; this happens at compile time, because of which it is called static binding (Method overloading). But if it is dynamic binding then it would call the Monkey class method. Java uses static binding for overloaded methods and dynamic binding for overridden methods.\n1) Static binding in Java occurs during Compile time while Dynamic binding occurs during Runtime.\n2) private, final and static methods and variables uses static binding and bonded by compiler while virtual methods are bonded during runtime based upon runtime object.\n3) Static binding uses Type(Class in Java) information for binding while Dynamic binding uses Object to resolve binding.\n3) Overloaded methods are bonded using static binding while overridden methods are bonded using dynamic binding at runtime.\n\nWhat is a Constructor?\nConstructor is a block of code that allows you to create an object of class. This can also be called creating an instance. Constructor looks like a method but it’s not, for example methods can have any retu\n type or no retu\n type (considered as void) but constructors don’t have any retu\n type not even void.\n\nWhat are different types of constructors?\nDefault constructor\nNo-arg constructor\nParameterized Constructor\n\nHow to Call a constructor?\nTo call a constructor use the keyword new, followed by the name of class, followed by parameters if any. For example to create the object of class Mangoe, you can call the constructor like this: new Mangoe()\n\nWhat are access modifiers?\nAccess Modifiers are set to access levels for classes, variables, methods and constructors. There are four levels:\nVisible package (No modifiers needed here)\nVisible to class only (Private to class)\nVisible to world (Public)\nVisible to the package and all subclasses (Protected)\n\nParseInt() in Java?\nThe first argument is interpreted as representing a signed integer in the radix specified by the second argument, exactly as if the arguments were given to the parseInt(java.lang.String, int) method. The result is an Integer object that represents the integer value specified by the string\n\nCan we achieve runtime Polymorphism by data members?\nNo.\n\nWhat is Encapsulation and Abstraction?\nEncapsulation is hiding the implementation details which may or may not be for generic or specialized behaviors.\nAbstraction is the process of generalization: taking a concrete implementation and making it applicable to different, albeit somewhat related, types of data.\n\nCan we use abstract method and final both with a method?\nNo. Because final methods cannot be overridden.\n\nCan we instantiate abstract class?\nAbstract class can never be instantiated.\n\nWhat is the difference between StringBuffer and StringBuilder?\nThe difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.\n\nWhat is a finalize() method?\nFinalize() method is defined / called just before an objects final destruction by garbage collector, it is used to make sure that object terminates cleanly.\n\nWhat is interface in java?\nAn interface is a special form of an abstract class which does not implement any methods. In Java, you create an interface like this:\n\ninterface Interface\n{\nvoid interfaceMethod();\n}\n\nCan we declare an interface method as static?\nInterface methods is abstract by default and static and abstract keywords cannot be used together. Hence No.\n\nDifference between abstract class and interface class?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
      AbstractInterface
      Partial implementationWe don't know anything about implementation, just requirements
      It has an abstract method. An addition, it uses concreteEvery method is public and abstract by default
      No restriction for abstract class method modifiersIt is a 100% pure abstract class
      No restriction for abstract class variable modifiersIf we declare public we cannot declare private and protected
      No restriction to initialize variablesEvery interface has public, static and final
      A constructor is not allowedInstance and static block not allowed
      No restriction to initialize variablesEvery variable is static
      \nIs it possible to define Private and Protected modifiers variables in interfaces?\nThey both are implicitly public, hence no.\n\nWhat is a finally block?\nA Block that is finally is always executed.","explanation_html":"Key interviewer evaluation criteria: Accuracy of syntax, architectural trade-offs, and clarity of practical examples in Java.","code_snippet":"","code_language":"text","difficulty":"Advanced","views_count":978,"likes_count":65,"last_reviewed":"2026-10-16 20:40:36","status":"published","meta_title":null,"meta_desc":null,"created_at":"2026-10-17 00:00:00","updated_at":"2026-10-17 07:25:49","summary":"Java Interview Questions Please go through important Java Interview Questions, solve them if you can, share it with your friends and save as bookmark for future reference! Java ...","reading_time_mins":7,"evaluation_points":"[\"Explain trade-offs between memory, CPU, and network latency.\",\"Identify failure modes, boundary conditions, and scalability bottlenecks.\",\"Discuss caching strategies, data consistency models, and recovery.\"]","original_legacy_answer":"
      \"Java
      Java Interview Questions
      \n

      Please go through important Java Interview Questions, solve them if you can, share it with your friends and save as bookmark for future reference!

      \n

      Java Interview Questions:

      \nWhat is difference between JDK,JRE and JVM?\nJVM\nJVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the run-time environment in which java bytecode can be executed. It is a specification.\nJVMs are available for many hardware and software platforms (so JVM is platform dependent).\n\nJRE\nJRE stands for Java Runtime Environment. It is the implementation of JVM.\n\nJDK\nJDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools.\n\nWhat is JIT compiler?\nJust-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.\n\nWhy is Java Architectural Neutral?\nIts compiler generates an architecture-neutral object file format, which makes the compiled code to be executable on many processors, with the presence of Java runtime system\n\nMention some Java Keywords?\nSome Java Keywords are Import, Super, Finally etc.\n\nHow do you define a class?\nA Java class is a blue print from which individual objects are created. A class can contain fields and methods to describe the behavior of an object.\n\nWhat is a Local Variable, Instance Variable and Class variable?\nLocal Variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and it will be destroyed when the method has completed.\nInstance Variables: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded.\nClass Variables: These variables declared with in a class, outside any method, with the static keyword.\n\nDefault Byte type value in java?\nDefault value is 0.\n\nWhat is a static Variable?\nClass variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.\n\nWhat is a Classloader?\nA Class Loader is a subsystem of JVM that is used to load classes and interfaces. eg.: Bootstrap classloader, Extension classloader, System classloader, plugin classloader etc.\n\nExplain Runtume Polymorphism?\nRun time (Dynamic) polymorphism is the polymorphism existed at run-time. Here, Java compiler does not understand which method is called at compilation time. Only JVM decides which method is called at run-time. Method overloading and method overriding using instance methods are the examples for dynamic polymorphism.\n\nExplain static binding and dynamic binding?\nThe compiler only knows that the type of \"a\" is Animal ; this happens at compile time, because of which it is called static binding (Method overloading). But if it is dynamic binding then it would call the Monkey class method. Java uses static binding for overloaded methods and dynamic binding for overridden methods.\n1) Static binding in Java occurs during Compile time while Dynamic binding occurs during Runtime.\n2) private, final and static methods and variables uses static binding and bonded by compiler while virtual methods are bonded during runtime based upon runtime object.\n3) Static binding uses Type(Class in Java) information for binding while Dynamic binding uses Object to resolve binding.\n3) Overloaded methods are bonded using static binding while overridden methods are bonded using dynamic binding at runtime.\n\nWhat is a Constructor?\nConstructor is a block of code that allows you to create an object of class. This can also be called creating an instance. Constructor looks like a method but it’s not, for example methods can have any retu\n type or no retu\n type (considered as void) but constructors don’t have any retu\n type not even void.\n\nWhat are different types of constructors?\nDefault constructor\nNo-arg constructor\nParameterized Constructor\n\nHow to Call a constructor?\nTo call a constructor use the keyword new, followed by the name of class, followed by parameters if any. For example to create the object of class Mangoe, you can call the constructor like this: new Mangoe()\n\nWhat are access modifiers?\nAccess Modifiers are set to access levels for classes, variables, methods and constructors. There are four levels:\nVisible package (No modifiers needed here)\nVisible to class only (Private to class)\nVisible to world (Public)\nVisible to the package and all subclasses (Protected)\n\nParseInt() in Java?\nThe first argument is interpreted as representing a signed integer in the radix specified by the second argument, exactly as if the arguments were given to the parseInt(java.lang.String, int) method. The result is an Integer object that represents the integer value specified by the string\n\nCan we achieve runtime Polymorphism by data members?\nNo.\n\nWhat is Encapsulation and Abstraction?\nEncapsulation is hiding the implementation details which may or may not be for generic or specialized behaviors.\nAbstraction is the process of generalization: taking a concrete implementation and making it applicable to different, albeit somewhat related, types of data.\n\nCan we use abstract method and final both with a method?\nNo. Because final methods cannot be overridden.\n\nCan we instantiate abstract class?\nAbstract class can never be instantiated.\n\nWhat is the difference between StringBuffer and StringBuilder?\nThe difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.\n\nWhat is a finalize() method?\nFinalize() method is defined / called just before an objects final destruction by garbage collector, it is used to make sure that object terminates cleanly.\n\nWhat is interface in java?\nAn interface is a special form of an abstract class which does not implement any methods. In Java, you create an interface like this:\n\ninterface Interface\n{\nvoid interfaceMethod();\n}\n\nCan we declare an interface method as static?\nInterface methods is abstract by default and static and abstract keywords cannot be used together. Hence No.\n\nDifference between abstract class and interface class?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
      AbstractInterface
      Partial implementationWe don't know anything about implementation, just requirements
      It has an abstract method. An addition, it uses concreteEvery method is public and abstract by default
      No restriction for abstract class method modifiersIt is a 100% pure abstract class
      No restriction for abstract class variable modifiersIf we declare public we cannot declare private and protected
      No restriction to initialize variablesEvery interface has public, static and final
      A constructor is not allowedInstance and static block not allowed
      No restriction to initialize variablesEvery variable is static
      \nIs it possible to define Private and Protected modifiers variables in interfaces?\nThey both are implicitly public, hence no.\n\nWhat is a finally block?\nA Block that is finally is always executed.","category_name":"Java","category_slug":"java","answer":"
      \"Java
      Java Interview Questions
      \n

      Please go through important Java Interview Questions, solve them if you can, share it with your friends and save as bookmark for future reference!

      \n

      Java Interview Questions:

      \nWhat is difference between JDK,JRE and JVM?\nJVM\nJVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the run-time environment in which java bytecode can be executed. It is a specification.\nJVMs are available for many hardware and software platforms (so JVM is platform dependent).\n\nJRE\nJRE stands for Java Runtime Environment. It is the implementation of JVM.\n\nJDK\nJDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools.\n\nWhat is JIT compiler?\nJust-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.\n\nWhy is Java Architectural Neutral?\nIts compiler generates an architecture-neutral object file format, which makes the compiled code to be executable on many processors, with the presence of Java runtime system\n\nMention some Java Keywords?\nSome Java Keywords are Import, Super, Finally etc.\n\nHow do you define a class?\nA Java class is a blue print from which individual objects are created. A class can contain fields and methods to describe the behavior of an object.\n\nWhat is a Local Variable, Instance Variable and Class variable?\nLocal Variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and it will be destroyed when the method has completed.\nInstance Variables: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded.\nClass Variables: These variables declared with in a class, outside any method, with the static keyword.\n\nDefault Byte type value in java?\nDefault value is 0.\n\nWhat is a static Variable?\nClass variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.\n\nWhat is a Classloader?\nA Class Loader is a subsystem of JVM that is used to load classes and interfaces. eg.: Bootstrap classloader, Extension classloader, System classloader, plugin classloader etc.\n\nExplain Runtume Polymorphism?\nRun time (Dynamic) polymorphism is the polymorphism existed at run-time. Here, Java compiler does not understand which method is called at compilation time. Only JVM decides which method is called at run-time. Method overloading and method overriding using instance methods are the examples for dynamic polymorphism.\n\nExplain static binding and dynamic binding?\nThe compiler only knows that the type of \"a\" is Animal ; this happens at compile time, because of which it is called static binding (Method overloading). But if it is dynamic binding then it would call the Monkey class method. Java uses static binding for overloaded methods and dynamic binding for overridden methods.\n1) Static binding in Java occurs during Compile time while Dynamic binding occurs during Runtime.\n2) private, final and static methods and variables uses static binding and bonded by compiler while virtual methods are bonded during runtime based upon runtime object.\n3) Static binding uses Type(Class in Java) information for binding while Dynamic binding uses Object to resolve binding.\n3) Overloaded methods are bonded using static binding while overridden methods are bonded using dynamic binding at runtime.\n\nWhat is a Constructor?\nConstructor is a block of code that allows you to create an object of class. This can also be called creating an instance. Constructor looks like a method but it’s not, for example methods can have any retu\n type or no retu\n type (considered as void) but constructors don’t have any retu\n type not even void.\n\nWhat are different types of constructors?\nDefault constructor\nNo-arg constructor\nParameterized Constructor\n\nHow to Call a constructor?\nTo call a constructor use the keyword new, followed by the name of class, followed by parameters if any. For example to create the object of class Mangoe, you can call the constructor like this: new Mangoe()\n\nWhat are access modifiers?\nAccess Modifiers are set to access levels for classes, variables, methods and constructors. There are four levels:\nVisible package (No modifiers needed here)\nVisible to class only (Private to class)\nVisible to world (Public)\nVisible to the package and all subclasses (Protected)\n\nParseInt() in Java?\nThe first argument is interpreted as representing a signed integer in the radix specified by the second argument, exactly as if the arguments were given to the parseInt(java.lang.String, int) method. The result is an Integer object that represents the integer value specified by the string\n\nCan we achieve runtime Polymorphism by data members?\nNo.\n\nWhat is Encapsulation and Abstraction?\nEncapsulation is hiding the implementation details which may or may not be for generic or specialized behaviors.\nAbstraction is the process of generalization: taking a concrete implementation and making it applicable to different, albeit somewhat related, types of data.\n\nCan we use abstract method and final both with a method?\nNo. Because final methods cannot be overridden.\n\nCan we instantiate abstract class?\nAbstract class can never be instantiated.\n\nWhat is the difference between StringBuffer and StringBuilder?\nThe difference between StringBuffer and StringBuilder is that StringBuffer is thread-safe. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.\n\nWhat is a finalize() method?\nFinalize() method is defined / called just before an objects final destruction by garbage collector, it is used to make sure that object terminates cleanly.\n\nWhat is interface in java?\nAn interface is a special form of an abstract class which does not implement any methods. In Java, you create an interface like this:\n\ninterface Interface\n{\nvoid interfaceMethod();\n}\n\nCan we declare an interface method as static?\nInterface methods is abstract by default and static and abstract keywords cannot be used together. Hence No.\n\nDifference between abstract class and interface class?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
      AbstractInterface
      Partial implementationWe don't know anything about implementation, just requirements
      It has an abstract method. An addition, it uses concreteEvery method is public and abstract by default
      No restriction for abstract class method modifiersIt is a 100% pure abstract class
      No restriction for abstract class variable modifiersIf we declare public we cannot declare private and protected
      No restriction to initialize variablesEvery interface has public, static and final
      A constructor is not allowedInstance and static block not allowed
      No restriction to initialize variablesEvery variable is static
      \nIs it possible to define Private and Protected modifiers variables in interfaces?\nThey both are implicitly public, hence no.\n\nWhat is a finally block?\nA Block that is finally is always executed."},{"id":159,"category_id":5,"question":"What is the internal working of HashMap in Java and how does collision resolution work in Java 8?","slug":"what-is-the-internal-working-of-hashmap-in-java-and-how-does-collision-resolution-work-in-java-8","answer_html":"

      In Java, a HashMap works on the principle of hashing. It internally uses an array of Node<K,V> buckets. When put(key, value) is called:

      1. The key's hashCode() is computed, then spread via an internal bitwise hash function.
      2. The array index is determined by (n - 1) & hash, where n is the bucket table length.
      3. If the bucket is empty, a new Node is placed.
      4. If collision occurs (multiple keys map to the same bucket), Java resolves it via linked list chaining.

      Java 8 Optimization: When the number of nodes in a bucket exceeds TREEIFY_THRESHOLD = 8 and table capacity is at least 64, the linked list is converted into a Red-Black Tree. This changes worst-case lookup from O(n) to O(log n).

      ","explanation_html":"

      When bucket items decrease to 6 (UNTREEIFY_THRESHOLD), the Red-Black tree converts back into a regular linked list to conserve memory.

      ","code_snippet":"Map map = new HashMap<>();\nmap.put(\"Bangalore\", 560001);\nmap.put(\"Chennai\", 600001);\n\n// Java 8 computeIfAbsent\nmap.computeIfAbsent(\"Mumbai\", k -> 400001);","code_language":"java","difficulty":"Intermediate","views_count":122,"likes_count":0,"last_reviewed":"2026-10-17 11:47:50","status":"published","meta_title":null,"meta_desc":null,"created_at":"2026-10-17 11:47:50","updated_at":"2026-10-17 11:47:50","summary":"HashMap uses bucket array with hashing. Java 8 improves worst-case collision lookup from O(n) to O(log n) using Red-Black trees when bucket size exceeds 8.","reading_time_mins":4,"evaluation_points":"1. Explains bucket index calculation (n-1 & hash). 2. Mentions chaining collision resolution. 3. Highlights Java 8 Red-Black tree threshold (8) and O(log n) complexity.","original_legacy_answer":null,"category_name":"Java","category_slug":"java","answer":"

      In Java, a HashMap works on the principle of hashing. It internally uses an array of Node<K,V> buckets. When put(key, value) is called:

      1. The key's hashCode() is computed, then spread via an internal bitwise hash function.
      2. The array index is determined by (n - 1) & hash, where n is the bucket table length.
      3. If the bucket is empty, a new Node is placed.
      4. If collision occurs (multiple keys map to the same bucket), Java resolves it via linked list chaining.

      Java 8 Optimization: When the number of nodes in a bucket exceeds TREEIFY_THRESHOLD = 8 and table capacity is at least 64, the linked list is converted into a Red-Black Tree. This changes worst-case lookup from O(n) to O(log n).

      "},{"id":241,"category_id":5,"question":"How do == and equals differ when comparing Java strings?","slug":"how-do-and-equals-differ-when-comparing-java-strings","answer_html":"For objects, == compares reference identity, while equals can compare logical content according to the class implementation. String overrides equals to compare character sequences. Interning may make some equal string literals share a reference, but relying on that for content comparison is incorrect. Objects.equals handles a possibly null pair safely. For primitives, == compares values rather than object identity. When creating a custom value type, define equals and hashCode consistently so logically equal objects work correctly in hash-based collections.","explanation_html":"","code_snippet":"import java.util.Objects;\r\n\r\nclass StringComparison {\r\n public static void main(String[] args) {\r\n String a = new String(\"java\");\r\n String b = new String(\"java\");\r\n System.out.println(a == b); // false\r\n System.out.println(Objects.equals(a, b)); // true\r\n }\r\n}","code_language":"java","difficulty":"Easy","views_count":103,"likes_count":0,"last_reviewed":"2026-10-17 14:35:10","status":"published","meta_title":null,"meta_desc":null,"created_at":"2026-10-17 00:00:00","updated_at":"2026-10-17 00:00:00","summary":null,"reading_time_mins":3,"evaluation_points":null,"original_legacy_answer":null,"category_name":"Java","category_slug":"java","answer":"For objects, == compares reference identity, while equals can compare logical content according to the class implementation. String overrides equals to compare character sequences. Interning may make some equal string literals share a reference, but relying on that for content comparison is incorrect. Objects.equals handles a possibly null pair safely. For primitives, == compares values rather than object identity. When creating a custom value type, define equals and hashCode consistently so logically equal objects work correctly in hash-based collections."},{"id":160,"category_id":5,"question":"What is the difference between String, StringBuilder, and StringBuffer in Java?","slug":"what-is-the-difference-between-string-stringbuilder-and-stringbuffer-in-java","answer_html":"

      String: Immutable object stored in the String Constant Pool. Any modification (e.g. concatenation) instantiates a new String object on the heap, resulting in memory fragmentation during frequent string manipulation loops.

      StringBuffer: Mutable sequence of characters where methods are synchronized. It is completely thread-safe but incurs synchronization locking overhead.

      StringBuilder: Mutable sequence introduced in Java 5. Identical API to StringBuffer but non-synchronized. It offers maximum execution speed in single-threaded environments and is the recommended default choice.

      ","explanation_html":"

      For simple string concatenations in single statements (e.g. a + b + c), modern Java javac compilers automatically bytecode-optimize expressions into StringBuilder instances.

      ","code_snippet":"// High performance string concatenation\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < 1000; i++) {\n sb.append(i).append(\",\");\n}\nString result = sb.toString();","code_language":"java","difficulty":"Beginner","views_count":116,"likes_count":0,"last_reviewed":"2026-10-17 11:47:50","status":"published","meta_title":null,"meta_desc":null,"created_at":"2026-10-17 11:47:50","updated_at":"2026-10-17 11:47:50","summary":"String is immutable. StringBuffer is mutable and thread-safe (synchronized). StringBuilder is mutable and fast (non-thread-safe).","reading_time_mins":3,"evaluation_points":"1. Explains String immutability and memory cost. 2. Identifies synchronization difference. 3. Chooses StringBuilder for single-threaded performance.","original_legacy_answer":null,"category_name":"Java","category_slug":"java","answer":"

      String: Immutable object stored in the String Constant Pool. Any modification (e.g. concatenation) instantiates a new String object on the heap, resulting in memory fragmentation during frequent string manipulation loops.

      StringBuffer: Mutable sequence of characters where methods are synchronized. It is completely thread-safe but incurs synchronization locking overhead.

      StringBuilder: Mutable sequence introduced in Java 5. Identical API to StringBuffer but non-synchronized. It offers maximum execution speed in single-threaded environments and is the recommended default choice.

      "},{"id":246,"category_id":5,"question":"Why does volatile not make counter++ thread-safe, and what would you use instead?","slug":"why-does-volatile-not-make-counter-thread-safe-and-what-would-you-use-instead","answer_html":"volatile provides visibility and ordering guarantees for accesses to the field, but increment is a read-modify-write sequence. Two threads can read the same value and both write the same incremented result, losing an update. AtomicInteger.incrementAndGet provides an atomic increment; synchronized or a lock can protect a larger invariant involving several fields. Pick the mechanism according to what must change together. An atomic counter does not automatically make associated collection updates atomic or make every operation in the surrounding method thread-safe.","explanation_html":"","code_snippet":"import java.util.concurrent.atomic.AtomicInteger;\r\n\r\nclass Counter {\r\n private final AtomicInteger value = new AtomicInteger();\r\n int increment() {\r\n return value.incrementAndGet();\r\n }\r\n int get() {\r\n return value.get();\r\n }\r\n}","code_language":"java","difficulty":"Medium","views_count":120,"likes_count":0,"last_reviewed":"2026-10-17 14:35:10","status":"published","meta_title":null,"meta_desc":null,"created_at":"2026-10-17 00:00:00","updated_at":"2026-10-17 00:00:00","summary":null,"reading_time_mins":3,"evaluation_points":null,"original_legacy_answer":null,"category_name":"Java","category_slug":"java","answer":"volatile provides visibility and ordering guarantees for accesses to the field, but increment is a read-modify-write sequence. Two threads can read the same value and both write the same incremented result, losing an update. AtomicInteger.incrementAndGet provides an atomic increment; synchronized or a lock can protect a larger invariant involving several fields. Pick the mechanism according to what must change together. An atomic counter does not automatically make associated collection updates atomic or make every operation in the surrounding method thread-safe."}]; let currentIndex = 0; let masteredCount = 0; let secondsElapsed = 0; let timerInterval = null; function startTimer() { timerInterval = setInterval(() => { secondsElapsed++; const mins = String(Math.floor(secondsElapsed / 60)).padStart(2, '0'); const secs = String(secondsElapsed % 60).padStart(2, '0'); document.getElementById('sessionTimer').innerText = `${mins}:${secs}`; }, 1000); } function renderCurrentQuestion() { const q = sessionQuestions[currentIndex]; document.getElementById('currentQNum').innerText = currentIndex + 1; document.getElementById('qCategoryName').innerText = q.category_name || ''; document.getElementById('qTitle').innerText = q.question; document.getElementById('qDifficultyBadge').innerText = (q.difficulty || 'Medium') + ' Level'; document.getElementById('sessionNotes').value = ''; const answerBox = document.getElementById('activeAnswerBox'); answerBox.classList.add('hidden'); document.getElementById('toggleAnswerText').innerText = 'Reveal Model Answer & Solution'; document.getElementById('activeAnswerHtml').innerHTML = q.answer || q.answer_html || ''; if (currentIndex === sessionQuestions.length - 1) { document.getElementById('nextBtnText').innerText = 'Complete Session'; } else { document.getElementById('nextBtnText').innerText = 'Next Question'; } } function toggleActiveAnswer() { const box = document.getElementById('activeAnswerBox'); const text = document.getElementById('toggleAnswerText'); if (box.classList.contains('hidden')) { box.classList.remove('hidden'); text.innerText = 'Hide Model Solution'; } else { box.classList.add('hidden'); text.innerText = 'Reveal Model Answer & Solution'; } } function rateQuestion(isMastered) { if (isMastered) masteredCount++; const q = sessionQuestions[currentIndex]; // Automatically flag as practiced via background API call fetch('/interview-questions/api/practice/' + q.id, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ notes: document.getElementById('sessionNotes').value }) }).catch(console.error); nextQuestion(); } function nextQuestion() { currentIndex++; if (currentIndex >= sessionQuestions.length) { finishSession(); } else { renderCurrentQuestion(); } } function finishSession() { clearInterval(timerInterval); document.getElementById('practiceContainer').classList.add('hidden'); const sum = document.getElementById('summaryCard'); sum.classList.remove('hidden'); document.getElementById('summaryTotal').innerText = sessionQuestions.length; document.getElementById('summaryMastered').innerText = masteredCount; const mins = String(Math.floor(secondsElapsed / 60)).padStart(2, '0'); const secs = String(secondsElapsed % 60).padStart(2, '0'); document.getElementById('summaryTime').innerText = `${mins}:${secs}`; } document.addEventListener('DOMContentLoaded', () => { startTimer(); renderCurrentQuestion(); });