Blog Archives
1 … 23 24 25 26 27 28

Spring Controller Unit Testing

This Spring controller unit test is based on

HATEOAS RESTFul Service with Spring tutorial. The request URL and JSON response content are shown below.

REQUEST URL: http://localhost:8080/simpleSpring/greeting?name=John
RESPONSE JSON: {“content”:”Hello, John!”,”links”:[{“rel”:”self”,”href”:”http://localhost:8080/simpleSpring/greeting?name=John”}]}

REQUEST URL: http://localhost:8080/simpleSpring/greeting
RESPONSE JSON:{“content”:”Hello,

…

Read more ›



Spring IO tutorial in 6 steps

Spring IO Platform is all about “list of dependencies and their versions that work well together”. It is implemented as a Maven POM file via Maven Bill-of-Materials dependency that you can import into your projects to set the versions for dependencies. You can go to “ … Read more ›...

This content is for 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


Spring loading property files & properties

conf/db.properties

# jdbc.X
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql://localhost/mytestdb
jdbc.user=SA
jdbc.pass=
# hibernate.X
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=

#1. Register a Properties File in Application Context XML

The “<property-placeholder>” tag.

OR

#2.

…

Read more ›



Spring, JavaConfig (@Configuration), and TransactionManager

This extedns configuring JDBC and JPA to configure the TransactionManager.

Example #1 Wiring JDBC Transaction Manager

Note: @EnableTransactionManagement annotation

If you want to create a mock transaction manager, then you can do

Also,

…

Read more ›



Spring, JavaConfig (i.e @Configuration) & JDBC by example

Example #1 Wiring JDBC Datasource

application.yml where the datasource properties are read.

Example #2 Wiring JDBC Datasource with JNDI

Example #3 Wiring JDBC Embedded Datasource for integration testing

Example #4 Wiring up the JdbcTemplate by passing in the datasource

Example #5 Wiring up a DAO...

This content is for 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


Spring, JavaConfig (i.e @Configuration) & JMS by example

Step 1: Define the messaging system connectivity, destination (e.g. topic or queue) and message selector properties via a YAML or .properties file. Here is an example of application.yml file.

Step 2: MQTopicConnectionFactory The Java based Spring configuration defining the connection factory. … Read more ›...

This content is for 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


Stack from scratch Java example

Q. If Java did not have a Stack implementation, how would you go about implementing your own? A. Determine the backing data structure (e.g. array, linked list, etc). Determine the methods that need to be implemented like pop( ), push( ), … Read more ›...

This content is for 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


Swap 2 values & bubble sort in Java

Q1. Can you write an algorithm to swap two values? A1.

Swapping without a temp variable

Note: also try with * and \ Using bitwise “xor”

Q2. … Read more ›...

This content is for 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


Swapping, partitioning, and sorting algorithms in Java

Q1. Can you write an algorithm in Java to swap two variables? A1.

Q2. Can you write an algorithm to bubble sort the following array { 30, 12, 18, 0, -5, 72, 424 }?? … Read more ›...

This content is for 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


Top 10 causes of performance issues in Java

Cause #1: The JVM spends more time performing garbage collection due to improper Garbage Collection (GC) configuration. E.g. Young generation being too small. Heap size is too small (use -Xmx). The application footprint is larger than the allocated heap size. … Read more ›...

This content is for 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


Two Pointers: Partitioning around a pivotal number

Q. How will you partition the following numbers 7 3 6 8 2 9 5 4 around the pivotal number of 5 so that the lower values are in front of it and higher values are behind it? The pointers are shown with: “^” … Read more ›...

This content is for 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


Unit Test Hibernate – DAO Layer with JPA, Spring & HSQLDB

This post extends the previous one on “Unit Test Hibernate – DAO Layer with Spring & HSQLDB“. The changes are

1. Add “persistence-jpa.xml” to src/main/resources.

2. Modify the “entityManagerFactory()” method in the “SimpleConfig.java”.

…

Read more ›



Unit Test Hibernate – DAO Layer with Spring & HSQLDB

Step 1: The pom.xml file with test jars, Spring jars, and hibernate jars

Step 2: The HSQL DB schema and data scripts in the src/test/resources folder.

sql/schema.sql

sql/data.sql

Step 3: The Spring configuration for the unit tests in the src/test/java folder.

…

Read more ›



1 … 23 24 25 26 27 28

300+ Java Interview Questions - FAQs

Tutorials on Java & Big Data