<?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>crossedstreams.com &#187; Beginners</title>
	<atom:link href="http://blog.crossedstreams.com/category/beginners/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.crossedstreams.com</link>
	<description>Total protonic reversal!</description>
	<lastBuildDate>Sat, 21 Jan 2012 20:10:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Faster Java &#8211; Strings</title>
		<link>http://blog.crossedstreams.com/development/faster-java-strings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=faster-java-strings</link>
		<comments>http://blog.crossedstreams.com/development/faster-java-strings/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 18:20:21 +0000</pubDate>
		<dc:creator>Paul Brabban</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[concatenation]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[stringbuffer]]></category>
		<category><![CDATA[stringbuilder]]></category>

		<guid isPermaLink="false">http://blog.crossedstreams.com/?p=31</guid>
		<description><![CDATA[If you&#8217;re building a long String in Java, don&#8217;t stick String objects together using &#8216;+&#8217;, for example: String str = "Hello"; str = str + world; str = str + "!"; Why not? It&#8217;s really slow when you do it a lot! What should you do instead? Use the append(String) method in StringBuffer (Java 1.4.2 [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re building a long String in Java, don&#8217;t stick String objects together using &#8216;+&#8217;, for example:</p>
<pre class="prettyprint">
String str = "Hello";
str = str + world;
str = str + "!";</pre>
<p><strong>Why not?</strong></p>
<p>It&#8217;s really slow when you do it a lot!</p>
<p><strong>What should you do instead?</strong></p>
<p>Use the append(String) method in <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html" title="StringBuffer Java 1.4 API documentation">StringBuffer</a> (Java 1.4.2 on), or <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuilder.html" title="Java 5 StringBuilder API Documentation">StringBuilder</a> (Java 5 on). StringBuilder is slightly faster than StringBuffer, but is not thread safe. Both are much faster than concatenating String objects &#8211; by orders of magnitude. For example:</p>
<pre class="prettyprint">
StringBuffer str = new StringBuffer("Hello");
str.append(world);
str.append("!");</pre>
<p><span id="more-31"></span></p>
<p>I set up a simple test rig to concatenate ints onto a String in a loop, by simple &#8216;+&#8217; concatenation, then with a StringBuilder. Running a half dozen times and taking a rough average, the results are pretty conclusive &#8211; concatenating the wrong way can really slow things down.</p>
<ul>
<li>Over 10,000 repetitions, &#8216;+&#8217; takes around 650 times as long (670 ms vs. 1ms).</li>
<li>Over 20,000 reps, it takes around 1,800 times longer(3,500ms vs. 2ms).</li>
<li>Over 100,000 reps takes around <strong>41,000</strong> times longer! (over <strong>5 minutes</strong> vs. 8ms).</li>
</ul>
<p><strong>Why&#8217;s it so slow?</strong><br />
Strings in Java are <em>immutable</em>, which means that once a String is instantiated (be it by new String() or as a literal &#8220;blah&#8221;) it cannot be changed. When you concatenate one String to another, you actually create a third String which is the result of the concatenation</p>
<p>Not too much of an overhead, except when that concatenation is in some nested loop structure or the like and becomes a real bottleneck in your code. In that situation, you&#8217;re creating loads of objects that you&#8217;ll never use again and you&#8217;ll probably be running the Garbage Collector a lot to mop up, which makes things go even slower.</p>
<p>I first came across this when I got caught out building a big HTML table from database query results. When I was using String concatenation, it ran like a dog and the speed was pretty obviously dependent on the amount of concatenation going on. Read up on it, switched to StringBuilder, and the processing to put the String together went (in the worst case) from taking minutes to milliseconds. That&#8217;s the kind of performance improvement people notice.</p>
<p>There&#8217;s a little more to it, and if you&#8217;re interested, there&#8217;s more info and further optimisation steps <a href="http://www.precisejava.com/javaperf/j2se/StringAndStringBuffer.htm" title="PreciseJava String optimisation">here</a>. The SCJP 5 qualification also covers this and a load of other simple gotchas in Java SE.</p>
<div class="disclaimer">These are my thoughts and opinions and do not reflect
those of anyone else. Read the <a href="disclaimer">disclaimer</a> for more verbal
teflon.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.crossedstreams.com/development/faster-java-strings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My Website&#8217;s Pictures Won&#8217;t Load!</title>
		<link>http://blog.crossedstreams.com/development/why-dont-my-pictures-load-on-my-website/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-dont-my-pictures-load-on-my-website</link>
		<comments>http://blog.crossedstreams.com/development/why-dont-my-pictures-load-on-my-website/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 23:29:35 +0000</pubDate>
		<dc:creator>Paul Brabban</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[php html relative absolute src image link web script]]></category>

		<guid isPermaLink="false">http://crossedstreams.com/wordpress/?p=3</guid>
		<description><![CDATA[So you&#8217;ve got a website with some pictures that you&#8217;ve saved somewhere. The pictures work on some pages, maybe only one, put not on others. Your problem is all to do with relative links in your HTML. Relative and Absolute Links You&#8217;ll put the pictures on your page using HTML&#8217;s img tag, and it probably [...]]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve got a website with some pictures that you&#8217;ve saved somewhere. The pictures work on some pages, maybe only one, put not on others. Your problem is all to do with <strong>relative links</strong> in your HTML.<span id="more-3"></span></p>
<h2>Relative and Absolute Links</h2>
<p>You&#8217;ll put the pictures on your page using HTML&#8217;s img tag, and it probably looks a little like this&#8230;</p>
<p><code class="prettyprint">&lt;img src="my-picture.jpg" /&gt;</code></p>
<p>HTML is rendered by your browser, so you can ignore your PHP or anything else happening in your server &#8211; the good stuff is happening right there on your desktop. You&#8217;ve just told the browser to grab an image file called my-picture.jpg from the same directory that your HTML page is in. That&#8217;s fine if that&#8217;s where the picture happens to be, but if your other pages use the exact same tag and aren&#8217;t in the same directory, they&#8217;re not going to be able to find it.</p>
<p>How can you tell it&#8217;s a relative link? Because that src attribute&#8217;s value doesn&#8217;t start with a / (forward slash) character. That looks like this&#8230;</p>
<p><code class="prettyprint">&lt;img src="/my-picture.jpg" /&gt;</code></p>
<p>The browser will now look for the my-picture.jpg in the Document Root of your website. (that&#8217;s configurable, but normally it&#8217;s a directory called www or htdocs) It&#8217;s called an <strong>absolute link</strong>, because the browser will look in the same place regardless of where the HTML file being rendered happens to be.</p>
<p>Absolute links can also start with http:// and define the whole URL, for example&#8230;</p>
<p><code class="prettyprint">&lt;img src="http://crossedstreams.com/img/common/banner.gif" /&gt;</code></p>
<p>&#8230;handy if you need or want to point to a file that&#8217;s actually on a different webserver. If you&#8217;ve not done it before, try and use the image resource in the above example in your own HTML page.</p>
<h2>Other Relatively Absolute Stuff</h2>
<p>There&#8217;s a little more to relative links than just loading from the same directory as your HTML though. You can specify any location you have access to relative to the HTML page. To specify a sub-folder, use forward-slash &#8211; so if there was a folder called images in the same place as your HTML and the picture was in there, your original link would look like&#8230;</p>
<p><code class="prettyprint">&lt;img src="images/my-picture.jpg" /&gt;</code></p>
<p>You can also walk up the file structure, using <strong>&#8216;../&#8217;</strong> to mean &#8216;up one level from where the HTML file is&#8217;.</p>
<p>The same principle applies to any tags with a src attribute &#8211; the browser loads the the file, and the relative vs. absolute thing applies. If you get into JavaScript, then you&#8217;ll probably write your fancy scripty stuff in a file on its own, and then use the &lt;script&gt; tag with a src attribute to get your browser to load the script content from the file into your page. HTML anchors (the &lt;a&gt; tag) use href as an attribute, which also specifies a relative or absolute location.</p>
<h2>Decisions, Decisions&#8230;</h2>
<p>So which should you use? As with pretty much anything else to do with computers, it depends.</p>
<p>Absolute links are easier to understand because you don&#8217;t need to think about where the page being rendered happens to live &#8211; the downside is that you can&#8217;t deploy the website feature that uses those files as a nice neat tar or zip archive.</p>
<p>You&#8217;d use relative links if you needed to package up your snazzy new file upload feature or whatever so that it could just be deployed onto any site &#8211; however if you do use relative links, you have to be careful where you put your HTML files so that those links work.</p>
<h2>And on the Server-Side</h2>
<p>Although in the case of problems with these HTML tags, anything happening on the server-side (most likely PHP or PERL code that&#8217;s writing out the HTML to be sent to the browser) is a red herring, the same relative vs. absolute path idea applies for resources you&#8217;re including in your code. In this case, the equivalent of Document Root is<strong> &#8216;/&#8217;</strong> for UNIX-type systems and something like <strong>&#8216;C:\&#8217;</strong> for Windows, but the same stuff applies as to how you can locate resources you need when your code runs.</p>
<h2>That&#8217;s all Folks</h2>
<p>That&#8217;s all I got on the subject &#8211; try googling relative and absolute for other perspectives. Hopefully if you found this post it was of some use to you. Have a good one!</p>
<div class="disclaimer">These are my thoughts and opinions and do not reflect
those of anyone else. Read the <a href="disclaimer">disclaimer</a> for more verbal
teflon.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.crossedstreams.com/development/why-dont-my-pictures-load-on-my-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

