Quantcast
Channel: silveira neto » Java
Browsing all 11 articles
Browse latest View live

Java Font List

Here’s a program that lists fonts available in your JVM. You can also set the environment variable JAVA_FONTS to specify the font directory. import java.awt.GraphicsEnvironment;   public class...

View Article



Image may be NSFW.
Clik here to view.

Beware the locale

Today I was programming a toString method for a class widely used in a application, using the very useful String.format that provides a C’s like printf formatter. @Override public String toString() {...

View Article

Image may be NSFW.
Clik here to view.

The Caps Lock Java Socket Server

Here is a simple server for those who are starting studying sockets or just needs a simple socket server example for reuse while writing your own behavior. Features: A client should enter a string and...

View Article

Image may be NSFW.
Clik here to view.

Getting enviroment information on Android

This is a simple program I wrote called Who Am I that shows informations about the device which it is running. Which can be useful for developers and maybe advanced users. Download: WhoAmI.tar.bz2 –...

View Article

Iterating over a HashMap

Iterating over a HashMap using the enhanced loop (foreach) in Java is a good way to keep your code smaller, more legible and usually more semantically coherent. import java.util.HashMap; import...

View Article


calling commands in Java

I don’t like the approach of calling native shell commands in any language instead of using multi platform libraries, but here is a little prof of concept Java program to call native commands. import...

View Article

Image may be NSFW.
Clik here to view.

Java: invoking a method by name

import java.lang.reflect.*;   public class Foo { public void bar(int param){ System.out.println(param); }   public static void main(String args[]){ Object f = new Foo(); try { Method m =...

View Article

Android screen height and width

Context ctx = getContext(); Display display = ((WindowManager)ctx.getSystemService(ctx.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); Yes,...

View Article


Java, printing arrays

As I keep forgetting, this post is to remind me that Java Java doesn’t have a pretty toString() for arrays objects, and it does for Lists. import java.util.List; import java.util.ArrayList; import...

View Article


Image may be NSFW.
Clik here to view.

Regex with negatives lookahead and lookbehind

“Looking different directions” by Paul Kline. Problem: Match strings that contains a single quotation mark ('), but not multiple ones together. Solution: (?<!')'(?!') This is a regex for a single...

View Article

parallel counting in Java using AtomicInteger

import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.TimeUnit; class ParallelCounterExample...

View Article
Browsing all 11 articles
Browse latest View live




Latest Images