Home » Author Archives: Martin Mois (page 2)

Author Archives: Martin Mois

Martin is a Java EE enthusiast and works for an international operating company. He is interested in clean code and the software craftsmanship approach. He also strongly believes in automated testing and continuous integration.

多线程和并发面试问题与答案 – 终极列表(PDF下载)

java-logo

编者按: 并发一直是开发者的挑战,编写并发程序可以是非常困难的。当涉及并发,有一系列事情可能会出现和系统复杂性大幅提高。但是,编写健壮的并发程序的能力是开发者的一个伟大的工具,可以帮助建立复杂的企业级的应用。在这篇文章中,我们将讨论可用于编程面试的不同类型问题,以评估面试者对并发和多线程的的认识问题。这些问题不仅是Java的特异性,同时也关于常规的编程原则。享受! 提示,您是否在寻找Java中的职业发展机会?   请访问我们的Job Board 搜索和查看一个为世界各地的IT专业人员手工挑选 Java就业机会的平台.   此外,您可以将您的简历发给我们的 Resumes Board 推广自己的技能给全球广泛的Java招聘人员。 目录 1. 什么是我们理解的并发? 2. 进程和线程之间的区别是什么? 3. 在Java中,什么是进程和线程? 4. 什么是调度器? 5. 一个Java程序至少有多少个线程? 6. 如何在Java应用程序中访问当前线程? 7. 每一个Java线程有哪些特性? 8. 线程组的目的是什么? 9. 线程有什么状态,每一个状态的意思是什么? 10. 我们如何设置线程的优先级? 11. 如何在Java创建线程? 12. 我们如何停止在Java的线程? 13. 为什么一个线程不会被调用的方法stop()停止? 14. 是否有可能启动一个线程两次? 15. 下列代码的输出结果是什么? 16. 什么是守护线程? 17. 有可能当一个普通用户线程已经开始了,将它转为守护线程吗? 18. 我们怎么理解忙等待? 19. 怎么避免忙等待? 20. 我们能否把Thread.sleep()用于实时处理? 21. 一个线程在被放在使用线程休眠Thread.sleep()前怎么被唤醒? 22. 怎么查询一个线程是否已经中断? 23. 如何处理一个InterruptedException异常? 24. 在启动子线程后,我们如何在父线程等待子线程终止? ...

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 »

Creating a DSL for AWT’s Robot

apache-maven-logo

The Java SDK ships with the class java.awt.Robot that allows the automation of keyboard and mouse input as well as the creation of screen captures. When you want to write a small test application that simulates user input or you just want to automate the input of some recurring text, this features comes in handy. But you do not want ...

Read More »

Hibernate Tutorial – The ULTIMATE Guide (PDF Download)

jboss-hibernate-logo

EDITORIAL NOTE: Hibernate ORM (Hibernate in short) is an object-relational mapping framework, facilitating the conversion of an object-oriented domain model to a traditional relational database. Hibernate solves the object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions. Hibernate is one of the most popular Java frameworks out there. For this reason we have provided ...

Read More »

JPA 2.1: Unsynchronized persistence context

java-interview-questions-answers

The JPA version 2.1 brings a new way how to handle the synchronization between the persistence context and the current JTA transaction as well as the resource manager. The term resource manager comes from the Java Transaction API and denotes a component that manipulates one resource (for example a concrete database that is manipulated by using its JDBC driver). Per ...

Read More »

JPA 2.1 criteria delete/update and temporary tables in Hibernate

jboss-hibernate-logo

Since JPA version 2.0 the EntityManager offers the method getCriteriaBuilder() to dynamically build select queries without the need of string concatenation using the Java Persistence Query Languge (JPQL). With version 2.1 this CriteriaBuilder offers the two new methods createCriteriaDelete() and createCriteriaUpdate() that let us formulate delete and update queries using the criteria API. For illustration purposes lets use a simple ...

Read More »

JPA Tutorial – The ULTIMATE Guide (PDF Download)

java-interview-questions-answers

EDITORIAL NOTE: The Java Persistence API (JPA) is a Java programming language application programming interface specification that describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition. JPA has become the de-facto standard to write application code that interacts with Databases. For this reason we have provided an abundance of tutorials here ...

Read More »

Testing System.in and System.out with system-rules

java-logo

Writing unit tests is an integral part of software development. One problem you have to solve when your class under test interacts with the operating system, is to simulate its behaviours. This can be done by using mocks instead of the real objects provided by the Java Runtime Environment (JRE). Libraries that support mocking for Java are for example mockito ...

Read More »

cjmx: A command-line version of JConsole

java-logo

JConsole is a nice tool when it comes to monitoring a running Java application. But when it is not possible to connect to a JVM with JConsole directly (due to network restrictions for example) and SSH tunneling is not possible, then it would be great to have a command line version of JConsole. jcmx is such a command line version ...

Read More »

Multithreading and Concurrency Interview Questions and Answers – The ULTIMATE List (PDF Download)

java-logo

EDITORIAL NOTE: Concurrency is always a challenge for developers and writing concurrent programs can be extremely hard. There is a number of things that could potentially blow up and the complexity of systems rises considerably when concurrency is introduced. However, the ability to write robust concurrent programs is a great tool in a developer’s belt and can help build sophisticated, ...

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:

  • Advanced Java Guide
  • Java Design Patterns
  • JMeter Tutorial
  • Java 8 Features Tutorial
  • JUnit Tutorial
  • JSF Programming Cookbook
  • Java Concurrency Essentials