Libera #java

Using SQL's "IN" in JDBC

In SQL, the IN operator is used to restrict columns to one of a set of values. Using IN in JDBC, though, is sometimes problematic because of the way different databases handle prepared statements. With JDBC, prepared statements use ? to serve as markers for values in a SQL statement. Thus, you might see: PreparedStatement ps=connection.prepareStatement("SELECT * FROM FOO WHERE BAR = ?"); This serves to help prevent SQL injection attacks; assigning a value of "'' or...

4 minute(s) read

Some interesting links for and from ##java, Jan 15 2016

Some links relevant to Java, as of Jan 15 2016: A git-flow cheatsheet. git-flow is a set of command-line scripts that implement Vincent Driessen‘s branching model for git projects, such as commands to complete feature requests, and the like. Yahoo has released a giant dataset for machine learning. jQuery has reached 3.0 beta. jQuery may not be the framework du jour for implementing a Javascript front end for Java web...

2 minute(s) read

Using karma on ##java

Ah, karma: me> ~karma javabot> All living beings have actions (karma) as their own, their inheritance, their congenital cause, their kinsman, their refuge. It is karma that differentiates beings into low and high states. me> ... what? Karma is normally a way of referring to the kind of person you are. It’s the sum of your actions in Hinduism and Buddhism. IRC isn’t Hinduism or Buddhism, but karma in ##java is...

2 minute(s) read

Eclipse Neon will require Java 8

Excellent news from the Eclipse Foundation: the next version of Eclipse, called “Neon,” will require the Java 8 runtime. The announcement in email is underwhelming, but the actual project plan is a little more explicit and informative: In general, the 4.6 release of the Eclipse Project is developed on Java SE 8 VMs. As such, the Eclipse SDK as a whole is targeted at all modern, desktop Java VMs. Most functionality is available for...

1 minute(s) read

From Apache: Log4J 1 end-of-lifed; update to Log4J 2 recommended

On 5 Aug 2015, the Apache Foundation announced that Log4J 1, the popular logging framework, has been end-of-lifed, meaning that no future releases are expected and maintenance and support have been discontinued. Migration to Log4J 2 is enabled through the use of a Log4J 1.X bridge, as described in a short FAQ about the EOL of Log4J 1: Q: Is there a way to quickly migrate from Log4j 1.x to Log4j...

1 minute(s) read

A set of testing tools

Petri Kainulainen posted “12 Tools That I Use for Writing Unit and Integration Tests,” which does a pretty good job of describing a set of testing tools and approaches, including solutions in the following categories: Running Tests Mock and Stub frameworks Writing Assertions Testing Data Access Testing Spring It’s not comprehensive (nor does it claim to be), with no mention of things like TestNG, Arquillian, Liquibase or Flyway, or testing CDI in general (see...

1 minute(s) read

Bypassing subclass method overrides

Someone in ##java recently asked a question that may come up with beginners to OOP: How to invoke a method of a superclass from the outside. For example, if ChildClass extends BaseClass and overrides BaseClass.method(), how can one invoke the method of the superclass, bypassing the override in ChildClass? This is not a very good idea from an OOP standpoint, because the child class might not expect the parent’s behavior to be invoked...

4 minute(s) read

Link: Jenkins over HTTPS with JNLP slaves

A user in ##java recently ran into a problem where he needed to connect Jenkins slaves to a master, using SSL – and it didn’t work, thanks to security. He helpfully wrote up how using correct policy files got it working. Jenkins is a continuous integration server – basically an application that runs your builds when changes occur in your source tree. Slaves allow the build to take place on different hardware configurations, as well as...

1 minute(s) read

Deep Dive: All about Exceptions

Overview Exceptions are a mechanism for java code to signal extraordinary conditions (such as virtual machine errors like running out of memory, code bugs such as passing a negative number to a method that doesn’t accept negative numbers, alternative ways a method can exit, such as an attempt to read from a network socket aborting because the other end severed the connection, and even intentional control flow such as aborting a thread ASAP). They...

21 minute(s) read

Finding hash collisions in Java Strings

In ##java, a question came up about generating unique identifiers based on Strings, with someone suggesting that hashCode() would generate generally usable numbers, without any guarantee of uniqueness. However, duplicate hash codes can be generated from very small strings, with ordinary character sets – see this stackoverflow answer – and therefore I thought it’d be interesting to find other short strings with the same hash values. It was discussed how prone to collisions the Strings hashCode...

2 minute(s) read