Download Dr Java has a definitions pane

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Abstraction (computer science) wikipedia , lookup

Comment (computer programming) wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Go (programming language) wikipedia , lookup

Compiler wikipedia , lookup

Class (computer programming) wikipedia , lookup

Structured programming wikipedia , lookup

Sieve of Eratosthenes wikipedia , lookup

Program optimization wikipedia , lookup

Library (computing) wikipedia , lookup

Java syntax wikipedia , lookup

C++ wikipedia , lookup

Object-oriented programming wikipedia , lookup

C Sharp syntax wikipedia , lookup

One-pass compiler wikipedia , lookup

Interpreter (computing) wikipedia , lookup

Scala (programming language) wikipedia , lookup

Name mangling wikipedia , lookup

Java (programming language) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Java performance wikipedia , lookup

Transcript
CS2200 Software Development
Lecture 2: Java Program Development
Lecturer: Adrian O’Riordan
Course Webpage:
http://www.cs.ucc.ie/~adrian/cs2200.html
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
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 alKhowarizmi who flourished at the end of the 8th Century A.D. (picture of alKhowarizmi from Russian stamp)
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.
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
/**
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
A program can consist of one or more .java files. Normally one class
per file
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)
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).
Compilation/Interpretation
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
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)
Eclipse IDE
Dr Java
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.
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
Java APIs
http://java.sun.com/j2se/1.5.0/docs/api/
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;