1 / 22

Intro to Java Programming

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. Intro to Java Programming. Java is an OOP language

neo
Download Presentation

Intro to Java Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 { intx,y; public intgetX(); public void setX(intx_val); ……

  4. Intro to Java Programming • Class example 2: • The Person class public class Person { String name; int age; …… public intgetName(); public intchangeName( 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

More Related