Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in 1995. In the Java programming language: A program is made."— Presentation transcript:

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 up of one or more classes A class contains one or more methods A method contains program statements

2 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 }

3 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

4 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

5 Java comments: Used to explain code. Ignored by the compiler //single line comment. /* multiple line comment */ /**This is a javadoc comment*/

6 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: MyClass Variable names begin with a lower case letter: myInteger Methods begin with a lower case letter: myMethod Constants are all caps: MAXIMUM

7 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 source code Machine code Java bytecode Java interpreter Java compiler

8 (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)

9 JAVA Hello World! Public class Test { public static void main(String[] args) { System.out.println(“Hello World!”); }

10 JAVA Page 52: Programming Project 1.1 – 1.2 Page 48:1.13 – 1.17 self review Page 50: MC 1.6 – 1.8 Page 51: Short Answer 1.7 – 1.9

11 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.8 Why might the following valid JAVA identifiers not be good ones? a)q b) totVal c. theNextValueInTheList

12 Identify the following errors as compile-time, runtime, or logical: a)Multiplying two numbers when you meant to add them b)Dividing by zero c)Forgetting a semi-colon at the end of a statement d)Spelling a word wrong in the output. e)Producing inaccurate results f)Typing “{“ when you should have typed “(“


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

Similar presentations


Ads by Google