Java Code Examples, Tips and Articles

Javadb.com provides source code examples in the Java language as well as other Java specific resources. Feel free to browse through the content or to search for a code example.



Arrays
java source code example Extend the size of an array
java source code example How to copy an array
java source code example Using the Comparable interface to compare and sort objects
java source code example How to sort an array

Collections
java source code example Using a Queue (or LinkedList)
java source code example Using a Stack
java source code example Using a Set (or HashSet)
java source code example Remove duplicate items from an ArrayList
java source code example Looping through a Collection object
View more...

Compression
java source code example Extract contents of a zip file
java source code example How to list the contents of a zip file
java source code example How to create a zip file

Database
java source code example Connect to database and call stored procedure
java source code example Using a database transaction with JDBC
java source code example Connecting to a Database - Step by Step
java source code example Connect to a database and read from table

Datatype conversions
java source code example Convert String to Boolean
java source code example Convert Boolean to String
java source code example Convert byte to String
java source code example Character array to String conversion
java source code example Convert String to character array
View more...

File I/O
java source code example Remove a line from a text file
java source code example Loading configuration parameters from textfile into a program
java source code example Writing objects to file with ObjectOutputStream
java source code example Write to file using a BufferedWriter
java source code example Write to file using BufferedOutputStream
View more...

Graphics Java 2D
java source code example Drawing a Ractangle with rounded corners using Java 2D Graphics API
java source code example Drawing a Ractangle using Java 2D Graphics API
java source code example Drawing a Line using Java 2D Graphics API
java source code example Drawing a String using Java 2D Graphics API

Java Language Fundamentals
java source code example Convert Characters to Lower Case
java source code example Convert Characters to Upper Case
java source code example Replace Characters in a String
java source code example Getting a substring from a String
java source code example Check if String Contains another String
View more...

Networking
java source code example Sending a POST Request with Parameters From a Java Class
java source code example Downloading a web page using URL and URLConnection classes
java source code example Perform NSLookup with the InetAddress class

Reflection
java source code example List methods of a class using Reflection
java source code example Invoke methods of an object using reflection

Servlets
java source code example Redirect Servlet Call to Another URL
java source code example Forward Call from a Servlet
java source code example Get Users IP Address
java source code example Get and Set Session Variables in a Servlet
java source code example Get Request Parameters in a Servlet

Swing
java source code example Show a message dialog with JOptionPane
java source code example Set Look and Feel for a Swing application
java source code example JLabel with more than one row

Threads
java source code example Setting thread priorities
java source code example How to create a thread


What's on in the Java world?

  • Editor's Daily Blog   2008-05-13 08:07
    A schedule for the mini-talk podcasts... also:
    Featured Podcast: j1-2k8-mtT01: Enabling Semantic Web Technologies with JBI
    Java Today: Open Source vs. Open Standards in the JCP, Portal Pack 2.0 final version for NetBeans 6.1, and How Portable is LWUIT?
    Weblogs: The future of testing, Kohsuke's JavaOne highlights, and Adding jMaki wrapped Yahoo widgets to a GWT app
    Forum posts: 3D audio, unmarshalling by declared type, and running an MIDP application from a command line
  • Cool Thing   2008-05-12 07:33
    What was your favorite thing from JavaOne 2008? Also
    Weblogs: Wrap-up from James Gosling, hits and misses, and the big picture
    Featured Podcast: Java Mobility Podcast 45: Live from JavaOne 2008
    java.net Poll: How do you feel about Java after JavaOne 2008?
    Java Today: The next Java epoch, taking mobile development out of the niche, and NetBeans JavaScript video tour
    Spotlight: Project SocialSite
    Forum Posts: Client vs. server VMs, podcast about off-deck ME apps, and hiding exceptions from clients
  • JavaOne 2008: Day Four   2008-05-02 07:08
    JavaOne packing day... also:
    Featured Podcasts: j1-2k8-pre01: Best of Community Corner 2007 and Java Mobility Podcast 44: John Charles, Airscape Down Under CTO
    Java Today: OpenJDK in Fedora 9 and Ubuntu 8.04 LTS, MAKEFaces project, and RoboHACC uncontest at JavaOne
    Weblogs: Hudson community update, Comet example on GlassFish v3 / Grizzly, and DIY I18N 4 ME
    Forum Posts: BD-J authoring wiki, jtreg harness open-sourced, and Wonderland JavaOne Showcase winners announced
  • Celebratory   2008-05-01 06:15
    No hard feelings about the wait for Java 6 on the Mac... right? Also:
    Weblogs: Gosling on Mac Java and OpenJDK for Fedora and Ubuntu, Josh on RIA podcast, and what's new in Servlet 3.0
    Java Today: Java Posse OpenJDK interview, Metro 1.1.1, and JavaTools Community Newsletter #167
    Feature Article: Students and the Mural project
    Forum Posts: 6u10 survey, JAX-WS feature sets and releases, and 6u10 comments and feature requests
  • The Fragile Army   2008-04-30 06:40
    Java 6 (finally) for Mac... now what? Also:
    Java Today: Java for Mac OS X 10.5 Update 1, JCP Program Award nominees, and generics, wildcards, and extends
    Weblogs: Mac Java 6 limitations, gratitude for open-source, and class data sharing
    Forum Posts: ME launchers, cookie roundtrips, and seeking ME tutorial
  • We Crawl   2008-04-29 06:46
    Power up your robots for JavaOne... also:
    Java Today: Greenfoot/Trackbot uncontest @ JavaOne, new OpenJDK subprojects, and embeddable GlassFish v3
    Featured Podcast: Java Mobility Podcast 43: Mobile Distillery's porting tool Celsius
    Weblogs: OSGi bundles and Java Module System, refactoring for performance, and hacking on OpenJDK
    Forum Posts: JVMs hanging around, new web tier list and forum, and Wonderland event at JavaOne
  • Light To Follow   2008-04-28 05:47
    NetBeans 6.1 makes an early debut... also:
    Java Today: NetBeans 6.1 final release
    Spotlight: java.net @ JavaOne and JavaOne Student Program still accepting participants
    Weblogs: Marge plays Tetris, Mobile ' Embedded at FSIL 9.0, and JMX gets a query langauge
    Forum Posts: User expectations and applet startup, anti-aliasing in JRE 6u10, and when ME does (and doesn't) scroll for you
  • History Never Repeats   2008-04-25 08:20
    Wave goodbye to languages without garbage collection... also:
    java.net Poll: Could you work with a non-garbage-collected language
    Java Today: Compatible JDK evolutions, new features in EJB 3.1, and Wizard project in-depth
    Spotlight: Recording of yesterday's project-owner tutorial
    Weblogs: ME on Windows Mobile, Grizzly unofficial benchmarks, and OpenJDK encumbrance-clearing progress
    Forum Posts: Moving GlassFish, JTHarness dependencies, Nimbus and SwingX, and extending GlassFish's Comet support
  • What's The Matter With You   2008-04-24 07:12
    Looking at and modifying classes as they're loaded... also:
    Feature Article: Add Logging at Class Load Time with Java Instrumentation
    Announcement: CEE Tutorial and Q&A: Tutorial For New Project Owners
    Java Today: MySQL and memcached on GlassFish, Trackbotcode project, and free GlassFish book chapter
    Weblogs: Top JavaOne desktop sessions, Hudson plugin for WAR/EAR deployment, and CRUD with Grails
    Forum Posts: Card-specific graphics regression reported, jMaki version numbering, and defending the system tray icon and menu
  • Another Great Divide   2008-04-23 06:17
    OpenJDK to add closures sub-project... also:
    Also Today: OpenJDK sub-project for BGGA closures, updated GlassFish roadmaps, and JavaTools Community Newsletter #166
    Weblogs: SailFin configuration, another filthy rich JavaOne session, and JavaScript character encoding pain points
    Forum Posts: Using JavaFX in web pages, javax.jnlp.* access in applets, and "working directory" concept in GlassFish