Java objective type questions and answers on static keyword



6.What is the output of below program ?

java multiple choice questions with answers

x=10 x=10
x=10 x=20
x=30 x=30
x=30 x=20




Java mcq with answers on this keyword




Core java multiple choice questions with answers on method overloading




Java mutliple choice questions with answers on constructors

  • On the request of many friends we added java multiple questions with answers.
  • Java mcq questions with answers on constructors.
  • We will add all java topics multiple questions with answers for freshers and experienced.



How to get java source files from jar file

  • Jar : Java Archive is a group of .class files.
  • We can create a jar file using following commands
  • jar -cvf  example.jar test.class
  • jar -cvf example.jar *.*
  • To unzip from jar file we need to use following command.
  • jar -xvf  instanceofjava.jar



How to get source code from jar file using java De-compilers

how to get source code from jar file in eclipse


  • Open JD-GUI and File -> open -> open target jar file.
  • It will show java source code.

How to extract java files from jar in eclipse

  •  We can get java source files from jar file by using eclipse also for this we need to add a plugin.
  • Download jar file from http://jd.benow.ca/
  • Unzip it . you will get jd.ide.eclipse.plugin_1.0.0.jar file  and add it to eclipse plugin folder.
  • And restart your eclipse.
  • Add target jar file to a project and now click on the file you will get source code.
  • You can add target jar file using java project->java buildpath -> add external jars option


how to convert jar to java source in eclipse


  • Here i added jstl core jar to eclipse to see java source files.
  • Click on the file now it will show source code 
  • How to extract java files from jar

how to extract java files from jar in eclipse

Hibernate Native sql query with example

  • By Using Hibernate Native SQL we can write database dependent queries as part of hibernate.
  • Hibernate Native Sql allows us to write create , update,  delete and insert queries.
  • We can also call Stored procedures using Hibernate Native Sql.
  • When the query is too complex using HQL then we need to use hibernate sql query.
  • Hibernate uses the org.hibernate.SQLQuery interface for native SQL
    1. SQLQuery is a sub interface of Query
    2. Use createSQLQuery() factory method on Session to create SQLQuery object.
  •  Hibernate SQLQuery must be associated with an existing Hibernate entity or scalar result.



Hibernate native sql insert query example

  1. Session session = sessionFactory.openSession();
  2. session.beginTransaction();
  3.  
  4. SQLQuery insertsqlQuery = session.createSQLQuery("INSERT INTO
  5. Physician(firstname,lastname,fee,hospital)VALUES(?,?,?,?)");
  6.  
  7.  insertsqlQuery.setParameter(0, "Saidesh");
  8.  insertsqlQuery.setParameter(1, "Kilaru");
  9.  insertsqlQuery.setParameter(2, 50); 
  10.  insertsqlQuery.setParameter(3, "Yashoda");        
  11.  insertsqlQuery.executeUpdate();

 Hibernate scalar query example

  • Writing a Hibernate Sql query to get list of  scalars or values from single or multiple tables.
  • Lets see an example on Hibernate scalar query.


  1. String hibernate_sql = "SELECT first_name, fee FROM  Physician";
  2. SQLQuery query = session.createSQLQuery(hibernate_sql);
  3. query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
  4. List results = query.list();

 Hibernate named sql Queries

  • Writing a Hibernate Sql query to get entity object by using addEntity() method.
  • Lets see an example on Hibernate named sql query

hibernate native sql query parameters scalar


Hibernate Named Query Introduction Tutorial

  • If we are using HQL or Native SQL queries multiple time then it will be code mess because all queries will be scattered throughout the project.
  • Hibernate Named Query is a way to use queries by giving a name.
  • Hibernate Named Queries will be defined at one place and used anywhere in the project.
  • use of named query in hibernate
  • Writing HQL query in HBM file is called HQL Named Query.
  • Or we can use @NameQuery annotation in entity.
  • For writing Hibernate Named Queries we will use <query> tag in Hibernate mapping file Or @NameQuery annotation in the entity.
  • If we want to create Named Query using hibernate mapping file then we need to use query element.



Advantages of Named Query in Hibernate 

  • Global access
  • Easy to maintain.

Hibernate Named Queries by using Annotations:

  • If we want to create Named Queries using annotations in entity class then we need to use @NameQueries and @NameQuery annotations
  • @NameQuery will be used to create single Query
  • @NameQueries annotations will be used to create multiple Queries. When we are using @NameQueries for every query we need to use @NameQuery annotation.

Hibernate Named Query example by using Annotations:


Hibernate Named Query example join

  1. Query query = session.getNamedQuery("findDocterById");
  2.         query.setInteger("id", 37);
  3.        List empList = query.list();


Hibernate Named Queries by using Hibernate mapping file:

  • We need to configure Hibernate Named Queries as part of Hibernate mapping file.
  • By using <query> element we need to write Hibernate named Queries.

  1. <hibernate_mapping>
  2.             <class  >
  3.             ---------
  4.             </class>
  5.  
  6.  <query name = “findDocterById”>
  7.  <![CDATA[from Docter s where s.id = :id]]>
  8. </query>  

  9.  </hibernate_mapping>     


  1. Query query = session.getNamedQuery("findDocterById");
  2.         query.setInteger("id", 64);
  3.        List empList = query.list();

Select Menu