Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.

Slides:



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

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
CMT Programming Software Applications
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Datalogi A 1: 8/9. Book: Cay Horstmann: Big Java or Java Consepts.
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;
Java Overview CS2336: Computer Science II1. First Program public class HelloWorld { public static void main(String args[]) { System.out.println("Hello.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Computer Programming Lab(4).
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Hello World 2 What does all that mean?.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Java Fundamentals Asserting Java Chapter 2: Introduction to Computer Science ©Rick Mercer.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
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.
Chapter 2 Elementary Programming
Chapter 2: Java Fundamentals
C++ Programming: Basic Elements of C++.
Making Decisions Chapter 5.  Thus far we have created classes and performed basic mathematical operations  Consider our ComputeArea.java program to.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Khalid Rasheed Shaikh Computer Programming Theory 1.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,
Java FilesOops - Mistake Java lingoSyntax
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
CONTROL STRUCTURE Chapter 3. CONTROL STRUCTURES ONE-WAY SELECTION Syntax: if (expression) statement Expression referred to as decision maker. Statement.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Primitive Data Types int is a primitive data type A primitive data type is one that stores only a single piece of data. TypeStorageDescription int 4 bytes+ve.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Variables and Constants Chapter 4 Review. Declaring Variables A variable is a name for a value stored in memory. Variables and constants are used in programs.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
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.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to programming in java
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.
CompSci 230 S Programming Techniques
Topic 2 Elementary Programming
Chapter 4 Assignment Statement
Elementary Programming
Chapter 3 Assignment Statement
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2.
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Introduction to Classes and Methods
Chapter 2: Basic Elements of Java
Fundamentals 2.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Chapter 2: Java Fundamentals
CS2011 Introduction to Programming I Elementary Programming
The keyboard is the standard input device.
Unit 3: Variables in Java
Presentation transcript:

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  An object has fields (attributes, properties) and methods (functions)  A class defines an object

Intro to Java Programming  Class example 1:  The point class public class Point { int x,y; public int getX(); public void setX(int x_val); ……

Intro to Java Programming  Class example 2:  The Person class public class Person { String name; int age; …… public int getName(); public int changeName( String new_name); protected void getAge(); ……

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.

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.

Intro to Java Programming  Every stand-alone program has to have a main method. Public static void main(…)  The entry point of the program

Intro to Java Programming  Errors:  Syntax errors: the compiler picks them up.  Run-time errors.  Logic errors.

Intro to Java Programming  Comments:  // comments to the end of line  /* block comments */

Intro to Java Programming  Special characters:  { … } Block  () Methods or expressions  [ … ] Array  “ … “ String  ; End of statement

Intro to Java Programming  Two types of programs:  Console (text) programs  Graphical programs

Intro to Java Programming  Two types of programs:  Console (text) programs  Graphical programs (event-driven)

Intro to Java Programming  Console programs:  Output:  System.out.print(…);  System.out.println(…);

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

Intro to Java Programming  Data types  int  double  String  boolean

Intro to Java Programming  Operators  Math: + - * / % pay attention to integer division  Relational: == != > >= < <=  Logical: && || ^

Intro to Java Programming  Program 1:  Read 3 floating numbers  Calculate their average  Display the results

Intro to Java Programming  Program 2:  Read the radius of a circle  Calculate the area of the circle  Display the result

Intro to Java Programming  Program 2:  Read the radius of a circle  Calculate the area of the circle  Display the result  Named constant pi

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 %

Intro to Java Programming  Program 4:  Read two integers between 10 and 99  Do multiplication  Display the result

Intro to Java Programming  Program 5:  Read total minutes  Convert the minutes into hours and minutes  Display the result