Interview Questions and Answers - Order By Rating Q541. Create a Table with 2 Columns and Insert a row into it Database
Ans. CREATE TABLE TABLE_NAME (
ID NUMBER PRIMARY KEY,
NAME VARCHAR(50) NOT NULL,
);
INSERT INTO TABLE_NAME(ID, NAME) VALUES(1, "Abc"); Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ddl  dml  create table  insert records into table Asked in 1 Companies Q542. What is the difference between compilation and decompilation ? Core Java
Ans. Compilation is the process of converting Java source files to class files which can be executed by the Java runtime environment whereas Decompilation is the process of converting class files back to the Java Source code. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  compilation vs decompilation  compiler vs decompiler Q543. What will be the output of following code ?
Base Interface
public interface BaseInterface {
int i = 4;
}
Derived Interfaces
public interface DerivedInterface1 extends BaseInterface{
int i = 5;
}
public interface DerivedInterface2 extends BaseInterface{
int i=6;
}
Implementing Class
public class Class implements DerivedInterface1,DerivedInterface2 {
int i=10;
public static void main(String[] args){
System.out.println(new Class().i);
}
}
What will be the output upon executing main and Why ? Core Java
Ans. 10 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  interfaces  coding  code intermediate Q544. What will be the output of following code ?
Base Interface
public interface BaseInterface {
int i = 4;
}
Derived Interfaces
public interface DerivedInterface1 extends BaseInterface{
int i = 5;
}
public interface DerivedInterface2 extends BaseInterface{
int i=6;
}
Implementing Class
public class Class implements DerivedInterface1,DerivedInterface2 {
public static void main(String[] args){
System.out.println(BaseInterface.i);
}
}
What will be the output upon executing main and Why ? Core Java
Ans. It will print 4 because member elements of an interface are implicitly static and hence the concept of overriding doesn't work.
Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  interfaces  coding  code  extending interfaces  diamond interfaces Asked in 1 Companies intermediate Ans. https://javasearch.buggybread.com/InterviewQuestions/questionSearch.php?searchOption=label' Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Algorithm  Sorting Algorithm Asked in 4 Companies basic   frequent Q546. What is a certificate authority ? Security
Ans. A trusted organization which issues public key certificates and provides identification to the bearer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  authentication  auth certificates Q547. What is the difference between authentication and authorization ? Authentication
Ans. Authentication is the process of verifying the identity and credentials of the user to authenticate him into the system.
whereas
Authorization is the process by which access to a segment , method or resource is determined.
Authorization is usually a step next to authentication. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  authentication  authorization  authentication vs authorization Asked in 9 Companies basic   frequent Q548. What is the difference between
File f = new File("homexyz.txt");
and
File f = File.createTempFile("xyz",".txt","home"); ? Core Java
Ans. First will not create physical file in storage whereas the second will. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  file handling  File.createTempFile  file handling intermediate   rare Q549. Can you name some of the Java frameworks in different domains ? Frameworks
Ans. Web Framework - Spring , Struts, Play
Dependency Injection frameworks - Google Guice , PicoContainer and Dagger
ORM Framework - Hibernate
Big Data / ETL Frameworks - Apche Hadoop , Apache Crunch, Apache Spark.
View Frameworks - JSF , Apache Wicket,jtwig.
Java Gui Frameworks - SWT , AWT, JavaFX
Testing - Junit, Mockito, PowerMock, EasyMock, JMock, JMockit
Rest Web services - Jersey , Restlet , RestX, RestEasy ,Restfulie
Here is the big list for reference - http://javasearch.buggybread.com/home2.php?keyword= Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  frameworks Asked in 2 Companies intermediate   frequent Q550. What are the benefits of creating immutable objects ? Core Java
Ans. 1. Security and Safety - They can be shared across multiple threads as they are thread safe. Moreover, it protects then from bad state due to interception by the other code segment. One such problem due to mutability and access by alternate code segment could be the change of hash code and then the impact on its search with hash collections.
2. Reuse - In some cases they can be reused as only one copy would exist and hence it can be relied upon. For example - String Pool Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  immutable  immutability objects Asked in 1 Companies Intermediate   frequent Q551. How does Lazy Initialization helps improving performance of an application ? Hibernate
Ans. Lazy Initialization means , Load Dependencies when required. Which means less load on application resources as only required data is loaded upfront. It's not only good for better performance but for better resource utilization too. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  lazy loading  lazy initialization   frequent Q552. What are the points to be considered if we move from Eager initialization to Lazy Initialization in Hibernate ? Hibernate
Ans. Make sure that the properties of dependent Hibernate entities are not accessed and if yes, better wrap the whole code within single transaction. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  lazy loading  lazy initializationUsually asked to entry level software developers. Q553. Write a program to swap two variables without using third Core Java
Ans. public static void main(String[] args) {
int num1 = 1;
int num2 = 2;
num1 = num1^num2;
num2 = num1^num2;
num1 = num1^num2;
System.out.print("num1 = " + num1 +", num2 = "+num2);
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  code  coding Asked in 37 Companies basic   frequent Q554. What is memory leak ? How Java helps countering memory leaks compared to C++ ? Core Java
Ans. Memory Leak is a situation wherein we have a reserved memory location but the program has lost its reference and hence has no way to access it.
Java doesn't have concept of Pointers, Moreover Java has concept of Garbage collection that frees up space in heap that has lost its references. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  memory leak  garbage collection intermediate   frequent Q555. How should we handle errors while writing or accessing Stored Procedures? Database
Ans. Store Procedure returns the error code. Moreover we can put the call withing try block and catch SQL Exception. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  stored procedure  exception handlingAns. Its used to access the object properties using the object reference or class properties using the Class Name. Moreover its used to access the classes and Interfaces of a package. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  operators Q557. How are DB transactions handled in Hibernate ? Hibernate
Ans. // Non-managed environment idiom
Session sess = factory.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
// do some work
...
tx.commit();
}
catch (RuntimeException e) {
if (tx != null) tx.rollback();
throw e; // or display error message
}
finally {
sess.close();
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q558. What actions you take if there is an issue related to Database server ? Support
Ans. We involve DBA and try to solve it through them. By the time they are solving it , we keep the stake holders informed regarding the progress. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  database  database server  production support Q559. How do you monitor your logs while investigating a high severity problem ? Support
Ans. We try to look for errors in the last n minutes when the issue occurred. If the issue is still occurring intermittently, We tail the logs for different application server instances to see the error snippets coming in the live logs. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  production support  unix  application logs Q560. Which Web and Application server is being used by your application ? Server
Ans. We are using Apache 2.3 and Tomcat 5.6 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  web server  application server  server Basic   frequent Q561. What are the cursors available in Java ? Core Java
Ans. Enumeration
Iterator
List iterator Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  cursors  iterator Q562. how to access the methods of an inner class? Core Java
Ans. It depends on the type of inner class
To access non static inner class method
new OuterClass().new InnerClass().getMethod();
To access static method of static inner class
new OuterClass.InnerClass().getMethod(); Sample Code for inner class Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inner classes  nested aclasses Asked in 1 Companies Intermediate   frequent Q563. Which interface is responsible for transaction management in JDBC ? Database
Ans. Connection Interface Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  jdbc Q564. Can we convert a numeric IP address to a web host name ? Java EE
Ans. Yes, using InetAddress.getByName("<IP Address>").getHostName(); Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ip address to hostname  INETAddress intermediate Ans. It's an object that reads from one stream and writes to another. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java io  io filter intermediate Q566. What is the difference between the Reader/Writer java.io hierarchy and the Stream class hierarchy? Core Java
Ans. The Reader/Writer hierarchy is character oriented, whereas the Stream class hierarchy is byte oriented. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java io  streams intermediate Q567. What kind of thread is garbage collection thread ? Core Java
Ans. Daemon thread Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  garbage collection intermediate Try 2 Question(s) TestAns. Interface that is declared inside the interface or class, is known as nested interface. It is static by default. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  interface  nested interface intermediate Try 1 Question(s) Test Q569. How does Java handle integer overflows and underflows? Core Java
Ans. It uses those low order bytes of the result that can fit into the size of the type allowed by the operation. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  integer  data types Asked in 1 Companies   rare Q570. Is there a way to know size of an object in Java ? Core Java
Ans. No, Java doesn't have a sizeOf operator. In C / C++ , its required to determine how much memory allocation is required which is not the case with Java. Java handles memory allocation and deallocation intrinsically. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sizeOf  size of object  sizeOf operator Asked in 1 Companies   rare