Skip to main content

Posts

Scala language implementation of Bubble Sort

Introduction Bubble sort is the simplest sorting algorithm. It has the following steps a) Iterates through the list b) Compares the adjacent elements c) Swap the adjacent elements if they are in not in proper sorting order d) The list is traversed repeatedly unless the list is sorted Worst Complexity : O(n*n) Best Complexity    : O(n) Alternate name      : Sinking Sort Implementation package main.scala object BubbleSort { val array = Array(0,5,2,6,3,1) def main (args : Array[String] ) { print("Unsorted List ") println(array.toList) print("Ascending sorted List ") bubbleSortAscending; println(array.toList) bubbleSortDescending print("Descending sorted List ") println(array.toList) } def bubbleSortAscending { //in scala you can combine inner and outer loops, until does not include the last number for( i <- 0 until array.length; j <- 1 until array.le

Create New Scala sbt project for Eclipse

Introduction In this post, we will learn how to create a new Scala sbt project and convert it into the eclipse project. We will then import the project into eclipse Step 1 Open your user's home directory, on windows, it will be user directory\.sbt\1.0\ Step 2 Create a new directory by the name of plugins if one does not exist Step 3 Create a new file  plugins.sbt ( if one does not exist)   inside the plugins folder Step 4 Open the newly created file  plugins.sbt and add the following line addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4") Step 5 Open a Command prompt and create a new directory for your Scala project i.e. > mkdir FirstScalaEclipseProject Step 6 Move to the new directory > cd FirstScalaEclipseProject Step 7 Enter the following command > sbt reload (if the shell is not restarted) > sbt eclipse Step 8 Open the eclipse, Go to File -> Import -> Import Existing Proj

Java Bubble Sort Example

Introduction Bubble sort is the simplest sorting algorithm. It has the following steps a) Iterates through the list b) Compares the adjacent elements c) Swap the adjacent elements if they are in not in proper sorting order d) The list is traversed repeatedly unless the list is sorted Worst Complexity : O(n*n) Best Complexity    : O(n) Alternate name      : Sinking Sort Implementation using Simple Loops public class BubbleSortExample { private static int array[] = {0,5,2,6,3,1}; static int temp = 0; public static void main(String[] args) { bubbleSortAscending(); System.out.println("Ascending Sorted List"); for(int value : array) { System.out.print(value + " "); } bubbleSortDescending(); System.out.println("Descending Sorted List"); for(int value : array) { System.out.print(value + " "); } } private static void bubbleSortAscending() { for(int outer=0; outer<array.length; outer++) {

WARN orm.deprecation - HHH90000014: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator

Introduction  I upgraded Hibernate from version 4 to 5.4.4. Following warning was thrown by Hibernate WARN  orm.deprecation - HHH90000014: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead.  See Hibernate Domain Model Mapping Guide for details. http-nio-8080-exec-10 WARN  orm.deprecation - HHH90000014: Found use of deprecated [org.hibernate.id.SequenceHiLoGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead.  See Hibernate Domain Model Mapping Guide for details. Old Code     @Id     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_PERSON")     @SequenceGenerator(name = "SEQ_PERSON", sequenceName = "SEQ_PERSON_ID",allocationSize=1)     private Long id; SequenceGenerator is deprecated by Hibernate and we have to use either SequenceStyleGenerator or GenericGenerator instea

Default Port numbers used by different software/protocols

The following table lists the default port numbers used by different software/protocols Software/Protocol Default Port Number http 80 https 443 Apache Server 80 IIS Server 80 Apache Tomcat 8080 MySQL server 3306 SQL Server 1433  MongoDB   27017 PostgreSQL 5432 Java No default port DynamoDB 8000 Cassandra 7000 neo4j http port 7474 neo4j https port 7473 Oracle SQL*Net Listener 1521 Oracle Data Guard 1521 Oracle Connection Manager 1630 Oracle Management Agent 3938 Oracle Enterprise Manager Database Console 1158 Oracle SQL*Plus RMI Port 5580 Oracle SQL*Plus JMS Port 5600

Hibernate - Could not instantiate id generator [entity-name=domainObject]

Exception Could not instantiate id generator [entity-name=Your DomainObject] Solution  <generator> or @GeneratedValue specifies the Java class that is used to generate a unique identifier to the mapped persistent class. Using increment  hbm.xml example <id name="id" type="java.lang.Long" column="id">        <generator class="increment" /> </id> Annotation example @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="ID") private Long id; Using database sequence hbm.xml example <id name="id" type="java.lang.Long" column="id">   <generator class="sequence">     <param name="sequence">SEQ_PERSON_ID</param>  </generator> </id> Annotation example @Id @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="PERSON_SEQ") @SequenceGenerator(name="PERSON_SEQ&qu

Hibernate 5.4.4 - select hibernate_sequence.nextval from dual

Exception http-nio-8080-exec-1 DEBUG hibernate.SQL - select hibernate_sequence.nextval from dual http-nio-8080-exec-1 WARN  spi.SqlExceptionHelper - SQL Error: 2289, SQLState: 42000 http-nio-8080-exec-1 ERROR spi.SqlExceptionHelper - ORA-02289: sequence does not exist org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) Solution Default value for hibernate.id.new_generator_mappings setting changed to true for 5.0, in previous versions it was set to false by default Add the following property to hibernate.cfg.xml <property name="hibernate.id.new_generator_mappings"> false </property> OR Add the following property to the configuration properties.put("hibernate.id.new_generator_mappings", " false &

Hibernate 5.4.4 - Instantiate an instance of SessionFactory

Introduction We will learn how to create an instance of SessionFactory using Hibernate 5.4.4 Code private static final SessionFactory sessionFactory; public static final String cfgFileLocation = "/hibernate.cfg.xml";  try {          StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()                                            .configure( cfgFileLocation ).build();           Metadata metadata = new MetadataSources( standardRegistry )             .getMetadataBuilder()             .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE )             .build();     sessionFactory = metadata.getSessionFactoryBuilder()           .build();     } catch (Throwable ex) {                  System.out.println( "exception" );         throw new ExceptionInInitializerError(ex);     } Following exceptions are resolved through the above code java.lang.IllegalArgumentException: org.hibernate.hql.intern

hibernate-release-5.4.4.Final - Required Jars

Introduction Hibernate (Object Relational Mapping framework) is an implementation of Java Persistence API (JPA) specification.   Required Jars for Hibernate 5.4.4 Following Jars resided inside the required folder are the mandatory jars required for Hibernate 5.4.4 antlr-2.7.7.jar byte-buddy-1.9.11.jar classmate-1.3.4.jar dom4j-2.1.1.jar FastInfoset-1.2.15.jar hibernate-commons-annotations-5.1.0.Final.jar hibernate-core-5.4.4.Final.jar istack-commons-runtime-3.0.7.jar jandex-2.0.5.Final.jar javassist-3.24.0-GA.jar javax.activation-api-1.2.0.jar javax.persistence-api-2.2.jar jaxb-api-2.3.1.jar jaxb-runtime-2.3.1.jar jboss-logging-3.3.2.Final.jar jboss-transaction-api_1.2_spec-1.1.1.Final.jar stax-ex-1.8.jar txw2-2.3.1.jar Hibernate 5.4.4 release is compatible with  Java 8 or 11  JPA 2.2 References https://hibernate.org/orm/releases/5.4/

Jersey Framework Client - How to add HTTP Basic Authentication Header to HTTP Request?

Introduction In this tutorial, we will learn how to add HTTP basic authorization token to the HTTP request header. We will use Jersey Framework to consume RESTful web services. Read the following post if you want to learn how to secure web services using HTTP Basic Authentication Jersey Java Framework - How to add HTTP Basic Authentication to RESTful web services? Maven Dependencies <dependency>     <groupId>org.glassfish.jersey.core</groupId>     <artifactId>jersey-client</artifactId>     <version>2.29</version>  </dependency>  <dependency>     <groupId>org.glassfish.jersey.inject</groupId>     <artifactId>jersey-hk2</artifactId>     <version>2.29</version> </dependency> Basic Authentication is the most simple way to secure HTTP requests. It has the following format Authorization: Basic base64-encoding of username:password Jersey Client Jersy is the refe