<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Developer Papercuts &#187; Java</title>
	<atom:link href="http://www.vogella.de/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vogella.de/blog</link>
	<description>Tips around Eclipse and Android programming</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Beginners Java challenge: Write &#8220;Hello&#8221; World&#8221;</title>
		<link>http://www.vogella.de/blog/2010/04/05/java-hello-world/</link>
		<comments>http://www.vogella.de/blog/2010/04/05/java-hello-world/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 22:10:15 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Challenge]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=2294</guid>
		<description><![CDATA[We recently discussed with several people the fact the Eclipse IDE makes coding so simple that people actually lose the ability to write (Java) code without an IDE.

So for the next few weeks I will post a few simple non-IDE Java challenges. 

This is the beginners Java challenge of the week: 

Take a piece ...]]></description>
			<content:encoded><![CDATA[<p>We recently discussed with several people the fact the <a href="http://www.vogella.de/articles/Eclipse/article.html">Eclipse IDE</a> makes coding so simple that people actually lose the ability to write (Java) code without an IDE.</p>
<p>So for the next few weeks I will post a few simple non-IDE Java challenges. </p>
<p>This is the beginners Java challenge of the week: </p>
<blockquote><p>Take a piece of paper and write down a Java program which prints the String &#8220;Hello World&#8221; to the console. Use packages. </p></blockquote>
<p>Once done, type your code into Eclipse and check if your paper Java version was correct. </p>
<p>Were you successful?</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2010/04/05/java-hello-world/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Integrating Twitter via Java</title>
		<link>http://www.vogella.de/blog/2010/02/11/java-twitter/</link>
		<comments>http://www.vogella.de/blog/2010/02/11/java-twitter/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 00:02:54 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1868</guid>
		<description><![CDATA[This you want to integrate to Twitter from Java you can use the following library JTwitter.

Try out the twitter integration with the following coding:



Another Java Twitter Library is Twitter4J.]]></description>
			<content:encoded><![CDATA[<p>This you want to integrate to Twitter from Java you can use the following library <a href="http://www.winterwell.com/software/jtwitter.php">JTwitter</a>.</p>
<p>Try out the twitter integration with the following coding:</p>
<pre class="brush: java; title: ; notranslate">

package de.vogella.twitter.test;

import java.util.List;

import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.Twitter.User;

public class TwitterTest {
	private static final String user =&quot;your-user&quot;;
	private static final String pw =&quot;your-password&quot;;

	public static void main(String[] args) {
		// Make a Twitter object
               Twitter twitter = new TwitterFactory().getInstance(user,pw);
		// Print Lars Vogel status
		System.out.println(twitter.getStatus(&quot;vogella&quot;));
		// Set my status
		twitter.setStatus(&quot;@vogella messing with Twitter in Java&quot;);
		List&lt;User&gt; followers = twitter.getFollowers();
		for (User user : followers) {
			System.out.println(user.getName());
		}
	}
}
</pre>
<p>Another Java Twitter Library is <a href="http://yusuke.homeip.net/twitter4j/en/index.html">Twitter4J</a>.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.vogella.de/blog/?flattrss_redirect&amp;id=1868&amp;md5=a8181e018068db0779982a7ce03a66b0" title="Flattr" target="_blank"><img src="http://www.vogella.de/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2010/02/11/java-twitter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How can I use a Java jar file in a Grails application?</title>
		<link>http://www.vogella.de/blog/2010/02/10/java-jar-grails/</link>
		<comments>http://www.vogella.de/blog/2010/02/10/java-jar-grails/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 03:00:33 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1861</guid>
		<description><![CDATA[After banging my head against the wall in trying to find out how I can use Java class in a Grails application I found out that the solution is embarrassing simple.

Just create a jar file from your Java classes and put the jar file into the folder "jar" of your Grails application. 

You also ...]]></description>
			<content:encoded><![CDATA[<p>After banging my head against the wall in trying to find out how I can use Java class in a <a href="http://www.vogella.de/articles/Grails/article.html">Grails</a> application I found out that the solution is embarrassing simple.</p>
<p>Just create a jar file from your Java classes and put the jar file into the folder &#8220;jar&#8221; of your Grails application. </p>
<p>You also have to add the correct import statement to your Groovy file. E.g. if you want to use class &#8220;MyJavaClass&#8221; in package &#8220;de.vogella.test&#8221; you have to add &#8220;import de.vogella.test.MyJavaClass&#8221; to your Groovy class. </p>
<p>You also need to re-start the grails server. </p>
<p>To learn more about Grails see <a href="http://www.vogella.de/articles/Grails/article.html">Grails Tutorial</a></p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2010/02/10/java-jar-grails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Disassemble Java class files via javap</title>
		<link>http://www.vogella.de/blog/2009/11/16/decompiling-java-class/</link>
		<comments>http://www.vogella.de/blog/2009/11/16/decompiling-java-class/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 15:30:20 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Basics]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1321</guid>
		<description><![CDATA[Today I received the question how someone could see the Java code for a Java class file. You can disassemble the Java byte code via the command line tool javap.

Lets assume you have this tiny Java class Test.java



Compile this class via javac Test. javaand you receive Java.class

If you you run javap Test you receive ...]]></description>
			<content:encoded><![CDATA[<p>Today I received the question how someone could see the Java code for a Java class file. You can disassemble the Java byte code via the command line tool javap.</p>
<p>Lets assume you have this tiny Java class Test.java</p>
<pre class="brush: java; title: ; notranslate">
package test;

public class Test {

	int number = 5;

	public void sayHello() {
		System.out.println(&quot;Hello&quot;);
	}
}
</pre>
<p>Compile this class via javac Test. javaand you receive Java.class</p>
<p>If you you run javap Test you receive the attributes and method signatures.</p>
<pre class="brush: java; title: ; notranslate">
C:\temp\javaptest&gt;javap Test
Compiled from &quot;Test.java&quot;
public class test.Test extends java.lang.Object{
    int number;
    public test.Test();
    public void sayHello();
}
</pre>
<p>If you you run javap -C Test you receive the byte-code</p>
<pre class="brush: java; title: ; notranslate">

C:\temp\javaptest&gt;javap -c Test
Compiled from &quot;Test.java&quot;
public class test.Test extends java.lang.Object{
int number;

public test.Test();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object.&quot;&lt;init&gt;&quot;:()V
   4:   aload_0
   5:   iconst_5
   6:   putfield        #2; //Field number:I
   9:   return

public void sayHello();
  Code:
   0:   getstatic       #3; //Field java/lang/System.out:Ljava/io/PrintStream;
   3:   ldc     #4; //String Hello
   5:   invokevirtual   #5; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
   8:   return

}
</pre>
<p>To get the full Java source code you can use the tool <a href="http://www.varaneckas.com/jad">jad</a>.</p>
<p><strong>16.11.2008 Updated entry based on comments from Eric and Phil. Thanks! </strong></p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/11/16/decompiling-java-class/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Quicksort in Scala</title>
		<link>http://www.vogella.de/blog/2009/11/13/quicksort-in-scala/</link>
		<comments>http://www.vogella.de/blog/2009/11/13/quicksort-in-scala/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 05:57:47 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=1283</guid>
		<description><![CDATA[Scala  allows to define very short and precise the intension of the programmer. To demonstrate this I use Quicksort as an Example.

The following is an implementation of quicksort in Scala. 



And a little test




To learn more about Scala check out this introduction tutorial: Scala development with Eclipse 

Update: this example is similar to ...]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vogella.de/articles/Scala/article.html">Scala </a> allows to define very short and precise the intension of the programmer. To demonstrate this I use <a href="http://www.vogella.de/articles/JavaAlgorithmsQuicksort/article.html">Quicksort </a>as an Example.</p>
<p>The following is an implementation of quicksort in Scala. </p>
<pre class="brush: scala; title: ; notranslate">

package de.vogella.scala.quicksort

/* Quicksort in Scala */
class Quicksort {
	def sort(a:Array[Int]): Array[Int] =
		if (a.length &lt; 2) a
		else {
			val pivot = a(a.length / 2)
			sort (a filter (pivot&gt;)) ++ (a filter (pivot == )) ++
				sort (a filter(pivot &lt;))
		}
}
</pre>
<p>And a little test</p>
<pre class="brush: scala; title: ; notranslate">

package de.vogella.scala.quicksort

object Test {
  def main(args: Array[String]) = {
    val quicksort = new Quicksort
	val a = Array(5, 3, 2, 2, 1, 1, 9, 39 ,219)
	quicksort.sort(a).foreach(n=&gt; (print(n), print (&quot; &quot; )))

  }
}
</pre>
<p>To learn more about Scala check out this introduction tutorial: <a href="http://www.vogella.de/articles/Scala/article.html">Scala development with Eclipse </a></p>
<p><strong>Update</strong>: this example is similar to the quicksort example from the excellent online <a href="http://www.scala-lang.org/docu/files/ScalaByExample.pdf">Scala by Example book</a>. Caution: The link is a pdf document.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.vogella.de/blog/?flattrss_redirect&amp;id=1283&amp;md5=4aa6cececf6742983e33fc239160a346" title="Flattr" target="_blank"><img src="http://www.vogella.de/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/11/13/quicksort-in-scala/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Collection of Java related Podcasts</title>
		<link>http://www.vogella.de/blog/2009/08/06/java-podcasts/</link>
		<comments>http://www.vogella.de/blog/2009/08/06/java-podcasts/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 16:08:10 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Podcasts]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=810</guid>
		<description><![CDATA[The following is a list of my favorite Java and Java related Podcasts. Please feel free to suggest additional Java podcasts.

 Java Podcasts:

Javaposse

Most likely the best known Java podcast is Javaposse which can be found on http://javaposse.com/.In this podcast Tor Norbye, Carl Quinn, Dick Wall and Joe Nuxoll discuss the news around Java and ...]]></description>
			<content:encoded><![CDATA[<p>The following is a list of my favorite Java and Java related Podcasts. Please feel free to suggest additional Java podcasts.</p>
<p><strong> Java Podcasts:</strong></p>
<p><strong><a href="http://javaposse.com/">Javaposse</a></strong></p>
<p>Most likely the best known Java podcast is Javaposse which can be found on <a href="http://javaposse.com/">http://javaposse.com/</a>.In this podcast Tor Norbye, Carl Quinn, Dick Wall and Joe Nuxoll discuss the news around Java and the Java Virtual Machine  and perform interviews with the key player in the Java world. They also cover news about Scala.</p>
<p>This podcast is in english.</p>
<p><strong><a href="http://live.eclipse.org/"> Eclipse live </a></strong></p>
<p>Eclipse related web seminars and podcasts can be found on <a href="http://live.eclipse.org/">http://live.eclipse.org/</a> .</p>
<p>Theses podcasts are (mainly) in english.</p>
<p><strong><a href="http://feeds.javahispano.org/JHPodcasts">Javahispano</a></strong></p>
<p>Spanish podcast around Java technology and Java news can be found <a href="http://feeds.javahispano.org/JHPodcasts">http://feeds.javahispano.org/JHPodcasts</a></p>
<p>This podcast is in spanish.</p>
<p><strong><a href="http://lescastcodeurs.com/">Les cast codeurs</a></strong></p>
<p>French podcast around Java technology and Java news can be found at <a href="http://lescastcodeurs.com/">http://lescastcodeurs.com/</a>.</p>
<p>This podcast is in french.</p>
<p><strong>Java related (covering also other topics)</strong></p>
<p><strong><a href="http://www.se-radio.net/">Software Engineering Radio </a></strong></p>
<p>Software Engineering Radio performs interesting interviews with the technical stars from different programming areas (including Java technology). They also have sessions there they explain on a starter level technology for example &#8220;what is database&#8221;.</p>
<p><a href="http://www.se-radio.net/">http://www.se-radio.net/</a></p>
<p>This podcast is in english.</p>
<p><strong><a href="http://www.ibm.com/developerworks/podcast/">IBM Developerworks</a></strong></p>
<p>IBM developerworks features mainly interviews about all kinds of topics including lots of Java and JVM related informations.</p>
<p><a href="http://www.ibm.com/developerworks/podcast/">http://www.ibm.com/developerworks/podcast/</a></p>
<p>This podcast is in english.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.vogella.de/blog/?flattrss_redirect&amp;id=810&amp;md5=b09f39d6dd23879df4fbb5a273069573" title="Flattr" target="_blank"><img src="http://www.vogella.de/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/08/06/java-podcasts/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using Collections.sort and Comparator in Java</title>
		<link>http://www.vogella.de/blog/2009/08/04/collections-sort-java/</link>
		<comments>http://www.vogella.de/blog/2009/08/04/collections-sort-java/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 20:17:18 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Basics]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=794</guid>
		<description><![CDATA[Sorting a collection in Java is easy, just use Collections.sort(Collection) to sort your values. For example:



This is possible because Integer implements the Comparable interface. This interface defines the method compare which performs pairwise comparison of the elements and returns -1 if the element is smaller then the compared element, 0 if it is equal ...]]></description>
			<content:encoded><![CDATA[<p>Sorting a collection in Java is easy, just use Collections.sort(Collection) to sort your values. For example:</p>
<pre class="brush: java; title: ; notranslate">
package de.vogella.algorithms.sort.standardjava;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Simple {
	public static void main(String[] args) {
		List list = new ArrayList();
		list.add(5);
		list.add(4);
		list.add(3);
		list.add(7);
		list.add(2);
		list.add(1);
		Collections.sort(list);
		for (Integer integer : list) {
			System.out.println(integer);
		}
	}
}
</pre>
<p>This is possible because Integer implements the Comparable interface. This interface defines the method compare which performs pairwise comparison of the elements and returns -1 if the element is smaller then the compared element, 0 if it is equal and 1 if it is larger. </p>
<p>But what if what to sort differently, e.g. for example in different order. Well, you could just use Collection.reverse(). Or you define your own class with implements the interface Comparator. </p>
<pre class="brush: java; title: ; notranslate">
package de.vogella.algorithms.sort.standardjava;

import java.util.Comparator;

public class MyIntComparable implements Comparator&lt;Integer&gt;{

	@Override
	public int compare(Integer o1, Integer o2) {
		return (o1&gt;o2 ? -1 : (o1==o2 ? 0 : 1));
	}
}
</pre>
<pre class="brush: java; title: ; notranslate">
package de.vogella.algorithms.sort.standardjava;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Simple2 {
	public static void main(String[] args) {
		List&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
		list.add(5);
		list.add(4);
		list.add(3);
		list.add(7);
		list.add(2);
		list.add(1);
		Collections.sort(list, new MyIntComparable());
		for (Integer integer : list) {
			System.out.println(integer);
		}
	}
}
</pre>
<p>The nice thing about this approach is that you then <strong>sort any object by any attribute or even a combination of attributes</strong>. For example if you have objects of type Person with an attribute income and dataOfBirth you could define different implementations of  Comparator and sort the objects according to your needs.</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/08/04/collections-sort-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Java Performance with Strings and StringBuilder</title>
		<link>http://www.vogella.de/blog/2009/07/19/java-string-performanc/</link>
		<comments>http://www.vogella.de/blog/2009/07/19/java-string-performanc/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 16:59:06 +0000</pubDate>
		<dc:creator>Lars Vogel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.vogella.de/blog/?p=585</guid>
		<description><![CDATA[Strings are very frequently used in Java programs. This blog post tries to explain what a programmer needs to consider from a performance point of view.  It will also explain in what situations you should use StringBuilder instead of String.

Strings in Java are immutable. If you look at the source code of String ...]]></description>
			<content:encoded><![CDATA[<p>Strings are very frequently used in Java programs. This blog post tries to explain what a programmer needs to consider from a performance point of view.  It will also explain in what situations you should use StringBuilder instead of String.</p>
<p>Strings in Java are <a href="http://www.vogella.de/articles/JavaConcurrency/article.html#immutability">immutable</a>. If you look at the source code of String you find that java.lang.String has the following properties.</p>
<pre class="brush: java; title: ; notranslate">
/** The value is used for character storage. */
    private final char value[];

 /** The offset is the first index of the storage that is used. */
    private final int offset;

 /** The count is the number of characters in the String. */
    private final int count;
</pre>
<p>The array is used to store the values of this String. </p>
<p>As Strings are immutable they can be freely shared. This property is utilized in the method substring(). The method substring will use a reference to the same String and only change the offset and the lenght value for the String. The same string is in this case used several times. </p>
<p>Therefore using  <strong> substring requires only a constant amount of time (and almost no additional memory) and can be freely used</strong>.</p>
<p>The operation  <strong> concat() </strong> (which is called by the + operator) combines two Strings. This method has to copy the characters of the two Strings and therefore  <strong>takes time and extra space which is propotional to the length of the two strings  </strong>.</p>
<p>The object StringBuilder has a more effectly way of concatenate Strings. It works similar to the class ArrayList by allocating a predefined array for storing the characters and keeps track of the used space. Every time the space is exceeded then it will extend the available capacity).</p>
<p>Does this means that you always have to use StringBuilder if you are concatening strings? </p>
<p>No. Of course if in your program you combine only a few times String the runtime overhead is normally not relevant for the overall performance. </p>
<p>But of course if you combine frequently strings in your program you should switch to StringBuilder. </p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.vogella.de/blog/2009/07/19/java-string-performanc/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

