DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Java Topics

article thumbnail
Java Suspended Thread States
Java threads can be in six different states: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED. We will explore them here.
May 19, 2016
by Ram Lakshmanan DZone Core CORE
· 161,136 Views · 19 Likes
article thumbnail
Java 8 HashMaps, Keys, and the Comparable Interface
In this post, we are going to discover a new, important feature that Java 8 brings to us in the event of hash collisions.
May 18, 2016
by Tamás Györfi
· 36,874 Views · 41 Likes
article thumbnail
Log4J 2 Configuration: Using the Properties File
This post looks at using and configuring the Log4j 2 properties file, letting you change various configuration options without modifying your application code.
May 18, 2016
by John Thompson
· 346,888 Views · 13 Likes
article thumbnail
Working With Akka Actors
Here we're going to look at the Akka actor model with a simple example: fetching weather data from Yahoo.
May 18, 2016
by Hardik Pandya
· 12,582 Views · 10 Likes
article thumbnail
Dynamic HTML Templates With FreeMarker and Vaadin
Skip the HTML! Learn about utilizing FreeMarker and Vaadin to help you generate HTML templates, so you don't have to write them yourself.
May 17, 2016
by Alejandro Duarte DZone Core CORE
· 14,819 Views · 2 Likes
article thumbnail
Java 8: Declare Private and Protected Methods in Interfaces
In the upcoming Java 9 release, it will be possible to declare private and protected methods in interfaces. Learn how you can use almost the same features in Java 8 interfaces today.
May 14, 2016
by Per-Åke Minborg
· 44,459 Views · 13 Likes
article thumbnail
Java EE 8 MVC: Global Exception Handling
Adding global exception handling to an Java EE MVC application is quite simple.
May 13, 2016
by Michael Scharhag
· 12,329 Views · 8 Likes
article thumbnail
James Gosling on Oracle, Once Again
James Gosling sounds off on Oracle's culture and handling of Java, clarifies some past comments, and addresses his "low expectations."
May 11, 2016
by Dave Fecak
· 45,660 Views · 33 Likes
article thumbnail
Comparing Golang with Java
The first impressions of a Java enthusiast when looking at Go's features.
May 11, 2016
by Peter Verhas DZone Core CORE
· 74,955 Views · 25 Likes
article thumbnail
A Polyglot's Guide to Multiple Dispatch Part 4: Clojure
The conclusion of this series about multiple dispatch focuses on using the technique in Clojure.
May 11, 2016
by Eli Bendersky
· 6,141 Views · 1 Like
article thumbnail
Restful Java Metering by Dropwizard Metrics
Dropwizard has taken the Java world by storm with it's ease of use and great functionality. The metrics library is particularly powerful for anyone wanting to measure statistics in their Java applications.
May 10, 2016
by Thamizh Arasu
· 21,987 Views · 6 Likes
article thumbnail
Major Benefits and Limits of Autowiring in Spring Java Web Development
In this post, you will learn about autowiring—its limitations, advantages, and disadvantages in detail. You also get to know about different modes of autowiring used in Java web development.
May 10, 2016
by James Warner
· 101,842 Views · 4 Likes
article thumbnail
Is Polyglot Programming Practical?
This article discusses the history of polyglot programming, and considers whether it's still a valid premise.
May 10, 2016
by Keith Gregory
· 26,284 Views · 46 Likes
article thumbnail
Understanding the Java Garbage Collection Log
To diagnose any memory problems, the Garbage Collection log file is the best place to start. Take a look at the anatomy of a GC log file in this helpful article.
Updated May 5, 2016
by Ram Lakshmanan DZone Core CORE
· 200,118 Views · 39 Likes
article thumbnail
Java 8: Lambda Functions—Usage and Examples
One of the major new language features in Java 8 is the lambda function. In fact, it is one of the biggest changes since the Java 1 release. Take a look at this introduction to Java 8's lambda function.
May 4, 2016
by Hari Kiran G
· 216,925 Views · 10 Likes
article thumbnail
Custom SecurityContext in JAX-RS
An article about how to override the default security-related information associated with a JAX-RS request using a custom SecurityContext.
May 3, 2016
by Abhishek Gupta DZone Core CORE
· 31,195 Views · 9 Likes
article thumbnail
Simple, Secure Role Based Access Control (RBAC) For REST APIs
There are a lot of ways to implement Access Controls, and some are slightly complicated. Have you considered using REST?
April 30, 2016
by Sharone Zitzman
· 73,947 Views · 10 Likes
article thumbnail
Sharing Test Classes Between Multiple Modules in a Multi-module Maven Project
Using Maven to effectively test software when test classes are not already packaged by Maven.
April 28, 2016
by Dave Turner
· 56,398 Views · 6 Likes
article thumbnail
Testing Java EE (or Why Integration Tests Are Overrated)
Testing that goes beyond just unit testing and integration testing. Why we should be doing full system testing.
April 27, 2016
by Sebastian Daschner
· 26,134 Views · 7 Likes
article thumbnail
Mocking Method with Wildcard Generic Return Type
[Ivan Zerin provides a primer on mocking methods that contain generic return types.] There are several cases where construction when().thenReturn is not suitable during Unit tests. One of then generic return type. I have faced such issue, let's take a look. There is a method in interface declaration: public interface FooInterface { public Iterable getList(); ... } Implementation looks like this: public class Foo implements FooInterface { public List getList() { ... } ... } At first mocking of such method should not be something unusual: public class UnitTest { @Mock private FooInterface mockFoo; @Test public void someUnitTest() { ... List testList = generateTestList(); when(mockFoo.getList()) .thenReturn(testList); } } But this code won't compile with error: Cannot resolve method 'thenReturn(List). Seems to be some mistake, cause returned type are correct from the interface point of view. This error happening cause compiler can not gurantee that returned type of method getList() will be List. Actually return type of method getList() in this case is Iterable and this means "Return some Iterable object with any objects that extends SomeClass". Let's rename this type as 'X'. So when(mockFoo.getList()) will create object OngoingStubbing> and it has method thenReturn(Iterable). Compiler can not tell what type X before runtime and cannot perform safe cast from List to Iterable (we perfrom actuall call of method thenReturn(List)). Sounds a little tricky but let's assume that SomeClass is standard Java class Number. Then classes Integer and Double are both fulfill the criteria of List. Let's say that as return type of mock we will use List, in this case, compiler should be ready that actual work with code during runtime will be performed with List too, but it is clearly that cast from Double to Integer will be incorrect (try to cast double value 12.6 to int). You could argue that in the case of mockito compiler won't need to bother about the casting of returned type because call of original method would not produce anything, but it is known by mockito. From compiler point of view, it is only Java code, that should be checked for safety and correctness before compiling. Ok, so how we should deal with such cases in mockito? Use doReturn() method: doReturn(testList).when(mockFoo).getList(); Such expression is not type safe, so it were designed for exceprional cases, so use it only when you cannot use standart when().thenReturn(), which is the type-safe, elegant and more readable syntax.
April 27, 2016
by Ivan Zerin
· 44,515 Views · 4 Likes
  • Previous
  • ...
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×