Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.

Similar presentations


Presentation on theme: "Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this."— Presentation transcript:

1 Java development environment and Review of Java

2 Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this as the default and do not ask again” box.

3 The importance of workspace This is where you will find all your java files. You can switch from one workspace to another. You need to define the workspace first (where you want to put your files) before click on OK

4 Eclipse TM tutorial Perspective is a set of related Views (windows) that enable a development specialist to perform specific tasks

5 Setting up preferences in Eclipse If you did not download the JDK earlier in this tutorial, and your existing JRE does not appear in the “Installed JREs” preference, you must add it yourself.

6 Setting up preferences in Eclipse

7

8 Create an Eclipse project From the Eclipse menu bar select File, New, Project to start the “New Project” wizard. Select “Java Project” and click “Next”.

9 Create an Eclipse project

10 Create a Java package Structure in dot format: for example: com.tm.tutorial.main

11 Create Java classes Create Application class under com.tm.tutorial.main package

12 Create Java classes Create Application class under com.tm.tutorial.main package

13 Implementation of Java class

14 Generating setters and getters for attributes

15 Implementation of Java class Generating constructors

16 Implementation of Java class Generating constructors

17 Compile Java Application

18

19 Run the application

20

21

22

23 Run Application (Shorter way)

24 Review of Java fundamentals Template for Class Definition class { } Import Statements Class Comment Class Name Data Members Methods (incl. Constructor) Methods (incl. Constructor)

25 Review of Java fundamentals Template for Class Definition class { } Import Statements Class Comment Class Name Data Members Methods (incl. Constructor) Methods (incl. Constructor)

26 Numeric data Variable declaration: ; If more than one variable has the same data type:,..;

27 Six numerical data types byte: -128 to 127 short:-32768 to 32767 (-2 15 to 2 15 -1) int: -2 31 to 2 31 -1 long: -2 63 to 2 63 -1 float: -3.4E+38 to 3.4E+38 double:-1.797E+308 to 1.797E+308

28 Assignment statement = ; Example: x =2*5+6-1;

29 Variable names It must be a legal identifier which is an unlimited series of characters that begins with a letter. It must not be a keyword, a boolean literal (true or false), or the reserved word null. It must be unique within its scope.

30 Variable name (cont.) Legal identifier:be composed of letters, numbers, _ and $. Identifiers may only begin with a letter, _, or $. Keyword: http://java.sun.com/docs/books/tutorial/java/nutsand bolts/_keywords.html Variable names begin with a lowercase letter Class names begin with an uppercase letter

31 Constant and variables Constant:  Value it contains doesn’t change final int MONTHS_IN_YEAR = 12; Variables:  Value it contains may vary double loanAmount; loanAmount =0; loanAmount = 1000.99;

32 Integer division and type casting Integer division:  Integer/integer = integer, 7/2 = 3  Integer/double = double, 7/2.0 = 3.5  Double/integer = double, 7.0/2 = 3.5 Type casting: a process that converts a value of one data type to another data type. Implicit casting Explicit casting

33 Type casting (cont.) Implicit casting:  Operand is converted from a lower to a higher precision  Higher precision: a data type with a larger range of values Double has a higher precision than float Int has a higher precision than short  Operand: can be a constant, variable, method call or another arithmetic expression

34 Type casting (cont.) Explicit casting  ( )  Example: float result; result = (float) ((3+5)/6); and result = ((float) (5+3))/6;

35 if ( ) ; else ; Simple Choice Statement if ( ) single statement; else single statement;

36 Boolean expression Boolean expression: is a conditional expression that is evaluated to either true or false. Conditional expression: is a three part expression: Boolean expressions can be combined by boolean operators

37 Relational Operators

38 Boolean operators && meansAND ||means OR ! means NOT

39 The While Loop while( ){ // Repeat multiple statements. statement 1 statement 2 statement 3... }

40 The Do Loop do{ // Repeat multiple statements. statement 1 statement 2 statement 3... } while(<boolean expression); Note that the statements in the body of the loop are always executed at least one. Note the final semicolon, which is required.

41 The For-Loop Outline // Repeat multiple statements. for(initialization; condition; post-body update){ // Statements to be repeated. statement 1 statement 2 statement 3... } Commonly used with increment and decrement operators.

42 Increment and Decrement Used as a shorthand for add-one-to and subtract-one-from: value = value+1; value += 1; value++; Prefix and postfix forms: ++value; --value; value--;

43 Attributes (Data Member) Declaration ; private String ownerName ; Modifiers Data Type Name Note: There’s only one modifier in this example.

44 Method Declaration ( ){ } public void setOwnerName ( String name ) { ownerName = name; } Statements Modifier Return Type Method Name Parameter

45 Constructor A constructor is a special method that is executed when a new instance of the class is created. public ( ){ } public Bicycle ( ) { ownerName = “ Unassigned ” ; } Statements Modifier Class Name Parameter

46 Arguments and Parameters An argument is a value we pass to a method. A parameter is a placeholder in the called method to hold the value of the passed argument. class Account {... public void add(double amt) { balance = balance + amt; }... } class Sample { public static void main(String[] arg) { Account acct = new Account();... acct.add(400);... }... } argument

47 Arguments and Parameters An argument is a value we pass to a method. A parameter is a placeholder in the called method to hold the value of the passed argument. class Account {... public void add(double amt) { balance = balance + amt; }... } class Sample { public static void main(String[] arg) { Account acct = new Account();... acct.add(400);... }... } parameter


Download ppt "Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this."

Similar presentations


Ads by Google