ECE 122 Feb. 1, 2005. Introduction to Eclipse Java Statements Declaration Assignment Method calls.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

IT151: Introduction to Programming
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Your First Java Program: HelloWorld.java
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter2: Introduction to Java Applications 1.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
CMT Programming Software Applications
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
CS 106 Introduction to Computer Science I 09 / 11 / 2006 Instructor: Michael Eckmann.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
 2005 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
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?
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
3 Major Steps for Creating/Running a Java Program You write the source code for the program and save it as a.java file. You compile the.java program using.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 2: Java Fundamentals
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
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.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Welcome to AP Computer Science A We use the Java language, but this class is much more rigorous than Intro to Java More programming, but also more theory.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
The eclipse IDE IDE = “Integrated Development Environment”
Console Output, Variables, Literals, and Introduction to Type
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2: Basic Elements of Java
Chapter 3 Classes and Objects
Java Tutotrial for [NLP-AI] 2
Anatomy of a Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Unit 3: Variables in Java
Instructor: Alexander Stoytchev
© A+ Computer Science - Basic Java © A+ Computer Science -
Presentation transcript:

ECE 122 Feb. 1, 2005

Introduction to Eclipse

Java Statements Declaration Assignment Method calls

Declaration A variable is like a container that can hold certain content/value. Variable declaration consists of type and name Variable name, by convention, begin with a lowercase letter, and every word after first word begins with a capital letter, e.g. firstName, accountNumber, courseName. The type shows what content the “container” can hold. The variable name will be used in other statements when such content is desired. int age; float weight; String name;

Assignment Assignment is to put content into a container. Assignment syntax is variable = value; age = 18; weight = 60.5; name = “Alex”;

Method Call A method is a unit of work always done together. Call the method when you want to do such a unit of work. float total = sum(s1, s2, s3); getAccount(accountID); joe.buildHouse(location);

Comments End of line (single line) comment starts with // //This is a comment line. Multiple line comments are enclosed by /* and */ /* This is multiple line comments */

Each statement ends in semicolon Declaration. int age; Assignment. age = 1; Method call. total = Sum(s1, s2, s3);

Demo StatementExample.java public class StatementExample { public static void main(String[] args) { int age; float weight; age = 5; //My dog is five years old. System.out.println("My dog is " + age + " years old."); weight = 10; //My dog weights 10 pounds. System.out.println("My dog weights " + weight + " pounds."); }

You can do in Java Split a statement in multiple lines to enhance readability, e.g. System.out.println (lastName + firstName + streetAddress + town + state + zip);

Good Programming Practice Write a comment before each class, documenting the purpose of the class. Write end of line (single line) comment, documenting the purpose of the statement. Use Eclipse to check your syntax error. Declare each variable in each line, allowing end of line comment. E.g. int age; //The age of my dog Choose meaningful variable names helps a program to be self-documenting. Easy to understand.

Which code is easier to understand? Code Sample 1: float examOneGrade = 90.0; float examTwoGrade = 95.0; float examThreeGrade = 85.0; float myAverageExamGrade = (examOneGrade + examTwoGrade + examThreeGrade)/3; Code sample 2 float asdfghjk = 90.0; float rujflwe = 95.0; float asdfkj = 85.0; float dfiefjek = (asdfghjk + rujflwe + asdfkj)/3;

Console Output System.out.println(“Hello World!”); Display a single line of text with multiple statements. System.out.print(“Welcome to “); System.out.println(“ECE122!”); Display multiple line of text with a single statement System.out.println(“Welcome\n to\nECE122!”);

Demo ConsoleOutput.java

Common Escape sequence \nNewline. Position the screen cursor at the beginning of the next line. \tHorizontal tab. \\Backslash. Print a backslash character. \”Double quote. Print a double quote character.

Demo ConsoleOutput.java

Console Input Demo Import package we will use. Let compiler and run time know where to find the class to load. Read from console is more “risky” than output. Things can go wrong. We want to prepare for it. Use “Exception Handling”. We will “try” to read from console. If something goes wrong, the system will throw something called “Exception”. We will then “catch” it and proceed. try { …//read from console } catch(Exception e) { …//do something to repair it }

Demo ConsoleInput.java

Assignment Read “Head First Java” Chapter 1 Read “Java 2, a beginner’s guide” Chapter 1 Install JDK on your home computer. Install Eclipse on your home computer. Create a new java project within Eclipse workspace. Compile “HelloWorld.java”, run “HelloWorld”