Difference between revisions of "Java Examples"

From Info216
Line 1: Line 1:
 
Here are the code examples we have used in the live sessions during the lectures - along with a few additional ones.
 
Here are the code examples we have used in the live sessions during the lectures - along with a few additional ones.
  
''(To appear as the course progresses.)''
+
''(More will appear as the course progresses.)''
 +
 
 +
==Lecture 1: Java, Jena, and Eclipse==
 +
===Hello Jena===
 +
 
 +
<nowiki>
 +
package no.uib.sinoa.info216;
 +
 
 +
import org.apache.jena.rdf.model.Model;
 +
import org.apache.jena.rdf.model.ModelFactory;
 +
import org.apache.jena.rdf.model.Resource;
 +
import org.apache.jena.vocabulary.FOAF;
 +
 
 +
public class HelloJena {
 +
 
 +
    public static void main(String[] args) {
 +
     
 +
        Model model = ModelFactory.createDefaultModel();
 +
     
 +
        Resource andreas = model.createResource("http://no.uib.infomedia.info216.ex/CadeTracy");
 +
        andreas.addLiteral(FOAF.name, "Cade Tracy");
 +
     
 +
        model.write(System.out, "TURTLE");
 +
    } 
 +
}</nowiki>
 +
 
 +
&nbsp;
  
 
<div class="credits" style="text-align: right; direction: ltr; margin-left: 1em;">''INFO216, UiB, Spring 2017-2018, Andreas L. Opdahl (c). All code examples are [https://creativecommons.org/choose/zero/ CC0].'' </div>
 
<div class="credits" style="text-align: right; direction: ltr; margin-left: 1em;">''INFO216, UiB, Spring 2017-2018, Andreas L. Opdahl (c). All code examples are [https://creativecommons.org/choose/zero/ CC0].'' </div>

Revision as of 20:58, 17 January 2018

Here are the code examples we have used in the live sessions during the lectures - along with a few additional ones.

(More will appear as the course progresses.)

Lecture 1: Java, Jena, and Eclipse

Hello Jena

package no.uib.sinoa.info216;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.FOAF;

public class HelloJena {

    public static void main(String[] args) {
       
        Model model = ModelFactory.createDefaultModel();
       
        Resource andreas = model.createResource("http://no.uib.infomedia.info216.ex/CadeTracy");
        andreas.addLiteral(FOAF.name, "Cade Tracy");
       
        model.write(System.out, "TURTLE");
    }   
}

 

INFO216, UiB, Spring 2017-2018, Andreas L. Opdahl (c). All code examples are CC0.