Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2200 Software Development Lecture 2: Java Program Development Lecturer: Adrian O’Riordan Course Webpage:

Similar presentations


Presentation on theme: "CS2200 Software Development Lecture 2: Java Program Development Lecturer: Adrian O’Riordan Course Webpage:"— Presentation transcript:

1 CS2200 Software Development Lecture 2: Java Program Development Lecturer: Adrian O’Riordan Course Webpage: http://www.cs.ucc.ie/~adrian/cs2200.html http://www.cs.ucc.ie/~adrian/cs2200.html

2 How do you develop software? Start with concept use a development process, e.g. design-code-test produce a good design † –procedural abstraction and data abstraction –high cohesion, low coupling produce readable code - self-documenting code using consistent coding conventions † Covered in separate lecture

3 Algorithm A formula or set of steps for solving a particular problem. In programming terms a set of instructions for solving a particular task. –Programming examples include sorting a list of names or searching for a record in a file. –Mathematics has many such procedures that are implemented as an algorithm: e.g. identify all prime numbers up to a given number (Sieve of Eratosthenes) The word algorithm in English comes from the Arab mathematician al- Khowarizmi who flourished at the end of the 8th Century A.D. (picture of al- Khowarizmi from Russian stamp)

4 Example Algorithm: Sieve of Eratosthenes 1.Write down the numbers 1, 2, 3,..., n. We will eliminate composites by marking them. Initially all numbers are unmarked. 2.Mark the number 1 as special (it is neither prime nor composite). a)Find the first number in the list greater than k that has not been identified as composite. (The very first number so found is 2.) Call it m. Mark the numbers 2m, 3m, 4m,... as Set k=1. Until k exceeds or equals the square root of n do this: b)composite. c)m is a prime number. Put it on your list. 3.Set k=m and repeat. 4.The list gives all the primes less than n.

5 Program Development Basics The basics of Java programming consist of specifying an algorithm and implementing this by writing Java program code. The program or source code is a set of instructions. E.g. HelloWorldApp.java A program can consist of one or more.java files. Normally one class per file /** * simply prints "Hello World!" to standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string. }

6 Example coding guidelines : Good use of variables Give sensible names to identifiers Use consistent style, e.g. carSpeed or car_speed Use each variable that you declare Initialise each variable properly Use each variable for one purpose only Minimise scope of identifiers Minimise duration of identifiers Minimise visibility of identifiers Use named constants (using final)

7 Java Programming Environment.java files compiled into a.class files, called bytecode. This is run on a JVM (Java Virtual Machine) such as Sun’s Hotspot. The bytecode is a standardized portable binary format. Multiple.class files can be packaged together into a.jar (Java archive). The JVM runtime executes.class or.jar files by emulating the JVM by interpreting it, or using a just-in-time compiler (JIT).

8 Compilation/Interpretation

9 Example: Using JDK Write your Java code in files – usually one class per file. Compile the code with javac. Fix the compile errors and recompile. When there are no more compile errors run the program wit the java command. Example: –Create a class Customer. Save in a file called Customer.java –Compile like so: prompt>javac Customer.java –And run like so: prompt>java Customer

10 Java IDEs IDEs (Integrated Development Environments) can widely available to speed up the process and provide increased support such as source code control, class browser, build-automation tools, and a debugger. Popular Professional Java IDEs include: NetBeans (Sun) Eclipse (Eclipse Foundation) JBuilder (CodeGear) JDeveloper (Oracle) Teaching and Learning (Interactive) IDEs BlueJ (bluej.org) Dr Java (drjava.org)

11 Eclipse IDE

12 Dr Java

13 Dr Java IDE DrJava (drjava.org) is a lightweight programming environment for Java designed specifically for beginners. DrJava supports the use of different Java compilers, such as the traditional javac compiler supplied with the JDK (versions 6, 5 or earlier). Dr Java has an interactions pane, where you can input Java expressions and statements and immediately see their results; Dr Java has a definitions pane, where you can enter and edit class definitions with support for brace matching, syntax highlighting, and automatic indenting.

14 Dr Java Features Features include: –Text editing with syntax highlighting, brace matching, line numbers,find and replace –Buttons for compiling and running –Interactive interpreter - an extension of free DynamicJava –Integrated javadoc –Integrated debugger –Integrated JUnit –Project facility –Language level facility

15 Java APIs http://java.sun.com/j2se/1.5.0/docs/api/

16 Java Debugging A special program called a debugger can used to find errors (bugs). A debugger allows a programmer to stop a program at any point and examine and change the values of variables. An error or defect in software that causes a program to malfunction. A compiler error indicates something that must be fixed before the code can be compiled. Run-time errors only occur when you run a program, i.e. executable crashes. example: trying to divide by zero int scores = 500, num = 0, avg; avg = scores / num;


Download ppt "CS2200 Software Development Lecture 2: Java Program Development Lecturer: Adrian O’Riordan Course Webpage:"

Similar presentations


Ads by Google