Download presentation
Presentation is loading. Please wait.
Published byArthur Haynes Modified over 9 years ago
1
JAVA BASICS
2
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! WE NEED TO LEARN IT ANYWAY!
3
How to run JDK – Java Development Kit –Basic compiler, linker, and libraries IDE – Integrated Development Environment –NetBeans – netbeans.org
4
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/bas ics/index.html http://java.sun.com/docs/books/tutorial/jar/bas ics/index.html http://java.sun.com/docs/books/tutorial/jar/bas ics/index.html –Packages – groups of related classes in a directory
5
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
6
How to run Environment Variables –Path – searches computer for executeable –Classpath – searches computer for classes that need to be used
7
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
8
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
9
How to run Makefile – example default: javac Animal.java note: there is a tabspace in front of javac note: there is a tabspace in front of javac Commandline – make - This compiles the file called Animal.java
10
How to run Makefile – example Tiger.java: Tiger.java Animal.class javac Tiger.java Animal.class must exist for tiger.java to compile Animal.class must exist for tiger.java to compile Commandline – make tiger.java
11
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
12
How to run ANT –Similar to make in that it stores in a project –Apache application –See handout
13
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 { …}
14
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
15
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
16
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
17
Java Programming Executable example (Welcome3.java) public class Welcome3 { // main method begins execution of Java application // main method begins execution of Java application public static void main( String args[] ) public static void main( String args[] ) { System.out.println( "Welcome\nto\nJava\nProgramming!" ); System.out.println( "Welcome\nto\nJava\nProgramming!" ); } // end method main } // end method main } // end class Welcome3
18
Circle.java example (Java vs C++) –Class Header Instead of: class Circle : public Point There is: public class Circle extends Point;
19
Java Programming Circle.java example (Java vs C++) –Member variables Instead of: private: double radius; There is: private double radius;
20
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
21
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
22
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 // main method begins execution of Java application public static void main( String args[] ) public static void main( String args[] ) { Circle circ = new Circle(2,2,4.0); //constructor Circle circ = new Circle(2,2,4.0); //constructor double rad = circ.getRadius();//calls to method getRadius double rad = circ.getRadius();//calls to method getRadius JOptionPane.showMessageDialog(null,rad); //prints radius JOptionPane.showMessageDialog(null,rad); //prints radius } // end method main } // end method main } // end class Welcome3
23
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
24
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
25
JDOM JDOM – java class that enables XML construction and parsing –Handout
26
Saxon Saxon - http://saxon.sourceforge.net/saxon6.5.3/in dex.html –Supports XSLT,XPath,XQuery –Can be used with JDOM –Commandline java classname sourcexml > destinationxml
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.