Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

 

and many more ....

 

 

Microservice Design Patterns

software-development-2-logo

The main characteristics of a microservices-based application are defined in Microservices, Monoliths, and NoOps.  They are functional decomposition or domain-driven design, well-defined interfaces, explicitly published interface, single responsibility principle, and potentially polyglot. Each service is fully autonomous and full-stack. Thus changing a service implementation has no impact to other services as they communicate using well-defined interfaces. There are several advantages of such an application, but its not ...

Read More »

JPA入门教程 – 终极指南

java-interview-questions-answers

编者按:Java持久化API(JPA)是Java语言中的应用程序编程接口规范,在基于Java平台标准版和Java平台企业版的应用程序中,JPA负责管理关系数据。 JPA已经成为事实上的标准,用于编写与数据库交互的代码。也正由于此,我们已经在Java Code Geeks提供了丰富的教程,可以在这里访问这些教程。此外,我们还制作了一本JPA迷你书,它能够帮助你入门JPA,而且顺利过渡到更高级的概念(加入我们的newsletter,可以免费获取)。 现在,我们想要建立一篇独立的、可做参考的文章:提供一个帮助你了解如何使用JPA的框架;并帮助你快速启动你的JPA应用程序开发。开始享受吧! 目录 1. 简介 2. 创建项目 3. 基础知识 3.1. EntityManager和持久化单元(Persistence Unit) 3.2. 事务(Transactions) 3.3. 数据库表(Tables) 4. 继承(Inheritance) 5. 实体关系(Relationships) 5.1. 一对一(OneToOne) 5.2. 一对多(OneToMany) 5.3. 多对多(ManyToMany) 5.4. Embedded / ElementCollection 6. 数据类型和转换器(Converters) 7. 条件查询(Criteria) API 8. 序列(Sequences) 9. 源码下载 1. 简介 Java持久化API(JPA)是一个独立于供应商的、用于映射Java对象和关系型数据库表的规范。此规范的实现,使得应用程序的开发者们可以不依赖于他们工作中面对的特定数据库产品,从而开发出可以与不同数据库产品良好工作的CRUD(创建、读取、更新、删除)操作代码。这些框架除了可以用于处理与数据库交互的代码(JDBC代码),也可以用于映射数据和应用程序中的对象。 JPA由三个不同的组件构成: 实体(Entities): 在当前版本的JPA中实体是普通Java对象(POJO)。老版本的JPA中实体类需要继承JPA提供的实体基类,但是这样的设计导致框架中存在了严重的依赖关系,测试变得更加困难;所以在新版JPA中不再要求实体类继承任何框架类。 对象-关系型元数据(Object-relational metadata): 应用程序的开发者们必须正确设定Java类和它们的属性与数据库中的表和列的映射关系。有两种设定方式:通过特定的配置文件建立映射;或者使用在新版本中支持的注解。 Java持久化查询语句(Java Persistence Query Language - JPQL): 因为JPA旨在建立不依赖于特定的数据库的抽象层,所以它也提供了一种专有查询语言来代替SQL。 这种由JPQL到SQL语言的转换,为JPA提供了支持不同数据库方言的特性,使得开发者们在实现查询逻辑时不需要考虑特定的数据库类型。 在本教程中,我们会纵览JPA框架的不同方面,同时开发一个简单的、可以从关系数据库中存储和检索数据的Java SE应用程序。我们使用到的类库/环境如下: ...

Read More »

What’s new in Grails 3

grails-logo

A few days ago Grails 3.0 was officially released. Grails is now based on Spring Boot, the build system changed from Gant to Gradle and significant parts of the framework have been rewritten. In this post we will have a look at all the major changes introduced by Grails 3. Updated file structure We will start with a screenshot that ...

Read More »

R: Snakes and ladders markov chain

software-development-2-logo

A few days ago I read a really cool blog post explaining how Markov chains can be used to model the possible state transitions in a game of snakes and ladders, a use of Markov chains I hadn’t even thought of! While the example is very helpful for understanding the concept, my understanding of the code is that it works ...

Read More »

Writing Clean Tests – Small Is Beautiful

software-development-2-logo

We have learned that “clean” unit tests might not be as clean as we think. We have done our best to make our unit tests as clean as possible. Our tests are formatted properly, use domain-specific language, and avoid excessive mocking. Nevertheless, our unit tests are not clean because:           When we make changes to the ...

Read More »

How does Hibernate store second-level cache entries

jboss-hibernate-logo

Introduction The benefit of using a database access abstraction layer is that caching can be implemented transparently, without leaking into the business logic code. Hibernate Persistence Context acts as a transactional write-behind cache, translating entity state transitions into DML statements. The Persistence Context acts as a logical transaction storage, and each Entity instance can have at-most one managed reference. No ...

Read More »

How to FlatMap a JDBC ResultSet with Java 8?

java-interview-questions-answers

You’re not into the functional mood yet? Then the title might not resonate with you – but the article will! Trust me. Essentially, we want this: +------+------+------+ | col1 | col2 | col3 | +------+------+------+ | A | B | C | row 1 | D | E | F | row 2 | G | H | I | ...

Read More »

Scala Snippet: Case Class vs plain ordinary Class

scala-logo

In Scala there exist the construct of a ‘case class’. According to Martin Odersky this supports you to write a “regular, non-encapsulated data structure”. It always seems to be associated with pattern matching. So when to use a case class and when to use a ‘plain’ class? I found this nice explanation stating: “Case classes can be seen as plain ...

Read More »

Spring Enable annotation – writing a custom Enable annotation

spring-interview-questions-answers

Spring provides a range of annotations with names starting with Enable*, these annotations in essence enable certain Spring managed features to be activated. One good example of such an annotation is EnableWebMvc which brings in all the beans needed to support a MVC flow in Spring based applications. Another good example is the EnableAsync annotation to activate beans to support ...

Read More »

用于Java和XML绑定的JAXB教程– 终极指南

java-logo

Java为处理XML结构和文件提供了一系列的选项。JAXB是其中最常见使用的一种。JAXB全称是Java Architecture for XML Binding。它能够将Java对象装换为XML结构,反过来亦然。JAXB是在JRE 1.6的第一个版本中随着JRE标准包一起发布的。 JAXB的第一个规范在2003年3月完成,实现过程由 Java Specification Request 31: https://jcp.org/en/jsr/detail?id=31所跟踪。在这个规范请求中你可发现很多关于JAXB的成长和所有的改进。 就像刚才提到的,JAXB实在1.6中加入JRE包的。在此之前,要使用它必须将它的包加入到工程中。 在JAXB可以使用之前(很久之前),Java处理XML的方式是DOM: http://www.w3.org/DOM/。这种方式并不是最好的,因为没有很好的抽象来映射XML节点,所有的值类型都被认为是字符串。JAXB有许多的优点,比如面向对象方式的操作XML节点和属性,值类型,注解和本文中将要阐述的其他优点。 本文中的所有例子程序都是使用以下版本来实现的: JRE 1.8.0 for 32b。所使用的IDE是Eclipse SDK 版本: Luna (4.4)。但是其他所有包含JAXB API的Java版本和IDE也能够完美的工作,只要是基于Java 8的。 目录 1. 映射(Mapping) 2. 编组(Marshal) 3. 反编组(Un-marshal) 4. 适配器(Adapters) 5. XSDs 6. 注解 7. 工具 8. 最佳实践 9. 总结 10. 资源 11. 下载   1. 映射(Mapping) 使用一些注解和以下的特定的规则,Java对象就能和XML结构绑定起来。这就是我们称之为映射的原因。在本教程中,我们将使用例子、资源和其他的一些信息来解释以下几点。 我们将展示一些关于如何将Java对象转换为XML结构的例子程序, 这种转换被称为编组(marshaling)。我们将展示如何使用适配器(adapter)处理原始类型,集合和更加复杂的类型。 我们还会解释如何进行相反的操作,也就是反编组(un-marshaling),例如将XML文件转换为Java对象。 所有这些都是通过使用Java注解来完成的。我们会列举并解释和JAXB一起使用的最重要的注解。 我们还会介绍用来校验的XSD(XML Schema),这也是JAXB所支持的一个重要的工具。我们也会看一下XSD在编组时如何起作用。 最后,我们会列举一些与JAXB一起配合使用的工具,它们能在很多的方面都对程序员起到帮助。 ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns