Posts in the “java” category

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

[toc]

Java String array FAQ: Can you share some Java array examples, specifically some String array examples, as well as the new for loop syntax that was introduced back in Java 5?

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

A Java Robot class mouse and keyboard/keystroke example

Java Robot class FAQ: Can you show me an example of how to use the Java Robot class?

Answer: Um, yeah, sure ... I say that a little jokingly. Okay, what really happened is that while developing this Java Robot example code on my Mac, I had to reboot it about 10 times. When you use the Java Robot class, you're poking your head out into the native operating system, and if you mess up with your GUI events -- at least on a Mac OS X system -- a lot of bad things can happen.

A Java CRUD generator (and PHP, and Ruby, and ...)

Way back in the late 1990s, I wrote a Java CRUD generator, which was based on the work of someone else. It was a static code generator, but like future dynamic frameworks like Ruby on Rails, CakePHP, and others, it scanned the database and generated source code from the database table definitions.

Java ‘array of objects’ syntax examples

Java array FAQ: Can you share some examples of how to create arrays in Java (Java object arrays)?

While I generally work with lists and maps in Java, I occasionally need to create object arrays in Java. Since I don't use arrays that often, I thought I'd share some examples here so I can have a handy Java array syntax reference.

A simple Java String array

I work with the String class a lot, and here's how to create a String array in Java:

Java best practice: Return a List, not a LinkedList

As I started to mention in another blog post, your Java code will be more flexible when you learn to return more-general object references. In most cases other developers only need to see your interface, not your implementation. Put another way, does it matter to anyone else if you used a LinkedList or an ArrayList? If it doesn't matter, then return a List, or perhaps even a Collection.

Java JFrame: How to create, center, and display a JFrame

Java JFrame FAQ: How do I properly create and display a JFrame? While you're at it, how do I center a JFrame?

In this Java tutorial I'll demonstrate how to create and display a JFrame Other than the comments in the source code, I'm going to keep the code as simple as possible, so I can demonstrate how this works.

How to set the initial size of a Java JFrame

I've been getting back into the Java/Swing world during the last few days, and I thought I'd share some example code here. In my current application, one of the things I just worked on was setting the initial JFrame size to a value I liked.

Java StringBuffer versus String: When to use StringBuffer

The most common reason to use a StringBuffer instead of a String in your Java programs is when you need to make a lot of changes to a string of characters. For instance, a lot of times you’ll be creating a string of characters that is growing, as shown in this sample example program:

A Java MySQL SELECT example

Summary: This is a Java/MySQL SQL SELECT example, demonstrating how to issue a SQL SELECT command from your Java source code, using a MySQL database.

A Java HTTPS client example

Java HTTPS client FAQ: Can you share some source code for a Java HTTPS client application?

Sure, here's the source code for an example Java HTTPS client program I just used to download the contents of an HTTPS (SSL) URL. I actually found some of this in a newsgroup a while ago, but I can't find the source today to give them credit, so my apologies for that.

A Java Model View Controller example (Part 3)

<< Back to Part 2 of our Java MVC Example

MVC - Handling data-changing events

Whenever the user adds, edits, or deletes data, such as our Process data, all the proper GUI components need to be notified of this event so they can properly update their displays. In this application, when a user adds a new Process, this means that we need to update our MainProcessTable. We implement this as follows: