Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.

Similar presentations


Presentation on theme: "Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used."— Presentation transcript:

1 Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.  The only way to learn programming is to write many programs.

2 Intro to Java Programming  Java is an OOP language  An object has fields (attributes, properties) and methods (functions)  A class defines an object

3 Intro to Java Programming  Class example 1:  The point class public class Point { int x,y; public int getX(); public void setX(int x_val); ……

4 Intro to Java Programming  Class example 2:  The Person class public class Person { String name; int age; …… public int getName(); public int changeName( String new_name); protected void getAge(); ……

5 Intro to Java Programming  For OOP programming, the most important aspect is how to define and implement classes.  Almost all executable statements are in classes.

6 Intro to Java Programming  Eclipse: Integral Development Environment (IDE)  The name of the main class and the name of the saved file must be the same.  The main class is the class that contains the main method.

7 Intro to Java Programming  Every stand-alone program has to have a main method. Public static void main(…)  The entry point of the program

8 Intro to Java Programming  Errors:  Syntax errors: the compiler picks them up.  Run-time errors.  Logic errors.

9 Intro to Java Programming  Comments:  // comments to the end of line  /* block comments */

10 Intro to Java Programming  Special characters:  { … } Block  () Methods or expressions  [ … ] Array  “ … “ String  ; End of statement

11 Intro to Java Programming  Two types of programs:  Console (text) programs  Graphical programs

12 Intro to Java Programming  Two types of programs:  Console (text) programs  Graphical programs (event-driven)

13 Intro to Java Programming  Console programs:  Output:  System.out.print(…);  System.out.println(…);

14 Intro to Java Programming  Console programs:  Input: Import java.util.Scanner; Scanner inp = new Scanner(System.in); Use nextInt() to input an integer Use nextDouble to imput a double Use nextLine to input a line ……

15 Intro to Java Programming  Data types  int  double  String  boolean

16 Intro to Java Programming  Operators  Math: + - * / % pay attention to integer division  Relational: == != > >= < <=  Logical: && || ^

17 Intro to Java Programming  Program 1:  Read 3 floating numbers  Calculate their average  Display the results

18 Intro to Java Programming  Program 2:  Read the radius of a circle  Calculate the area of the circle  Display the result

19 Intro to Java Programming  Program 2:  Read the radius of a circle  Calculate the area of the circle  Display the result  Named constant pi

20 Intro to Java Programming  Program 3:  Read an integer between 10 and 99  Extract the left and right digits of the number  Display the result  Hint: use / and %

21 Intro to Java Programming  Program 4:  Read two integers between 10 and 99  Do multiplication  Display the result

22 Intro to Java Programming  Program 5:  Read total minutes  Convert the minutes into hours and minutes  Display the result


Download ppt "Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used."

Similar presentations


Ads by Google