object

A Java deep clone (deep copy) example

While interviewing for computer programming positions here in the Boulder, Colorado area, I've found that most interviewers ask questions about Java serialization. After being asked about serialization for the third time recently, I suddenly remembered an old Java deep clone hack that takes advantage of serialization.

The basic idea is this:

Scala REPL - How to show more methods on a class/object in the REPL

When you're working in the Scala REPL and want to see what methods are available on a class/object, you can create an instance of an object, follow that with the "." character, and then press the [Tab] key. This process, known as "tab completion" in the REPL, gives you a preliminary list of methods that can be called on the object.

Here's what this looks like when we try it on an Int object:

Converting a Scala class file to decompiled Java source code

As a Scala newbie, I'm curious about how the process of converting a Scala class back to Java source code works. What I really want to see is how my Scala source code is converted to Java source code. Besides plain old curiosity, I think that understanding more about how Scala works can also be very important to my understanding of Scala (such as the apply() method, and so on).

How to create multiple class constructors in Scala

Scala constructors FAQ: How do I create a Scala class with multiple constructors (secondary constructors)?

The Scala approach to defining multiple class constructors is a little different than Java, but somewhat similar. Rather than try to explain this in words, I just created some example source code to demonstrate how this works.

Here's some source code to demonstrate the Scala "multiple constructors" approach:

Scala YAML parser examples using Snakeyaml

Summary: A Scala YAML parsing example using the Snakeyaml parser.

If you need some Scala YAML parsing examples using Snakeyaml parser, you've come to the right place. I just worked through some Snakeyaml issues related to Scala, in particular converting YAML to JavaBean classes written in Scala, so I thought I'd share the source code here.

Java String array examples (with Java 5 for loop syntax)

Java String array FAQ: Can you share some Java array examples, specifically some String array examples, as well as the Java 5 for loop syntax?

Sure. In this tutorial, we'll show how to declare, populate, and iterate through a Java String array, including the Java 5 for loop syntax. Because creating a String array is just like creating and using any other Java object array, these examples can also work as more generic object array examples.

A Smarty templates object array example

Smarty templates object array FAQ: How can I display an array of objects with Smarty templates?

I just wasted about thirty minutes trying to figure out how to display an array of objects with Smarty templates, so I thought I'd share the solution here. I'll include my PHP class, some of the PHP logic that builds the Smarty variables (my Smarty object array), and then a portion of the Smarty template that displays my PHP object array.

How to put an object on the request in a servlet

Many times when you're working with Java servlets and JSP's, you'll want to forward some piece of information from your servlet to your JSP without having to put that piece of information into the session. For instance, in many applications you may not have a user session, and in other cases where you do have a session, you may just not want to put a bunch of junk in there.

When a Java method call requires a Class reference

Today I was working with a class that extended the Spring class NamedParameterJdbcDaoSupport, and when I went to use the getNamedParameterJdbcTemplate().queryForObject() method, the third parameter of the method required a Class reference.

UML state diagram - show object lifetime states

Question: What UML diagram can I use to show how an object state changes during its lifetime?

A UML state diagram will do the trick. A state diagram is very good for showing how an object state changes over the lifetime of a software application, and the triggers (triggering events) that cause the state to be changed.

 

Syndicate content