MSIS 655 Advanced Business Applications Programming

Slides:



Advertisements
Similar presentations
IT151: Introduction to Programming
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
Chapter 2 - Introduction to Java Applications
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
Introduction to Computers and Programming Lecture 3: Variables and Input Professor: Evan Korth New York University.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 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.
Chapter 2 - Introduction to Java Applications
Introduction to C Programming
Java Applications & Program Design
 2005 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 2005 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A First Program in Java: Printing.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
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
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
9/6: Variable Types, Arithmetic Operators, Comparison Operators Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A First Program in Java: Printing a Line of Text 2.2.1Compiling and Executing.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Introduction to Java Applications
Chapter 6 JavaScript: Introduction to Scripting
Chapter 2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Yanal Alahmad Java Workshop Yanal Alahmad
2.5 Another Java Application: Adding Integers
Chapter 2 Introduction to Java Applications
Chapter 2 Introduction to Java Applications
Introduction to Scripting
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to Java Applications
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Advanced Programming Lecture 02: Introduction to C# Apps
Chapter 2 - Introduction to Java Applications
Chapter 2 - Introduction to C Programming
IFS410 Advanced Analysis and Design
Chapter 2 - Introduction to Java Applications
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 3 – Introduction to C# Programming
Introduction to Java Applications
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to Java Applications
Introduction to C Programming
Presentation transcript:

MSIS 655 Advanced Business Applications Programming Week 2 Intro to Java Application This week, a few review of application will be presented. The first assignment is reviewed first, and new concepts in the java is presented. Some operations and methods are briefly presented. 12/3/2018 2.1

Assignment 1: Addition Addition.java 12/3/2018 import javax.swing.JOptionPane; public class Addition { public static void main( String args[] ) { String firstNumber; // first string entered by user String secondNumber; // second string entered by user int number1; // first number to add int number2; // second number to add int sum; // sum of number1 and number2 firstNumber = JOptionPane.showInputDialog( "Enter first integer" ); secondNumber = JOptionPane.showInputDialog( "Enter second integer" ); number1 = Integer.parseInt( firstNumber ); number2 = Integer.parseInt( secondNumber ); sum = number1 + number2; JOptionPane.showMessageDialog( null, "The sum is " + sum, "Results", JOptionPane.PLAIN_MESSAGE ); System.exit( 0 ); // terminate application } // end method main } // end class Addition 12/3/2018

A few tips for Java programming Comments Every program should begin with a comment that explains the purpose of the program, the author and the date and time the program was last modified. Blank line Makes program more readable Blank lines, spaces, and tabs are white-space characters Ignored by compiler Use blank lines and space characters to enhance program readability. Java Application: Applications begin executing at main() Parentheses indicate main is a method (Ch. 3 and 6) Java applications contain one or more methods Exactly one method must be called main() Each line within this method (ex. String firstNumber;) is called a statement. Statements must end with semicolon ; 12/3/2018

Java Identifier Java identifier (name for classes, variables, or methods) Series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) Does not begin with a digit, has no spaces Examples: Welcome1, $value, _value, button7 7button is invalid Java is case sensitive (capitalization matters) a1 and A1 are different By convention, always begin a class name’s identifier with a capital letter and start each subsequent word in the identifier with a capital letter. Java programmers know that such identifiers normally represent Java classes, so naming your classes in this manner makes your programs more readable. Java is case sensitive. Not using the proper uppercase and lowercase letters for an identifier normally causes a compilation error. It is an error for a public class to have a file name that is not identical to the class name (plus the .java extension) in terms of both spelling and capitalization. It is an error not to end a file name with the .java extension for a file containing a class declaration. If that extension is missing, the Java compiler will not be able to compile the class declaration. 12/3/2018

Modifying the first program: Another Adding Integers Fig 2.7 (p. 47) Addition Program using class Scanner Contrast with the assignment 1. Class Scanner was imported before the class declaration. new Scanner command invokes a new object “input.” Numbers were assigned to int variables without converting. System method “printf.” 12/3/2018

class Scanner (new to v. 5.0) Imported to the package to be used with the program Scanner variable (input) is initialized, and used to read data typed by the user at the keyboard (without converting String to integer). Some labs are not upgraded to 5.0 (- -;) This edition of book (6th ed.) is fully incorporated the J2SE 5.0 which includes this Scanner class and printf method of the class System. The labs should have been upgraded. If you have downloaded the J2SE 5.0 for your PC, the program should work as it is. 12/3/2018

import import declarations Used by compiler to identify and locate classes used in Java programs All import declarations must appear before the first class declaration in the file. Tells compiler to load class Scanner from java.util package All import declarations must appear before the first class declaration in the file. Placing an import declaration inside a class declaration’s body or after a class declaration is a syntax error. Forgetting to include an import declaration for a class used in your program typically results in a compilation error containing a message such as “cannot resolve symbol.” When this occurs, check that you provided the proper import declarations and that the names in the import declarations are spelled correctly, including proper use of uppercase and lowercase letters. 3 import java.util.Scanner; // program uses class Scanner 12/3/2018

objects System.in, System.out, System.err Included in the package java.lang. Always imported by compiler. System.in: enables program to input bytes from keyboard. System.out: enables program to output data to screen System.err: enables program to output error message to screen Actually, these three objects are objects of stream. For detailed discussion about the stream, please refer to the chapter 14. These objects are instantiated for any applications executed to prepare for any input, output, or error messages. 12/3/2018

Method “print()” print(argument) – print argument on a line and stop at the end of argument println(argument) – print argument on a line and go to the beginning of next line printf(argument with %_, reference) – formatted printing %d: digit = short, int, long %f: floating point = float, double %s: String = String 12/3/2018

Escape Caracters Escape characters Newline characters (\n) Backslash ( \ ) Indicates special characters be output Newline characters (\n) Interpreted as “special characters” by methods System.out.print and System.out.println, etc. Indicates cursor should be at the beginning of the next line 12/3/2018

Fig. 2.5 | Some common escape sequences. 12/3/2018

Arithmetic Operation Addition + Subtraction - Multiplication * Division / Modulus % (r % s = r mod s) Addition to division should need no explanation. Modulus is sometimes called Remainder, which produce an integer value that is a remnant of division. That is if r is divided by s, and the integer value of the answer was t, then r-s*t is the remainder. e.g., 1 % 3 = 1, 2 % 3 = 2, 3 % 3 = 0, 4 % 3 = 1, … In the same way the operations are conducted in arithmetic, multiplication, division, and modulus are performed prior to addition or subtraction unless those are in parentheses. Assignment statement “sum = number1 + number2” Calculates sum of number1 and number2 (right hand side) Uses assignment operator = to assign result to variable sum Read as: sum gets the value of number1 + number2 number1 and number2 are operands 12/3/2018

if statement Condition if statement Expression can be either true or false if statement Simple version in this section, more detail later If a condition is true, then the body of the if statement executed Control always resumes after the if statement Conditions in if statements can be formed using equality or relational operators (next slide) 12/3/2018

Equality and Relational Operators != not equal > < >= <= Confusing the equality operator, ==, with the assignment operator, =, can cause a logic error or a syntax error. The equality operator should be read as “is equal to,” and the assignment operator should be read as “gets” or “gets the value of.” To avoid confusion, some people read the equality operator as “double equals” or “equals equals.” It is a syntax error if the operators ==, !=, >= and <= contain spaces between their symbols, as in = =, ! =, > = and < =, respectively. 12/3/2018

12/3/2018 Line 6: begins class Comparison declaration Line 12: declares Scanner variable input and assigns it a Scanner that inputs data from the standard input Lines 14-15: declare int variables Lines 17-18: prompt the user to enter the first integer and input the value Lines 20-21: prompt the user to enter the second integer and input the value if statement to test for equality using (==) If variables equal (condition true) Line 24 executes If variables not equal, statement skipped No semicolon at the end of if statement Empty statement No task is performed 12/3/2018

Lines 26-27, 29-30, 32-33, 35-36 and 38-39 Compare number1 and number2 with the operators !=, <, >, <= and >=, respectively 12/3/2018

Lab activities (Week 2) Coding Assignment 2 Exercises (pp. 79-80) 2:24, 2:25, 2:27, 2:30, 2:31 This problem should be similar to the example just we reviewed. Check the examples in the book, you will be able to find necessary stuff. 12/3/2018