java basics
Download
Skip this Video
Download Presentation
JAVA BASICS

Loading in 2 Seconds...

play fullscreen
1 / 26

JAVA BASICS - PowerPoint PPT Presentation


  • 331 Views
  • Uploaded 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
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
How to run
  • JDK – Java Development Kit
    • Basic compiler, linker, and libraries
  • IDE – Integrated Development Environment
    • NetBeans – netbeans.org
how to run4
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
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
How to run
  • Environment Variables
    • Path – searches computer for executeable
    • Classpath – searches computer for classes that need to be used
how to run7
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
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
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
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
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
How to run
  • ANT
    • Similar to make in that it stores in a project
    • Apache application
    • See handout
java programming
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
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
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
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
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
Circle.java example (Java vs C++)
    • Class Header
      • Instead of:

class Circle : public Point

      • There is:

public class Circle extends Point;

java programming19
Java Programming
  • Circle.java example (Java vs C++)
    • Member variables
      • Instead of:

private:

double radius;

      • There is:

private double radius;

java programming20
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
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
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
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
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
JDOM
  • JDOM – java class that enables XML construction and parsing
    • Handout
saxon
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