Java basics
Download
1 / 26

JAVA BASICS - PowerPoint PPT Presentation


  • 326 Views
  • Updated On :

JAVA BASICS. Why Java for this Project?. Its open source - FREE Java has tools that work well with rdf and xml Jena, Jdom, Saxon Can be run on UNIX,Windows,LINUX,etc GUI/Applet capabilities Igor’s application WE NEED TO LEARN IT ANYWAY! . How to run. JDK – Java Development Kit

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' JAVA BASICS' - Gabriel


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Why java for this project l.jpg
Why Java for this Project?

  • Its open source - FREE

  • Java has tools that work well with rdf and xml

    • Jena, Jdom, Saxon

  • Can be run on UNIX,Windows,LINUX,etc

  • GUI/Applet capabilities

  • Igor’s application

  • WE NEED TO LEARN IT ANYWAY!


How to run l.jpg
How to run

  • JDK – Java Development Kit

    • Basic compiler, linker, and libraries

  • IDE – Integrated Development Environment

    • NetBeans – netbeans.org


How to run4 l.jpg
How to run

  • Types of files

    • .java – source code

    • .class – executable code

    • .jar (java archive) - bundle of multiple files Tutorial - http://java.sun.com/docs/books/tutorial/jar/basics/index.html

    • Packages – groups of related classes in a directory


How to run5 l.jpg
How to run

  • Applications

    • javac – java compiler

      • Commandline - javac classname.java

    • java – executes application

      • Commandline - java classname

    • Jikes – faster version of java command

      • http://oss.software.ibm.com

      • Commandline – jikes classname


How to run6 l.jpg
How to run

  • Environment Variables

    • Path – searches computer for executeable

    • Classpath – searches computer for classes that need to be used


How to run7 l.jpg
How to run

  • Applets – java applications that are embedded in html and run in a browser

    • Appletviewer – shows sample in browser

      • Commandline – appletviewer appletpage.html


How to run8 l.jpg
How to run

  • Make – (if you are sick of javac and java)

    • Defines which components go together to make a program.

    • Defines how to "put the pieces together".

    • Keeps track of dependencies among components.

    • Helps avoid doing unnecessary work and forgetting to do necessary work


How to run9 l.jpg
How to run

  • Makefile – example

    default:

    javac Animal.java

    note: there is a tabspace in front of javac

    Commandline – make

    - This compiles the file called Animal.java


How to run10 l.jpg
How to run

  • Makefile – example

    Tiger.java: Tiger.java Animal.class

    javac Tiger.java

    Animal.class must exist for tiger.java to compile

    Commandline – make tiger.java


How to run11 l.jpg
How to run

  • Makefile – example

    all: Tiger Animal

    Tiger:

    javac Tiger.java

    Animal:

    javac Animal.java

    Commandline – make all

    “all” triggers both Tiger and Animal to compile


How to run12 l.jpg
How to run

  • ANT

    • Similar to make in that it stores in a project

    • Apache application

    • See handout


Java programming l.jpg
Java Programming

  • Import

    • “includes” a predefined java package that will be used in a program

    • Statements made outside of the code

    • Package must be contained in a directory given in the classpath

    • * denotes search entire directory

    • Example

      Import java.applet.Applet;

      Public class BinarySearch extends JApplet {

      …}


Java programming14 l.jpg
Java Programming

  • Important predefined java classes

    • Java.io.* - i/o files and streams

    • Java.awt.*,java.swing.* - GUI tools

    • Java.util.* - data structures

    • Java.applet.Applet – applets

    • Java.servlet.* - used for scripts, tomcat and other interactive servers

    • Java.sql.* - used for sql handling

    • Java.net.* - network apps


Java programming15 l.jpg
Java Programming

  • Package – used for user defined packages

    • Command used when wanting to include the class in a package

    • Used outside class declaration

    • Example

      package john.harney.example;

      Public class whatever {…}

      • Assuming the current directory is default, this statement will place the whatever.class in the default/john/harney/example directory

      • Commandline – javac –d . Whatever.java


Java programming16 l.jpg
Java Programming

  • General Format

    /*import and package statements here*/

    public/private/protected class classname{

    Member variables

    Constructors

    Methods (member functions)

    }

    • File must be saved as “classname.java”

    • Main (like c++) is executeable for an application (public static void main(args))

    • Class must be compiled in order to be used by another class


Java programming17 l.jpg
Java Programming

  • Executable example (Welcome3.java)

    public class Welcome3 {

    // main method begins execution of Java application

    public static void main( String args[] )

    {

    System.out.println( "Welcome\nto\nJava\nProgramming!" );

    } // end method main

    } // end class Welcome3


Slide18 l.jpg


Java programming19 l.jpg
Java Programming

  • Circle.java example (Java vs C++)

    • Member variables

      • Instead of:

        private:

        double radius;

      • There is:

        private double radius;


Java programming20 l.jpg
Java Programming

  • Circle.java example (Java vs C++)

    • Constructors

      • Instead of:

        Circle(int x,int y, double radiusValue);

      • There is:

        public circle(int x,int y, double radiusValue);

        Note: “public” denotes that this may be constructed outside of the class declaration


Java programming21 l.jpg
Java Programming

  • Circle.java example (Java vs C++)

    • Member functions (methods)

      • Instead of:

        double getRadius()

        {

        return radius;

        }

      • There is:

        public double getRadius()

        {

        return radius;

        }

        Note: “public” denotes that this may called outside of the class


Java programming22 l.jpg
Java Programming

  • Circle.java example

    //assume the compiler can find circle.class

    Import javax.swing.JOptionPane; //allows GUI input

    public class CircleImplement {

    // main method begins execution of Java application

    public static void main( String args[] )

    {

    Circle circ = new Circle(2,2,4.0); //constructor

    double rad = circ.getRadius();//calls to method getRadius

    JOptionPane.showMessageDialog(null,rad); //prints radius

    } // end method main

    } // end class Welcome3


Java programming23 l.jpg
Java Programming

  • Other notable differences between Java and C++

    • Strings are immutable

    • No global variables

    • Memory allocation is not needed (ie no pointers)

    • Garbage Collection

    • No operator overloading


Javadoc l.jpg
Javadoc

  • Javadoc – gives info about a source file

    • Commandline – javadoc class.java

    • Gives html documentation on the variables, methods, inheritence, other comments, etc.

    • Format – see handout


Slide25 l.jpg
JDOM

  • JDOM – java class that enables XML construction and parsing

    • Handout


Saxon l.jpg
Saxon

  • Saxon - http://saxon.sourceforge.net/saxon6.5.3/index.html

    • Supports XSLT,XPath,XQuery

    • Can be used with JDOM

    • Commandline

      java  classname sourcexml > destinationxml


ad