JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995....

12
JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made up of one or more classes A class contains one or more methods A method contains program statements

Transcript of JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995....

Page 1: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

JAVA

JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995.

In the Java programming language:A program is made up of one or more classesA class contains one or more methodsA method contains program statements

Page 2: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

JAVA

Class with a method: class name

public class MyClass //class header{

private int myInt = 5; //instance variable

public double myMethod(int intParam) //method header

{// do stuff here

}

}

Page 3: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

Class with a method:

public class myClass variable name initial value { type

private int myInt = 5; //instance variable

public double myMethod(int intParam){

// do stuff here}

}

JAVA

Page 4: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

Class with a method:

public class myClass{

private int myInt = 5; //instance variable

return type name parameter type

public double myMethod(int intParam){

// do stuff here parameter name

return myVar; //return statement}

}

JAVA

Page 5: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

JAVA

Java comments: Used to explain code. Ignored by the compiler

//single line comment.

/* multipleline comment*/

/**This is a javadoc comment*/

Page 6: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

JAVA

The words used to program in Java (or any other language) are called identifiers. Java identifiers can be made of letters digits or the underscore character. They can not start with a number:

You should use JAVA conventions in naming your identifiers:Class names begin with a capital letter: MyClassVariable names begin with a lower case letter: myIntegerMethods begin with a lower case letter: myMethodConstants are all caps: MAXIMUM

Page 7: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

JAVA

Many languages compile to run on a specific machine. The Java compiles the code to Java bytecode. A java interpreter installed on the machine running the program converts the Java bytecode to the machines native code. This lets a program written in Java run on multiple platforms. For instance a program compiled on a Linux machine can be run on a Microsoft machine. Java is considered to be architecture-neutral.

Java sourcecode

Machinecode

Javabytecode

Javainterpreter

Javacompiler

Page 8: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

(x, y)

JAVA

Graphics in Java:

Horizontal (x) coordinates are measured from right.Vertical (y) coordinates are measured from top.

We are used to measuring vertical coordinates from the x-axis, so this can take some getting used to:

(x, y)

Page 9: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

JAVA

Hello World!

Public class Test{

public static void main(String[] args) {

System.out.println(“Hello World!”);}

}

Page 10: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

JAVA

Page 52: Programming Project 1.1 – 1.2

Page 48:1.13 – 1.17 self reviewPage 50: MC 1.6 – 1.8Page 51: Short Answer 1.7 – 1.9

Page 11: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

JAVA

1.13 What is the difference between a high level language and a machine Language?

1.14 What is JAVA bytecode?

1.15 What is whitespace. Does it change program execution.

1.16 Which of the following are not valid JAVA identifiers?a)RESULT b) result c) 12345 d) x12345y e) black&white

f)answer_7

Page 51 1.8Why might the following valid JAVA identifiers not be good ones?a)q b) totVal c. theNextValueInTheList

Page 12: JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made.

Identify the following errors as compile-time, runtime, or logical:a)Multiplying two numbers when you meant to add themb)Dividing by zeroc)Forgetting a semi-colon at the end of a statementd)Spelling a word wrong in the output.e)Producing inaccurate resultsf)Typing “{“ when you should have typed “(“