+ All Categories
Home > Documents > Intro to Java Programming

Intro to Java Programming

Date post: 10-Feb-2016
Category:
Upload: neo
View: 52 times
Download: 0 times
Share this document with a friend
Description:
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 - PowerPoint PPT Presentation
22
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.
Transcript
Page 1: 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.

Page 2: Intro to Java Programming

Intro to Java Programming Java is an OOP language

An object has fields (attributes, properties) and methods (functions)

A class defines an object

Page 3: Intro to Java Programming

Intro to Java Programming Class example 1:

The point classpublic class Point {int x,y;public int getX();public void setX(int x_val);……

Page 4: Intro to Java Programming

Intro to Java Programming Class example 2:

The Person classpublic class Person {String name;int age;……public int getName();public int changeName( String new_name);protected void getAge();……

Page 5: Intro to Java Programming

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.

Page 6: Intro to Java Programming

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.

Page 7: Intro to Java Programming

Intro to Java Programming Every stand-alone program

has to have a main method.Public static void main(…)

The entry point of the program

Page 8: Intro to Java Programming

Intro to Java Programming Errors:

Syntax errors: the compiler picks them up.

Run-time errors. Logic errors.

Page 9: Intro to Java Programming

Intro to Java Programming Comments:

// comments to the end of line

/* block comments */

Page 10: Intro to Java Programming

Intro to Java Programming Special characters:

{ … } Block () Methods or expressions [ … ] Array “ … “ String ; End of statement

Page 11: Intro to Java Programming

Intro to Java Programming Two types of programs:

Console (text) programs Graphical programs

Page 12: Intro to Java Programming

Intro to Java Programming Two types of programs:

Console (text) programs Graphical programs (event-driven)

Page 13: Intro to Java Programming

Intro to Java Programming Console programs:

Output:System.out.print(…);System.out.println(…);

Page 14: Intro to Java Programming

Intro to Java Programming Console programs:

Input:Import java.util.Scanner;Scanner inp = new Scanner(System.in);Use nextInt() to input an integerUse nextDouble to imput a doubleUse nextLine to input a line……

Page 15: Intro to Java Programming

Intro to Java Programming Data types

int double String boolean

Page 16: Intro to Java Programming

Intro to Java Programming Operators

Math: + - * / %pay attention to integer division

Relational: == != > >= < <=

Logical: && || ^

Page 17: Intro to Java Programming

Intro to Java Programming Program 1:

Read 3 floating numbers Calculate their average Display the results

Page 18: Intro to Java Programming

Intro to Java Programming Program 2:

Read the radius of a circle Calculate the area of the circle

Display the result

Page 19: Intro to Java Programming

Intro to Java Programming Program 2:

Read the radius of a circle Calculate the area of the circle

Display the result Named constant pi

Page 20: Intro to Java Programming

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 %

Page 21: Intro to Java Programming

Intro to Java Programming Program 4:

Read two integers between 10 and 99

Do multiplication Display the result

Page 22: Intro to Java Programming

Intro to Java Programming Program 5:

Read total minutes Convert the minutes into hours and minutes

Display the result


Recommended