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

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
8-May-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 Chapter 3 Arithmetic Expressions. 2 Chapter 3 Topics l Overview of Java Data Types l Numeric Data Types l Declarations for Numeric Expressions l Simple.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Review… Yong Choi BPA CSUB. Access Modifier public class HelloWorldApp –More detailes of Java key (reserved) wordJava key (reserved) word –The keyword,
Java Syntax Primitive data types Operators Control statements.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Review Java.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Fundamental concepts in Java. Lesson plan Variable declaration, assign statement & practice Design document & practice.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Java Structure import java_packages; class JavaClass { member variables declarations; void otherMethod( ) { } public static void main(String[]
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
1 Operations Making Things Happen (Chap. 3) Expressions.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Basic Java Syntax COMP 401, Spring 2014 Lecture 2 1/14/2014.
Apr, 2011 Dating with Java Larry Li. Objective Hello world program Setup development environment Data types and variables Operators and Expressions Control.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Methods: A Deeper Look. Template for Class Definition public class { } A.Import Statement B.Class Comments C.Class Name D.Data members E.Methods (inc.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Selection statements Repetition statements. Lesson plan Main concepts Practice session –If- then –Switch –Nested if.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CompSci 100E JB1.1 Java Basics (ala Goodrich & Tamassia)  Everything is in a class  A minimal program: public class Hello { public static void main(String[]
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 4 : Defining Your Own Classes Part 1 - Objectives After you have read and studied this chapter, you should be able to Define a class with multiple.
Information and Computer Sciences University of Hawaii, Manoa
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 3: Understanding C# Language Fundamentals
Starting JavaProgramming
Chapter 8 JavaScript: Control Statements, Part 2
An Introduction to Java – Part I, language basics
Recap Week 2 and 3.
Expressions and Assignment
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Chap 2. Identifiers, Keywords, and Types
Additional control structures
Review of Java Fundamentals
Presentation transcript:

Java development environment and Review of Java

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

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

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

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.

Setting up preferences in Eclipse

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”.

Create an Eclipse project

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

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

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

Implementation of Java class

Generating setters and getters for attributes

Implementation of Java class Generating constructors

Implementation of Java class Generating constructors

Compile Java Application

Run the application

Run Application (Shorter way)

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

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

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

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

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

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.

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

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 = ;

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

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

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

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

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

Relational Operators

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

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

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.

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.

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--;

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

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

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

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

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