|
|
COMPUTER ENGINEERING LABORATORY[This page is CSS2 enabled. Your browser might not fully support it] [http://www.ee.oulu.fi/research/ tklab/ courses/521260S/] First steps using Java$RCSfile: index.html,v $ $Revision: 1.1 $ $Date: 2010/9/6 17:19:00 $ IndexIntroductionRepresenting Structured Information course gives an overview of XML and related technologies such as XML Schema, RDF, XSLT, XPath... One of the most important tasks that an application using XML should implement is parsing. Parsing is the process of analyzing an XML file in order to determine its grammatical structure in respect to a given grammar. Actually when parsing what you do is pass the elements and attributes that an XML document contains to an application. This application could later process this received data. So, parsing is one of the most important tasks that you must do when are working with XML documents. That is the main reason why the vast majority of programming languages have built-in support for XML parsing. Implementing a parser from scratch is not a trivial task. Unless you have very special requirements, it is better to use the facilities different programming language offer to implement the parsers. Java is currently one of the most widely used programming languages in the world. It is extensively used in network and distributed applications, especially because the applications created in Java run on any platform that has a Java virtual machine available to it. These kind of applications are using more and more often XML technologies. Furthermore, Java offers a great support for implementing XML parsers and actually there are a great amount of them currently available. That is why it is very useful know how to implement XML parsers with Java. During Representing Structure Course students must complete 4 exercises. During the 3rd and 4th exercise students must implement some Java program. The goal of this webpage is to give a quick introduction for those who have never programmed in Java before. The idea is to offer some links where students can try to learn Java by themselves. In the end of the document it is explained briefly what each exercise is about and what are the basic Java skills that student should know to solve each one. It will help people that have already worked with Java to determine which concepts they should review. Java first stepsInstallation of JDKThe best way to learn a programming language is doing actual programming. If you want to create your own programs in Java you should first download JDK (Java development kit) from Sun Webpage. There are many architectures and extensions. You should choose one depending on the software you want to develop. For our purposes we are going to use JavaSE (Java Standard Edition). The latest stable version of JavaSE at the moment of writing is Java 6 Update 21.
Hello WorldWhen you are learning a new programming language one of the first thing you usually do is to program a so-called Hello World. Hello World is a program that shows on the screen the sentence Hello World. It makes you to get familiar with the programming environment. Before starting to program you should know a few things. A short comment about files extensions. In java the code you are writing is saved in a raw text file with extension .java. The compiler generates the binary in a file with .class extension. Several .class files (and other configuration files) can be compressed in a .jar file. .jar are the Java extensions for the libraries. The Folder /bin in Java path contains all the executables files you are going to need in java. Two of them are the ones you are going to use more often:
Now is time to implement the Hello World.
Object Oriented ProgrammingJava is an Object Oriented Programming Language. Those who have programmed in C++, Pascal or ADA are familiar with this concept. But students who only have worked with C, maybe aren't. There is a big difference between programming using objects and using a procedural language (like C). To understand Java programming first you should know the basis of Object Oriented Programming. The main idea of Object Oriented Programming is that everything is focused on objects instead of actions. These objects has some attributes, can do some actions (methods) and can interact with other objects. You can find a short description of what object programming is in this link: http://searchwinit.techtarget.com/sDefinition/0,,sid1_gci212681,00.html You can read the main concepts you need to understand about object oriented programming to program in Java in the lessons located at http://download.oracle.com/javase/tutorial/java/concepts/ Basic SyntaxBefore starting programming you should learn the basic Java syntax. In general the syntax is very similar to C++. One of the biggest difference between C++ and Java is that Java doesn't support pointers. If you are familiar with any other programming language, learning Java syntax is not going to be difficult. The only thing you should remember is that everything is encapsulated in objects. More information about Java syntax in this webpage: http://download.oracle.com/javase/tutorial/java/nutsandbolts/index.html. At this stage you should learn also something about classes and objects (how to create classes, how to implement methods and variables in that class, how to instatiate objects and so on). You can find some information about that in the previous links. There is a page that can be very useful when you start programming Java to remember the syntax. It is a kind of syntax cheat sheet. You can find it at: http://mindprod.com/jgloss/jcheat.html. The official Java Tutorials are a good place to start looking for information on how to implement specific things in Java. You can also find some code examples from this tutorial. You can also search for code using Google Code Search using in the search lang:java. Start practising using BlueJA joint research group at Deakin University, Melbourne, Australia, and the University of Kent in Canterbury, UK created a few years ago a platform to teach and learn Java. This platform is named BlueJ. BlueJ is a framework that allows students to create, edit, compile and debug Java Code with the advantages that have a very simple Graphical User Interface, is object oriented (you can interact with the objects individually) and allows graphical visualization of class and objects. It is a free software that you can download from http://www.bluej.org/download/download.html. A tutorial to learn how to use it in different languages can be downloaded from this webpage: http://www.bluej.org/doc/tutorial.html. With this tool you will see more graphically the object oriented idea. You can instantiate objects from one class, execute different methods from them and see the results. All that with the help of graphic figures and popup windows that tell you what you can use at any moment. More, and more and moreWhen you have learned the basis of the syntax you can practise by yourself some other important concepts of Java. For example Inheritance and polymorphism, Interfaces, Exceptions and creating and using packages. If you have still some difficulties, you can consult this book online where you can find also some examples and exercises. To practise some of these concepts you can do using BlueJ exercises from BlueJ00 to BlueJ7 from this webpage. You can find also exercises in this webpage http://www.javapassion.com/javaintro1/Class.html (I specially recommend exercises from Class 4, 5 and 6). When you have "under control" Java syntax and basic concepts you only need to know different classes already implemented, that is the API(Application Program Interface). You can find J2SE 6 Java API in http://download.oracle.com/javase/6/docs/api/ Using IDEsProgramming in the notepad or using command line is a quite hard task. Currently there are a lot of programs that assist you in the creation of Java programs. Some of them are very general frameworks that allow you to use different programming languages such as JGrasp or Vim. These programs usually offer you the possibility of changing the colors of different elements, making indentations and correct simple syntax errors (such as missing parenthesis). There are much more complex programs that offer much more possibilities but are focusing on a single programming language. The IDEs (Integrated development environment) not only offer all characteristics from previous editors but also help you in application development giving you for example autocompletion possibilities and APIs. With an IDE you can also manage complex projects that contain a lot of files. There are two IDEs installed in the laboratory NetBeans and Eclipse. Eclipse is an open source and free IDE programmed in Java. Apart from the basic functionality, you can install different plugins which offer extra functionalities. In course assistants' opinion, although in the beginning could seem a little bit complex, Eclipse is one of the best IDEs available. More links |