Java alphanumeric patterns: How to remove non-alphanumeric characters from a Java String
Java String "alphanumeric" tip - How to remove non-alphanumeric characters from a Java String.
Java String "alphanumeric" tip - How to remove non-alphanumeric characters from a Java String.
And in the category of “Strangest Things I Never Knew About Java,” I give you ... CAFEBABE.
you can read more about it here on wikipedia
Java SwingUtilities FAQ: Can you demonstrate an example of the Java SwingUtilities invokeLater
method?
As often happens, I have about 50 browser tabs open, and in an effort to close some of those down, these are some of the best links I found while working with RxJava a week or two ago:
A long time ago — around 2009 — I initially shared some free Java and OOP training material. If you’re interested, you can find it here:
Here is some sample Java source code for some JMX tests that I created a while ago. I started my first tests with an introductory JMX tutorial, then created this JMX example to see how JMX might work with a standalone application, in this case, a Java Swing GUI application. Let's look at the code.
First, here's the source code for a Java interface (an MBean interface) named HelloMBean
:
Here is some sample Java source code for a multithreaded JMX test that I created recently. After creating two other JMX example projects -- a simple JMX Hello World tutorial project and then a JMX standalone (Swing) project -- I decided to create this multi-threaded JMX test application to see how JMX would work with an application that had multiple threads running simultaneously.
One of the nice things about Java is javadoc. The javadoc utility lets you put your comments right next to your code, inside your ".java" source files. When you're satisfied with your code and comments, you simply run the javadoc
command, and your HTML-style documentation is automatically created for you.
Java Matcher problem: You're trying to use the matches method of the Java Matcher class to match a regular expression (regex) you have defined, and it's not working against a given string, and you don't know why.
In my spare time back in 2011 I created a Java version of the old Unix/X-Windows “Xeyes” application. If you ever used Xeyes, you know it as a set of eyes that are displayed on-screen, and follow the mouse cursor as you move it around.
Now in 2019 I just brought it back to life, and here’s a 56-second video that shows how it works:
If for some reason that video doesn’t work, you can see it at this YouTube link.
The app currently only works on MacOS, but it can probably be ported to Linux and Windows systems by anyone motivated. The source code is pretty rough — I wrote it in less than two days back in 2011 — but if you want to build it or improve it, you can find the code here:
As you can see there, the build works with SBT/Assembly and the app-packaging process uses javapackager
.
Feel free to fork it, clean it up, improve it, etc.
Java FileFilter FAQ: How do I implement a file filter in Java so I can limit the possible files that are shown to a user in a "select file" dialog, or limit the list of files that I see when listing the files in a directory?
Java/Mac FAQ: Where is JAVA_HOME
located on Mac OS X systems?
This has changed over time, but if you're using Mac OS X 10.9 or newer, your JDK/SDK JAVA_HOME
location for Java 8 will be something like this:
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
For Java 7 it was also in the same area:
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/
Of course that will vary by the JDK version you have installed.
Question: How do I create a comment in Java?
Answer: There are two ways to create Java comments, and both are shown in the example code below:
// this is a one-line comment /** * this is also * a comment, but it can span multiple * lines. */
The //
syntax makes everything after it on the current line a Java comment, and the /** ... */
syntax lets you create multi-line Java comments.
In this InfoQ Java in 2019 Predictions article, this line stood out the most: Java 9 and 10 saw virtually no deployment to production. Working alone I occasionally wonder what large companies are doing, and with these Java major version number releases coming every six months I was wondering how that was playing out.
To take a break from a project I was working on yesterday I gave my brain a little exercise to see if I could remember how to create a Java class that used the Java 5 Generics magic. Since I’ve used Scala a lot recently, I decided to create a Java version of the Scala Tuple
class.
The Tuple
class simply stores two values, which are often key/value pairs. Beginning with the end in mind, here’s how you would typically use a Tuple
in Java (if it existed):
I just read a short chapter in the book Effective Java, and realized I was doing something pretty dumb in my own code by always creating my own custom exceptions instead of using other exceptions already intended to be reused in the Java API.
I just solved a problem with a Java web service client I've been working on. I've been trying to read a Java web service that was created with Apache Axis2, and it has methods that can return an array or List
of User
objects. I couldn't find any examples on the Axis2 web site that showed how to get an array or List
from a web service client, but I finally find the solution by digging around a little.
In this post I'll provide some sample Java source code that shows what I did to solve this problem.
Java current directory FAQ: Can you share an example of how to determine the current directory in Java?
You can determine the current directory your application is started in using Java's System.getProperty()
method and the user.dir
property, like this:
Java enum FAQ: Can you share a Java enum toString
example?
I haven’t tried this before, but I was just working on several Java enum examples (Java enum examples tutorial, Java enum switch example), and I thought I’d take a look at the Java enum toString
behavior.
To that end I wrote the following Java enum “toString” example class: