Byte Buddy - runtime code generation for the JVM
“Byte Buddy is a code generation library for creating Java classes during the runtime of a Java application and without the help of a compiler.” Cool.
“Byte Buddy is a code generation library for creating Java classes during the runtime of a Java application and without the help of a compiler.” Cool.
Here's a Java class that I created today that creates constants for all the FTP server return codes listed on this Wikipedia page. If you ever start doing programming against a real FTP server, or perhaps a mock FTP server, you'll know what these FTP return codes are needed for.
Without any further delay, here's the Java source code for a class I've named FtpServerReturnCodes
:
I normally don't share source code that doesn't work, but I just want to make a note here for myself on how to use JavaMail to search for multiple search terms. While the code doesn't currently work, I believe it does show the correct syntax for searching for multiple search terms, and there's just something about the overall JavaMail API (or Yahoo Mail) that I don't understand at this moment.
While working on a Java application yesterday, I ran into a situation where I needed to search my POP3 mailbox for unseen messages, i.e., email messages I haven't read yet. (I'm adding some "You've got mail" functionality to one of my automated robots.)
Jumping right to the solution, here's the complete source code for a JavaMail example class that demonstrates how to search for unseen (unread) email messages in a POP/POP3 mailbox:
Here's the source code for a simple "Java send mail" class that can simplify the process of sending email messages from Java applications. I've named this class MailAgent
, and I'm sharing the source code here for free. I've included a brief usage statement in the Javadoc at the top of the class. Hopefully it's all pretty straightforward, and a decent example of using the JavaMail API to send an email message.
While working on a Java application, I found the need for a simple Java mailbox reader. I wanted to be able to scan through one of my POP/POP3 mailboxes for messages, and then do something with those messages.
To that end I created the following example JavaMail POP mailbox reader. It connects to a standard POP/POP3 mailbox, then scans through all the messages in the "Inbox" folder.
Java String FAQ: How can I tell if a Java String contains a given regular expression (regex) pattern?
In a Java program, you want to determine whether a String contains a case-insensitive regular expression (regex). You don't want to manipulate the String or extract the match, you just want to determine whether the pattern exists at least one time in the given String.
A frequently asked Java question is, "How can I tell what version of Java is running my program?"
Answer: Just use this line of source code to determine the version of Java that is running your program:
Java Ant build FAQ: Can you share some examples of the Ant copy task, i.e., the Ant copy task syntax?
Sure. I've shared quite a few Ant examples on the website now (just search the website for "Ant"), and here's another snippet of code from an Ant build script that shows how to use the Ant copy task.
As you can see from this sample code, I'm using the Ant copy task to copy files from source locations to other destination locations.
I thought this might be harder, but if you have a file URL like “file:///Users/al/SherlockHolmes.txt”, and want to read those file contents as a Java URL
, the process in Java and Scala is simple, as shown in this Scala code:
I just learned how to send STDOUT and STDERR to a file in a Java application (without using Unix shell redirect symbols). Just add these two lines of code to the main
method in your Java (or Scala) program:
System.setOut(new PrintStream("/Users/al/Projects/Sarah2/std.out")); System.setErr(new PrintStream("/Users/al/Projects/Sarah2/std.err"));
Then when you use:
System.out.println("foo");
or
If you want the horizontal and/or vertical scrollbars to always show on a Java JScrollPane, configure them like this:
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
Other options are:
HORIZONTAL_SCROLLBAR_AS_NEEDED HORIZONTAL_SCROLLBAR_NEVER
and:
Here are a few examples of how to set the Font on Java Swing components, including JTextArea, JLabel, and JList:
// jtextarea textArea.setFont(new Font("Monaco", Font.PLAIN, 20)); // jlabel label.setFont(new Font("Helvetica Neue", Font.PLAIN, 14)); // jlist list.setFont(new Font("Helvetica Neue", Font.PLAIN, 12));
You can use code like the following Scala code to easily test different fonts. Modify however you need to, but it displays a JFrame with a JTextArea, and you can change the font on it:
I just tried a quick test of transparency/translucency on Mac OS X using Java, and in short, here is the source code I used to create a transparent/translucent Java JFrame on Mac OS X 10.9:
As a quick note, I use code like this in my Mac/Java/Scala applications to determine where I can put my application data files on a user’s Mac OS X filesystem:
If you want to set your Java JScrollPane
scrollbars to always scroll, both horizontally and vertically, this code shows the solution: