diff options
Diffstat (limited to '.html/java')
| -rw-r--r-- | .html/java/_list.html | 101 | ||||
| -rw-r--r-- | .html/java/a-new-kind-of.html | 203 | ||||
| -rw-r--r-- | .html/java/index.html | 101 | ||||
| -rw-r--r-- | .html/java/install/_list.html | 96 | ||||
| -rw-r--r-- | .html/java/install/centos.html | 136 | ||||
| -rw-r--r-- | .html/java/install/index.html | 102 | ||||
| -rw-r--r-- | .html/java/install/ubuntu.html | 158 | ||||
| -rw-r--r-- | .html/java/kwargs.html | 223 | ||||
| -rw-r--r-- | .html/java/stop-using-class-dot-forname.html | 155 |
9 files changed, 1275 insertions, 0 deletions
diff --git a/.html/java/_list.html b/.html/java/_list.html new file mode 100644 index 0000000..4b6c78f --- /dev/null +++ b/.html/java/_list.html @@ -0,0 +1,101 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + ls /java + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="./">java</a> + + </li> + + <li class="crumb-2 last"> + + <span class="list-crumb">list</span> + + </li> + + </ol> + + + + <div id="listing"> + <h1><code>ls /java</code></h1> + + + <div id="directories"> + <h2>Directories</h2> + <ul> + + <li><a href="install/">install/</a></li> + + </ul> + </div> + + + + <div id="pages"> + <h2>Pages</h2> + <ul> + + <li><a href="a-new-kind-of">A New Kind of Java</a></li> + + <li><a href="kwargs">Keyword Arguments in Java</a></li> + + <li><a href="stop-using-class-dot-forname">Stop Using Class Dot Forname</a></li> + + </ul> + </div> + + + + </div> + + + + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java">See this directory on Bitbucket</a>. + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file diff --git a/.html/java/a-new-kind-of.html b/.html/java/a-new-kind-of.html new file mode 100644 index 0000000..764fb45 --- /dev/null +++ b/.html/java/a-new-kind-of.html @@ -0,0 +1,203 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + A New Kind of Java + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="./">java</a> + + </li> + + <li class="crumb-2 last"> + + a-new-kind-of + + </li> + + </ol> + + + + <div id="article"> + <h1 id="a-new-kind-of-java">A New Kind of Java</h1> +<p>Java 8 is almost here. You can <a href="http://jdk8.java.net/download.html">play with the early access +previews</a> right now, and I think you +should, even if you don't like Java very much. There's so much <em>potential</em> in +there.</p> +<h2 id="the-one-more-thing">The “One More Thing”</h2> +<p>The Java 8 release comes with a slew of notable library improvements: the new +<a href="http://openjdk.java.net/jeps/150"><code>java.time</code></a> package, designed by the folks +behind the extremely capable Joda time library; <a href="http://openjdk.java.net/jeps/118">reflective +access</a> to parameter names; <a href="http://openjdk.java.net/jeps/133">Unicode +6.2</a> support; numerous others. But all of +these things are dwarfed by the “one last thing”:</p> +<p><strong>Lambdas</strong>.</p> +<h2 id="ok-so">Ok, So..?</h2> +<p>Here's the thing: all of the “modern” languages that see regular use - C#, +Python, Ruby, the various Lisps including Clojure, and Javascript - have +language features allowing easy creation and use of one-method values. In +Python, that's any object with a <code>__call__</code> method (including function +objects); in Ruby, it's blocks; in Javascript, it's <code>function() {}</code>s. These +features allow <em>computation itself</em> to be treated as a value and passed +around, which in turn provides a very powerful and succinct mechanism for +composing features.</p> +<p>Java's had the “use” side down for a long time; interfaces like <code>Runnable</code> are +a great example of ways to expose “function-like” or “procedure-like” types to +the language without violating Java's bureaucratic attitude towards types and +objects. However, the syntax for creating these one-method values has always +been so verbose and awkward as to discourage their use. Consider, for example, +a simple “task” for a thread pool:</p> +<pre><code>pool.execute(new Runnable() { + @Override + public void run() { + System.out.println("Hello, world!"); + } +}); +</code></pre> +<p>(Sure, it's a dumb example.)</p> +<p>Even leaving out the optional-but-recommended <code>@Override</code> annotation, that's +still five lines of code that only exist to describe to the compiler how to +package up a block as an object. Yuck. For more sophisticated tasks, this sort +of verbosity has lead to multi-role “event handler” interfaces, to amortize +the syntactic cost across more blocks of code.</p> +<p>With Java 8's lambda support, the same (dumb) example collapses to</p> +<pre><code>pool.execute(() -> System.out.println("Hello, world")); +</code></pre> +<p>It's the same structure and is implemented very similarly by the compiler. +However, it's got much greater informational density for programmers reading +the code, and it's much more pleasant to write.</p> +<p>If there's any justice, this will completely change how people design Java +software.</p> +<h2 id="event-driven-systems">Event-Driven Systems</h2> +<p>As an example, I knocked together a simple “event driven IO” system in an +evening, loosely inspired by node.js. Here's the echo server I wrote as an +example application, in its entirety:</p> +<pre><code>package com.example.onepointeight; + +import java.io.IOException; + +public class Echo { + public static void main(String[] args) throws IOException { + Reactor.run(reactor -> + reactor.listen(3000, client -> + reactor.read(client, data -> { + data.flip(); + reactor.write(client, data); + }) + ) + ); + } +} +</code></pre> +<p>It's got a bad case of Javascript “arrow” disease, but it demonstrates the +expressive power of lambdas for callbacks. This is built on NIO, and runs in a +single thread; as with any decent multiplexed-IO application, it starts to +have capacity problems due to memory exhaustion well before it starts to +struggle with the number of clients. Unlike Java 7 and earlier, though, the +whole program is short enough to keep in your head without worrying about the +details of how each callback is converted into an object and without having to +define three or four extra one-method classes.</p> +<h2 id="contextual-operations">Contextual operations</h2> +<p>Sure, we all know you use <code>try/finally</code> (or, if you're up on your Java 7, +<code>try()</code>) to clean things up. However, context isn't always as tidy as that: +sometimes things need to happen while it's set up, and un-happen when it's +being torn down. The folks behind JdbcTemplate already understood that, so you +can already write SQL operations using a syntax similar to</p> +<pre><code>User user = connection.query( + "SELECT login, group FROM users WHERE username = ?", + username, + rows -> rows.one(User::fromRow) +); +</code></pre> +<p>Terser <strong>and</strong> clearer than the corresponding try-with-resources version:</p> +<pre><code>try (PreparedStatement ps = connection.prepare("SELECT login, group FROM users WHERE username = ?")) { + ps.setString(1, username); + try (ResultSet rows = rs.execute()) { + if (!rows.next()) + throw new NoResultFoundException(); + return User.fromRow(rows); + } +} +</code></pre> +<h2 id="domain-specific-languages">Domain-Specific Languages</h2> +<p>I haven't worked this one out, yet, but I think it's possible to use lambdas +to implement conversational interfaces, similar in structure to “fluent” +interfaces like +<a href="http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/UriBuilder.html">UriBuilder</a>. +If I can work out the mechanics, I'll put together an example for this, but +I'm half convinced something like</p> +<pre><code>URI googleIt = Uris.create(() -> { + scheme("http"); + host("google.com"); + path("/"); + queryParam("q", "hello world"); +}); +</code></pre> +<p>is possible.</p> + </div> + + + +<div id="comments"> +<div id="disqus_thread"></div> +<script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'grimoire'; // required: replace example with your forum shortname + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); +</script> +<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> +<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> +</div> + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java/a-new-kind-of.md">See this page on Bitbucket</a> (<a href="https://bitbucket.org/ojacobson/grimoire.ca/history-node/master/wiki/java/a-new-kind-of.md">history</a>). + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file diff --git a/.html/java/index.html b/.html/java/index.html new file mode 100644 index 0000000..4b6c78f --- /dev/null +++ b/.html/java/index.html @@ -0,0 +1,101 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + ls /java + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="./">java</a> + + </li> + + <li class="crumb-2 last"> + + <span class="list-crumb">list</span> + + </li> + + </ol> + + + + <div id="listing"> + <h1><code>ls /java</code></h1> + + + <div id="directories"> + <h2>Directories</h2> + <ul> + + <li><a href="install/">install/</a></li> + + </ul> + </div> + + + + <div id="pages"> + <h2>Pages</h2> + <ul> + + <li><a href="a-new-kind-of">A New Kind of Java</a></li> + + <li><a href="kwargs">Keyword Arguments in Java</a></li> + + <li><a href="stop-using-class-dot-forname">Stop Using Class Dot Forname</a></li> + + </ul> + </div> + + + + </div> + + + + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java">See this directory on Bitbucket</a>. + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file diff --git a/.html/java/install/_list.html b/.html/java/install/_list.html new file mode 100644 index 0000000..4af64c6 --- /dev/null +++ b/.html/java/install/_list.html @@ -0,0 +1,96 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + ls /java/install + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="../">java</a> + + </li> + + <li class="crumb-2 not-last"> + + <a href="./">install</a> + + </li> + + <li class="crumb-3 last"> + + <span class="list-crumb">list</span> + + </li> + + </ol> + + + + <div id="listing"> + <h1><code>ls /java/install</code></h1> + + + + + <div id="pages"> + <h2>Pages</h2> + <ul> + + <li><a href="centos">Installing Java on CentOS</a></li> + + <li><a href="ubuntu">Installing Java on Ubuntu</a></li> + + </ul> + </div> + + + + </div> + + + + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java/install">See this directory on Bitbucket</a>. + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file diff --git a/.html/java/install/centos.html b/.html/java/install/centos.html new file mode 100644 index 0000000..9bbf3f4 --- /dev/null +++ b/.html/java/install/centos.html @@ -0,0 +1,136 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + Installing Java on CentOS + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="../">java</a> + + </li> + + <li class="crumb-2 not-last"> + + <a href="./">install</a> + + </li> + + <li class="crumb-3 last"> + + centos + + </li> + + </ol> + + + + <div id="article"> + <h1 id="installing-java-on-centos">Installing Java on CentOS</h1> +<p>Verified as of CentOS 5.8, Java 6. CentOS 6 users: fucking switch to Debian +already. Is something wrong with you? Do you like being abused by your +vendors?</p> +<h2 id="from-package-management-yum">From Package Management (Yum)</h2> +<p>OpenJDK is available via <a href="http://fedoraproject.org/wiki/EPEL/FAQ">EPEL</a>, from +the Fedora project. Install EPEL before proceeding.</p> +<p>You didn't install EPEL. Go install EPEL. <a href="http://fedoraproject.org/wiki/EPEL/FAQ#Using_EPEL">The directions are in the EPEL +FAQ</a>.</p> +<p>Now install the JDK:</p> +<pre><code>sudo yum install java-1.6.0-openjdk-devel +</code></pre> +<p>Or just the runtime:</p> +<pre><code>sudo yum install java-1.6.0-openjdk +</code></pre> +<p>The RPMs place the appropriate binaries in <code>/usr/bin</code>.</p> +<p>Applications that can't autodetect the JDK may need <code>JAVA_HOME</code> set to +<code>/usr/lib/jvm/java-openjdk</code>.</p> +<h2 id="by-hand">By Hand</h2> +<p>The <a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html">Java SE Development Kit +7</a> +tarballs can be installed by hand. Download the “Linux x64” <code>.tar.gz</code> version, +then unpack it in <code>/opt</code>:</p> +<pre><code>cd /opt +tar xzf ~/jdk-7u45-linux-x64.tar.gz +</code></pre> +<p>This will create a directory named <code>/opt/jdk1.7.0_45</code> (actual version number +may vary) containing a ready-to-use Java dev kit.</p> +<p>You will need to add the JDK's <code>bin</code> directory to <code>PATH</code> if you want commands +like <code>javac</code> and <code>java</code> to work without fully-qualifying the directory:</p> +<pre><code>cat > /etc/profile.d/oracle_jdk <<'ORACLE_JDK' +PATH="${PATH}:/opt/jdk1.7.0_45/bin" +export PATH +ORACLE_JDK +</code></pre> +<p>(This will not affect non-interactive use; setting PATH for non-interactive +programs like build servers is beyond the scope of this document. Learn to use +your OS.)</p> +<p>Installation this way does <em>not</em> interact with the alternatives system (but +you can set that up by hand if you need to).</p> +<p>For tools that cannot autodetect the JDK via <code>PATH</code>, you may need to set +<code>JAVA_HOME</code> to <code>/opt/jdk1.7.0_45</code>.</p> + </div> + + + +<div id="comments"> +<div id="disqus_thread"></div> +<script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'grimoire'; // required: replace example with your forum shortname + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); +</script> +<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> +<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> +</div> + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java/install/centos.md">See this page on Bitbucket</a> (<a href="https://bitbucket.org/ojacobson/grimoire.ca/history-node/master/wiki/java/install/centos.md">history</a>). + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file diff --git a/.html/java/install/index.html b/.html/java/install/index.html new file mode 100644 index 0000000..d167e58 --- /dev/null +++ b/.html/java/install/index.html @@ -0,0 +1,102 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + Installing Java … + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="../">java</a> + + </li> + + <li class="crumb-2 last"> + + install + + </li> + + </ol> + + + + <div id="article"> + <h1 id="installing-java">Installing Java …</h1> +<p>This document provided as a community service to +<a href="irc://irc.freenode.org/##java">##java</a>. Provided as-is; pull requests +welcome.</p> +<ol> +<li> +<p><a href="ubuntu">… on Ubuntu</a> (may also be applicable to Debian; needs verification + from a Debian user)</p> +</li> +<li> +<p><a href="centos">… on CentOS</a> (probably also applicable to RHEL; needs verification + from a RHEL user)</p> +</li> +</ol> + </div> + + + +<div id="comments"> +<div id="disqus_thread"></div> +<script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'grimoire'; // required: replace example with your forum shortname + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); +</script> +<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> +<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> +</div> + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java/install/index.md">See this page on Bitbucket</a> (<a href="https://bitbucket.org/ojacobson/grimoire.ca/history-node/master/wiki/java/install/index.md">history</a>). + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file diff --git a/.html/java/install/ubuntu.html b/.html/java/install/ubuntu.html new file mode 100644 index 0000000..0d81292 --- /dev/null +++ b/.html/java/install/ubuntu.html @@ -0,0 +1,158 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + Installing Java on Ubuntu + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="../">java</a> + + </li> + + <li class="crumb-2 not-last"> + + <a href="./">install</a> + + </li> + + <li class="crumb-3 last"> + + ubuntu + + </li> + + </ol> + + + + <div id="article"> + <h1 id="installing-java-on-ubuntu">Installing Java on Ubuntu</h1> +<p>Accurate as of: Java 7, Ubuntu 12.04. The instructions below assume an amd64 +(64-bit) installation. If you're still using a 32-bit OS, work out the +differences yourself.</p> +<h2 id="via-package-management-apt">Via Package Management (Apt)</h2> +<p>OpenJDK 7 is available via apt by default.</p> +<p>To install the JDK:</p> +<pre><code>sudo aptitude update +sudo aptitude install openjdk-7-jdk +</code></pre> +<p>To install the JRE only (without the JDK):</p> +<pre><code>sudo aptitude update +sudo aptitude install openjdk-7-jre +</code></pre> +<p>To install the JRE without GUI support (appropriate for headless servers):</p> +<pre><code>sudo aptitude update +sudo aptitude install openjdk-7-jre-headless +</code></pre> +<p>(You can also use <code>apt-get</code> instead of <code>aptitude</code>.)</p> +<p>These packages interact with <a href="http://manpages.ubuntu.com/manpages/hardy/man8/update-alternatives.8.html">the <code>alternatives</code> +system</a>, +and have <a href="http://manpages.ubuntu.com/manpages/hardy/man8/update-java-alternatives.8.html">a dedicated <code>alternatives</code> manager +script</a>. +The <code>alternatives</code> system affects <code>/usr/bin/java</code>, <code>/usr/bin/javac</code>, and +browser plugins for applets and Java Web Start applications for browsers +installed via package management. It also affects the symlinks under +<code>/etc/alternatives</code> related to Java.</p> +<p>To list Java versions available, with at least one Java version installed via +Apt:</p> +<pre><code>update-java-alternatives --list +</code></pre> +<p>To switch to <code>java-1.7.0-openjdk-amd64</code> for all Java invocations:</p> +<pre><code>update-java-alternatives --set java-1.7.0-openjdk-amd64 +</code></pre> +<p>The value should be taken from the first column of the <code>--list</code> output.</p> +<h3 id="tool-support">Tool support</h3> +<p>Most modern Java tools will pick up the installed JDK via <code>$PATH</code> and do not +need the <code>JAVA_HOME</code> environment variable set explicitly. For applications old +enough not to be able to detect the JDK, you can set <code>JAVA_HOME</code> to +<code>/usr/lib/jvm/java-1.7.0-openjdk-amd64</code>.</p> +<h2 id="by-hand">By Hand</h2> +<p>The <a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html">Java SE Development Kit +7</a> +tarballs can be installed by hand. Download the “Linux x64” <code>.tar.gz</code> version, +then unpack it in <code>/opt</code>:</p> +<pre><code>cd /opt +tar xzf ~/jdk-7u45-linux-x64.tar.gz +</code></pre> +<p>This will create a directory named <code>/opt/jdk1.7.0_45</code> (actual version number +may vary) containing a ready-to-use Java dev kit.</p> +<p>You will need to add the JDK's <code>bin</code> directory to <code>PATH</code> if you want commands +like <code>javac</code> and <code>java</code> to work without fully-qualifying the directory:</p> +<pre><code>cat > /etc/profile.d/oracle_jdk <<'ORACLE_JDK' +PATH="${PATH}:/opt/jdk1.7.0_45/bin" +export PATH +ORACLE_JDK +</code></pre> +<p>(This will not affect non-interactive use; setting PATH for non-interactive +programs like build servers is beyond the scope of this document. Learn to use +your OS.)</p> +<p>Installation this way does <em>not</em> interact with the alternatives system (but +you can set that up by hand if you need to).</p> +<p>For tools that cannot autodetect the JDK via <code>PATH</code>, you may need to set +<code>JAVA_HOME</code> to <code>/opt/jdk1.7.0_45</code>.</p> + </div> + + + +<div id="comments"> +<div id="disqus_thread"></div> +<script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'grimoire'; // required: replace example with your forum shortname + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); +</script> +<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> +<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> +</div> + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java/install/ubuntu.md">See this page on Bitbucket</a> (<a href="https://bitbucket.org/ojacobson/grimoire.ca/history-node/master/wiki/java/install/ubuntu.md">history</a>). + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file diff --git a/.html/java/kwargs.html b/.html/java/kwargs.html new file mode 100644 index 0000000..64cc16b --- /dev/null +++ b/.html/java/kwargs.html @@ -0,0 +1,223 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + Keyword Arguments in Java + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="./">java</a> + + </li> + + <li class="crumb-2 last"> + + kwargs + + </li> + + </ol> + + + + <div id="article"> + <h1 id="keyword-arguments-in-java">Keyword Arguments in Java</h1> +<h2 id="what">What</h2> +<p>Java arguments are traditionally passed by position:</p> +<pre><code>void foo(int x, int y, int z) +</code></pre> +<p>matches the call</p> +<pre><code>foo(1, 2, 3) +</code></pre> +<p>and assigns <code>1</code> to <code>x</code>, <code>2</code> to <code>y</code>, and <code>3</code> to <code>z</code> in the resulting +activation. Keyword arguments assign values to formal parameters by matching +the parameter's name, instead.</p> +<h2 id="why">Why</h2> +<p>Fuck the builder pattern, okay? Patterns like</p> +<pre><code>Response r = Response + .status(200) + .entity(foo) + .header("X-Plane", "Amazing") + .build(); +</code></pre> +<p>(from JAX-RS) mean the creation and maintenance of an entire separate type +just to handle arbitrary ordering and presence/absence of options. Ordering +can be done using keywords; presence/absence can be done by providing one +method for each legal combination of arguments (or by adding optional +arguments to Java).</p> +<p>The keyword-argument version would be something like</p> +<pre><code>Response r = new Response( + .status = 200, + .entity = foo, + .headers = Arrays.asList(Header.of("X-Plane", "Amazing")) +); +</code></pre> +<p>and the <code>ResponseBuilder</code> class would not need to exist at all for this case. +(There are others in JAX-RS that would still make <code>ResponseBuilder</code> mandatory, +but the use case for it gets much smaller.)</p> +<p>As an added bonus, the necessary class metadata to make this work would also +allow reflective frameworks such as Spring to make sensible use of the +parameter names:</p> +<pre><code><bean class="com.example.Person"> + <constructor-arg name="name" value="Erica McKenzie" /> +</bean> +</code></pre> +<h2 id="other-languages">Other Languages</h2> +<p>Python, most recently:</p> +<pre><code>def foo(x, y, z): + pass + +foo(z=3, x=1, y=2) +</code></pre> +<p>Smalltalk (and ObjectiveC) use an interleaving convention that reads very much +like keyword arguments:</p> +<pre><code>Point atX: 5 atY: 8 +</code></pre> +<h2 id="challenges">Challenges</h2> +<ul> +<li>Minimize changes to syntax.<ul> +<li>Make keyword arguments unambiguous.</li> +</ul> +</li> +<li>Minimize changes to bytecode spec.</li> +</ul> +<h2 id="proposal">Proposal</h2> +<p>Given a method definition</p> +<pre><code>void foo(int x, int y, int z) +</code></pre> +<p>Allow calls written as</p> +<pre><code>foo( + SOME-SYNTAX(x, EXPR), + SOME-SYNTAX(y, EXPR), + SOME-SYNTAX(z, EXPR) +) +</code></pre> +<p><code>SOME-SYNTAX</code> is a production that is not already legal at that point in Java, +which is a surprisingly frustrating limitation. Constructs like</p> +<pre><code>foo(x = EXPR, y = EXPR, z = EXPR) +</code></pre> +<p>are already legal (assignment is an expression) and already match positional +arguments.</p> +<p>Keyword arguments match the name of the formal argument in the method +declaration. Passing a keyword argument that does not match a formal argument +is a compilation error.</p> +<p>Calls can mix keyword arguments and positional arguments, in the following +order:</p> +<ol> +<li>Positional arguments.</li> +<li>Varargs positional arguments.</li> +<li>Keyword arguments.</li> +</ol> +<p>Passing the same argument as both a positional and a keyword argument is a +compilation error.</p> +<p>Call sites must satisfy every argument the method/constructor has (i.e., this +doesn't imply optional arguments). This makes implementation easy and +unintrusive: the compiler can implement keyword arguments by transforming them +into positional arguments. Reflective calls (<code>Method.invoke</code> and friends) can +continue accepting arguments as a sequence.</p> +<p>The <code>Method</code> class would expose a new method:</p> +<pre><code>public List<String> getArgumentNames() +</code></pre> +<p>The indexes in <code>getArgumentNames</code> match the indexes in <code>getArgumentTypes</code> and +related methods.</p> +<p>Possibilities for syntax:</p> +<ul> +<li> +<p><code>foo(x := 5, y := 8, z := 2)</code> - <code>:=</code> is never a legal sequence of tokens in + Java. Introduces one new operator-like construct; the new sequence <code>:=</code> + “looks like” assignment, which is a useful mnemonic.</p> +</li> +<li> +<p><code>foo(x ~ 5, y ~ 8, z ~ 2)</code> - <code>~</code> is not a binary operator and this is never + legal right now. This avoids introducing new operators, but adds a novel + interpretation to an existing unary operator that's not related to its + normal use.</p> +</li> +<li> +<p><code>foo(.x = 5, .y = 8, .z = 2)</code> - using <code>=</code> as the keyword binding feels more + natural. Parameter names must be legal identifiers, which means the leading + dot is unambiguous. This syntax is not legal anywhere right now (the dot + always has a leading expression). The dot is a “namespace” symbol already.</p> +</li> +</ul> +<p>To support this, the class file format will need to record the names of +parameters, not just their order. This is a breaking change, and generated +names will need to be chosen for existing class files. (This may be derivable +from debug information, where present.)</p> +<h2 id="edge-cases">Edge Cases</h2> +<ul> +<li>Mixed positional and keyword arguments.<ul> +<li>Collisions (same argument passed by both) are, I think, detectable at + compile time. This should be an error.</li> +</ul> +</li> +<li>Inheritance. It is legal for a superclass to define <code>foo(a, b)</code> and for + subclasses to override it as <code>foo(x, y)</code>. Which argument names do you use + when?</li> +<li>Varargs.</li> +</ul> + </div> + + + +<div id="comments"> +<div id="disqus_thread"></div> +<script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'grimoire'; // required: replace example with your forum shortname + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); +</script> +<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> +<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> +</div> + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java/kwargs.md">See this page on Bitbucket</a> (<a href="https://bitbucket.org/ojacobson/grimoire.ca/history-node/master/wiki/java/kwargs.md">history</a>). + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file diff --git a/.html/java/stop-using-class-dot-forname.html b/.html/java/stop-using-class-dot-forname.html new file mode 100644 index 0000000..85190e8 --- /dev/null +++ b/.html/java/stop-using-class-dot-forname.html @@ -0,0 +1,155 @@ +<!DOCTYPE html> +<html> +<head> + <title> + The Codex » + Stop Using Class Dot Forname + </title> + + <link + rel='stylesheet' + type='text/css' + href='http://fonts.googleapis.com/css?family=Buenard:400,700&subset=latin,latin-ext'> + <link + rel="stylesheet" + type="text/css" + href="../media/css/reset.css"> + <link + rel="stylesheet" + type="text/css" + href="../media/css/grimoire.css"> +</head> +<body> + +<div id="shell"> + + <ol id="breadcrumbs"> + + <li class="crumb-0 not-last"> + + <a href="../">index</a> + + </li> + + <li class="crumb-1 not-last"> + + <a href="./">java</a> + + </li> + + <li class="crumb-2 last"> + + stop-using-class-dot-forname + + </li> + + </ol> + + + + <div id="article"> + <h1 id="jdbc-drivers-and-classforname">JDBC Drivers and <code>Class.forName()</code></h1> +<p>The short version: stop using <code>Class.forName(driverClass)</code> to load JDBC +drivers. You don't need this, and haven't since Java 6. You arguably never +needed this.</p> +<p>This pattern appears all over the internet, and it's wrong.</p> +<h2 id="backstory">Backstory</h2> +<p>JDBC has more or less always provided two ways to set up <code>Connection</code> objects:</p> +<ol> +<li> +<p>Obtain them from a driver-provided <code>DataSource</code> class, which applications or + containers are expected to create for themselves.</p> +</li> +<li> +<p>Obtain them by passing a URL to <code>DriverManager</code>.</p> +</li> +</ol> +<p>Most people start with the latter, since it's very straightforward to use. +However, <code>DriverManager</code> needs to be able to locate <code>Driver</code> subclasses, and +the JVM doesn't permit class enumeration at runtime.</p> +<p>In the original JDBC release, <code>Driver</code> subclasses were expected to register +themselves on load, similar to</p> +<pre><code>public class ExampleDriver extends Driver { + static { + DriverManager.registerDriver(ExampleDriver.class); + } +} +</code></pre> +<p>Obviously, applications <em>can</em> force drivers to load using +<code>Class.forName(driverName)</code>, but this hasn't ever been the only way to do it. +<code>DriverManager</code> also provides <a href="https://docs.oracle.com/javase/8/docs/api/java/sql/DriverManager.html">a mechanism to load a set of named classes at +startup</a>, +via the <code>jdbc.drivers</code> <a href="http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html">system property</a>.</p> +<h2 id="jdbc-4-fixed-that">JDBC 4 Fixed That</h2> +<p>JDBC 4, which came out with Java 6 in the Year of our Lord <em>Two Thousand and +Six</em>, also loads drivers using the <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Service%20Provider">service +provider</a> +system, which requires no intervention at all from deployers or application +developers.</p> +<p><em>You don't need to write any code to load a JDBC 4 driver.</em></p> +<h2 id="whats-the-harm">What's The Harm?</h2> +<p>It's harmless in the immediate sense: forcing a driver to load immediately +before JDBC would load it itself has no additional side effects. However, it's +a pretty clear indicator that you've copied someone else's code without +thoroughly understanding what it does, which is a bad habit.</p> +<h2 id="but-what-about-my-database">But What About My Database?</h2> +<p>You don't need to worry about it. All of the following drivers support JDBC +4-style automatic discovery:</p> +<ul> +<li> +<p>PostgreSQL (since version 8.0-321, in 2007)</p> +</li> +<li> +<p>Firebird (since <a href="http://tracker.firebirdsql.org/browse/JDBC-140">version 2.2, in 2009</a>)</p> +</li> +<li> +<p><a href="../mysql/choose-something-else">MySQL</a> (since <a href="http://dev.mysql.com/doc/relnotes/connector-j/en/news-5-0-0.html">version 5.0, in 2005</a>)</p> +</li> +<li> +<p>H2 (since day 1, as far as I can tell)</p> +</li> +<li> +<p>Derby/JavaDB (since <a href="https://issues.apache.org/jira/browse/DERBY-930">version 10.2.1.6, in 2006</a>)</p> +</li> +<li> +<p>SQL Server (version unknown, because MSDN is archaeologically hostile)</p> +</li> +</ul> + </div> + + + +<div id="comments"> +<div id="disqus_thread"></div> +<script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'grimoire'; // required: replace example with your forum shortname + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); +</script> +<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> +<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> +</div> + + + + <div id="footer"> + <p> + + The Codex — + + Powered by <a href="http://markdoc.org/">Markdoc</a>. + +<a href="https://bitbucket.org/ojacobson/grimoire.ca/src/master/wiki/java/stop-using-class-dot-forname.md">See this page on Bitbucket</a> (<a href="https://bitbucket.org/ojacobson/grimoire.ca/history-node/master/wiki/java/stop-using-class-dot-forname.md">history</a>). + + </p> + </div> + +</div> +</body> +</html>
\ No newline at end of file |
