Outline. Numbers and Operations. What is binary digit? Dr. Fotis Liarokapis
|
|
- David Douglas
- 7 years ago
- Views:
Transcription
1 Numbers and Operations Dr. Fotis Liarokapis Outline What is a binary digit? Word and byte Java primitive types Arithmetic calculations Precedence of arithmetic operations Concept of casting Variables and assignment Memory concepts Variable names Application for adding integers Program for adding integers Adding integers program output Explanation Lines 4, 6 to 7 Explanation Lines 10 to 11 Explanation Lines 12 to 14 Explanation Lines 16 to 18 Explanation Lines 19 to 21 Explanation Lines 23 to 25 Explanation Lines 27 to 28 Explanation Lines 30 to 33 Final overview of adding integers program Taking input from keyboard Example Java program reading input from keyboard What is binary digit? Word and byte CPU can understand only two conditions 1 current on 0 current off All further computer processing is based on this simple scheme On machine level all data and programs ultimately represented by combination of binary digits (bits) consists of two symbols 0 and 1 Some binary patterns Binary pattern Number Binary pattern Letter A B C D E Data and programs stored in groups of binary digits (bits) A certain number of bits is called word (or machine word) Word length depends on particular hardware and can be: 8, 16, 32, 64 or 128 bits Calculation accuracy depends on the length of word Longer word higher accuracy Byte (= 8 bits) is the amount of memory required to hold a character (letter, digit or punctuation mark) Size of computer memory is described byte units 1 KiloByte (K) = 2 10 = 1024 bytes 1 MegaByte (M) = 2 20 = bytes 1 GigaByte (G) = 2 30 = bytes 1
2 Java primitive types Arithmetic calculations The two major categories of data types in Java are: Primitive Reference Following table illustrates the most commonly used data types Type Size Description byte 8-bit Byte-length integer short 16-bit Short integer int 32-bit Integer long 64-bit Long integer float 32-bit Single-precision floating point double 64-bit Single-precision floating point char 16-bit A single Unicode character boolean True, False A boolean value Integer numbers Real numbers Other types Operator ( + ) Operation addition Operator ( - ) Operation subtraction Operator ( * ) Operation multiplication Operator ( / ) Operation division Note that if both operands are integers, integer division will be performed automatically i.e. 7 / 3 evaluates to 2 Operator ( % ) Operation modulus (returns the reminder from integer division) i.e. 7 % 3 evaluates to 1 Precedence of arithmetic operations The rules of operator precedence (order of evaluation) enable Java to apply operators in the correct order In general operators evaluate from left to right Operator ( ) *, / or % + or - Operations Parenthesis Multiplication, Division, Modulus Addition, Subtraction Precedence Evaluated first. Nested expression innermost first. Same level left to right Evaluated second. If several left to right Evaluated last. If several left to right Concept of casting A simple casting example: Student's grade can be represented by integer numbers (ranging from 1 to 6). Need to calculate average grade for three students where two of them have grade 2 and one has grade 4 Using simple mathematics we can calculate total = 2*2 + 4 = 8 average = total / numberofstudents Note that: total and numberofstudents numberofstudents are integer numbers, and average is double (floating-point real number). But then the average grade is calculated as: Average = 8 / 3 = 2 Wrong answer, because integer division was performed Both operands are integers 2
3 Concept of casting (cont) Variables and assignment For the right answer use Java unitary cast operator average = (double) total / 3 Here total is still an integer but cast operator has created a temporary floating-point copy of its operand 8.0 instead of 8 The right answer for the average is calculated as: average = 8.0 / 3 = 2.67 This kind of casting is called explicit conversion Example: : Calculation of a discount price for some item. Old price was 10 and discount is 2 Variables used: double oldprice,, discount, newprice Calculation procedure: oldprice = 10.0; (assignment operator =) discount = 2.0; newprice = oldprice discount; Assignment operator assigns a particular value to a variable Value of variables may change any number of times during program execution, but only latest value matters. Variables and assignment (cont) Variables and assignment (cont) Consider memory as a large set of boxes that can hold the values of potential variables Boxes for different types of values are different int,, double, char, boolean etc. When we declare variable (describe its name and type), the box of correspondent type allocated and name of variable stick on it int boolean double char declaration oldprice Assignment discount newprice oldprice 10.0 discount 2.0 newprice 8.0 3
4 Memory concepts Variable names Variables Every value has a name, a type, a size and a value Name corresponds to a location in memory When new value is placed into a variable it replaces (and destroys) the previous value Reading values from memory does not change them Visual representation oldprice 10.0 A program refers to a variable s value by its name In Java the following must be true for a variable name It must be a legal Java identifier comprised of a series of Unicode characters Legal Java identifier is a sequence of letters, symbols and digits, started from letter of symbol It must not be a keyword Special reserved words in Java It must not have the same name as another variable declared in the t same scope Variable names (cont) Application for adding integers By Java convention variables names always begin with lower case i.e. average, total, etc. In addition, class names always begin with UPPER case i.e. Vehicle, String, etc. In cases where name consists of more that one word, the words are joined together and each word after first begins with an UPPER case For variable name - averagemark; For class name - StockMarket; The upcoming program Uses input dialogs to input two values from user Uses message dialog to display sum of the two values 4
5 Program for adding integers 1 //application to receive two integers as an input from the user 2 //and print in dialog window their sum 3 4 import java.swing.joptionpane; //import class JOptionPane 5 6 public class AddIntegers 7 { 8 public static void main (String args[]) 9 { 10 String firstnumber, //first String entered by user 11 secondnumber; //second String entered by user 12 int number1, //first number to add 13 number2, //second number to add 14 sum; //sum of number1 and number // read in first number from the user as a String 17 firstnumber = 18 JOptionPane.showInputDialog("Enter first integer"); Program for adding integers (cont) 19 // read in second number from the user as a String 20 secondnumber = 21 JOptionPane.showInputDialog("Enter first integer"); //convert numbers from type String to type int 24 number1 = Integer.parseInt(firstNumber); 25 number2 = Integer.parseInt(secondNumber); //add the numbers 28 sum = number1 + number2; //display the results 31 JOptioPane.showMessageDialog( 32 null, "The sum is " + sum, "Results", 33 JOptionPane.PLAIN_MESSAGE); System.exit(0); //terminate the program 36 } //end of main method 37 } //end of AddIntegers class Adding integers program output Explanation Lines 4, 6 to 7 4 import java.swing.joptionpane; //import class JOptionPane Location of JOptionPane class for the compiler 6 public class AddIntegers 7 { Begins public class AddIntegers Remember that the file name must be AddIntegers.java Line 8, main method declaration 5
6 Explanation Lines 10 to String firstnumber, //first String entered by user 11 secondnumber; //second String entered by user Variable declaration must be declared with names and data type before used in order to locate the required memory space Both variables ( firstnumber firstnumber and secondnumber secondnumber ) are of type String Declarations end with semicolons ( ; ) Can declare multiple variables of the same type at a time Use comma to separate the variables Can add comments to describe the purpose of variables Explanation Lines 12 to int number1, //first number to add 13 number2, //second number to add 14 sum; //sum of number1 and number2 Declare variables number1, number2,, and sum of type int Data type int holds integer values (whole numbers) i.e. 0, 1, 2, 3, -1, -2, -3, etc. Data types float and double can hold decimal numbers i.e. 0.23, 1.34, -5,05, etc. Data type char can hold a single character i.e. a, b, c, etc. Explanation Lines 16 to // read in first number from the user as a String 17 firstnumber = 18 JOptionPane.showInputDialog("Enter first integer"); Read input from the user as a String using JOptionPane dialog window Method JOptionPane.showMessageDialog displays the following: Message called a prompt Directs user to perform an action Argument appears as prompt text If wrong type of data entered (non-integer) then an error occurs! Explanation Lines 16 to 18 (cont) 16 // read in first number from the user as a String 17 firstnumber = 18 JOptionPane.showInputDialog("Enter first integer"); Result of call to showinputdialog given to the variable firstnumber using the assignment operator ( = ) Assignment is a binary operation, takes two operands i.e. calculatenumber = ; Expression on the right evaluated and assigned to a variable on the left Read as: firstnumber gets the value of JOptionPane.showInputDialog( Enter first integer ); 6
7 Explanation Lines 19 to // read in second number from the user as a String 20 secondnumber = 21 JOptionPane.showInputDialog("Enter second integer"); Similar operation with previous slide Only difference is that it is for the second integer value from the user Explanation Lines 23 to //convert numbers from type String to type int 24 number1 = Integer.parseInt(firstNumber); 25 number2 = Integer.parseInt(secondNumber); Method used here is Integer.parseInt Converts String argument into an integer (type int) Class Integer from package java.lang Integer returned by Integer.parseInt is assigned to variable number1 (see line 24) Remember that number1 was declared as type int Line 25 similar to the above Explanation Lines 27 to //add the numbers 28 sum = number1 + number2; Assignment statement 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 Explanation Lines 30 to //display the results 31 JOptioPane.showMessageDialog( 32 null, "The sum is " + sum, "Results", 33 JOptionPane.PLAIN_MESSAGE); Use showmessagedialog to display results "The sum is " + sum Uses the operator + to add the string literal "The sum is " + sum Performs concatenation of a String and another data type Results in a new String If sum contains the value 117, then "The sum is " + sum results in the following new String "The sum is 117" Note the space in "The sum is " 7
8 Explanation Lines 30 to 33 (cont) 30 //display the results 31 JOptioPane.showMessageDialog( 32 null, "The sum is " + sum, "Results", 33 JOptionPane.PLAIN_MESSAGE); Different version of showmessagedialog Requires four arguments (instead of two from previous example) First argument null for now Second argument String to display Third argument String in the title bar Fourth argument type of message dialog JOptionPane.PLAIN_MESSAGE No icon JOptionPane.ERROR_MESSAGE JOptionPane.INFORMATION_MESSAGE JOptionPane.WARNING_MESSAGE JOptionPane.QUESTION_MESSAGE Final overview of adding integers program 1 // clas AddIntegers.java 2 // An addition program 3 4 import javax.swing.joptionpane; // import class JOptionPane 5 6 public class AddIntegers { Declare variables: name and data 7 public static void main( String args[] ) type. 8 { 9 String firstnumber, // first string entered by user 10 secondnumber; // second string entered by user 11 int number1, // first number to add 12 number2, // second number to add 13 sum; // Input sum first of number1 integer as and a number2 String, read in first assign to firstnumber. number from user as a string // 16 firstnumber = 17 JOptionPane.showInputDialog( "Enter first integer" 18 ); 19 // read in second number from user as a string 20 secondnumber = Final overview of adding integers program (cont) 21 JOptionPane.showInputDialog( "Enter Convert second strings to integers. integer" 22 ); 23 // convert numbers from type String to type int 24 number1 = Integer.parseInt( firstnumber ); 25 number2 = Integer.parseInt( secondnumber Add, place ); result in sum // add the numbers 28 sum = number1 + number2; // display the results 31 JOptionPane.showMessageDialog( 32 null, "The sum is " + sum, "Results", 33 JOptionPane.PLAIN_MESSAGE ); System.exit( 0 ); // terminate the program 36 } 37 } Taking input from keyboard Import java.io.package Data from keyboard treats as a stream of data Special java classes desigened to deal with streams of data: InputStreamReader BufferedReader IOException Full list of related classes can be found at Java API specification ion Methods in these classes design to perform different operations with data stream readline() method from class BufferedReader return input data as a String Full list of methods can be found at Java API specification 8
9 Example Java program reading input from keyboard //This application reads in a String input from keyboard and //displays it in command window import java.io.*; public class KeyboardInputTest { public static void main(string args[]) throws IOException { InputStreamReader mystream = new InputStreamReader(System.in); BufferedReader mybuffer = new BufferedReader(myStream); System.out.print("Please, type your message:"); System.out.flush(); String myinput = mybuffer.readline(); System.out.println("You typed in the following message:"); System.out.println(myInput); } } Please, type your message: Hello, Java! You typed in the following message: Hello, Java! Program output 9
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
More informationMULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationHandout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.
Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:
More informationHandout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
More informationSources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
More informationTopics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:
Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of
More informationIntroduction to Visual C++.NET Programming. Using.NET Environment
ECE 114-2 Introduction to Visual C++.NET Programming Dr. Z. Aliyazicioglu Cal Poly Pomona Electrical & Computer Engineering Cal Poly Pomona Electrical & Computer Engineering 1 Using.NET Environment Start
More informationjava.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner
java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources
More informationChapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
More informationIntroduction to Java. CS 3: Computer Programming in Java
Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods
More informationIntroduction to Java Applets (Deitel chapter 3)
Introduction to Java Applets (Deitel chapter 3) 1 2 Plan Introduction Sample Applets from the Java 2 Software Development Kit Simple Java Applet: Drawing a String Drawing Strings and Lines Adding Floating-Point
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 29 / 2014 Instructor: Michael Eckmann Today s Topics Comments and/or Questions? import user input using JOptionPane user input using Scanner psuedocode import
More informationPemrograman Dasar. Basic Elements Of Java
Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle
More informationText file I/O and simple GUI dialogues
Chapter 11 Text file I/O and simple GUI dialogues Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN:
More informationCS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
More informationIntroduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
More informationMoving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
More informationObject Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More informationWRITING DATA TO A BINARY FILE
WRITING DATA TO A BINARY FILE TEXT FILES VS. BINARY FILES Up to now, we have looked at how to write and read characters to and from a text file. Text files are files that contain sequences of characters.
More informationpublic static void main(string[] args) { System.out.println("hello, world"); } }
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
More informationObject Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
More informationJava Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
More informationLecture 5: Java Fundamentals III
Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd
More informationChapter 2 Elementary Programming
Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input
More informationJava Basics: Data Types, Variables, and Loops
Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables
More informationJavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.
1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
More informationJava Crash Course Part I
Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux
More informationCreating a Simple, Multithreaded Chat System with Java
Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate
More informationJava Programming Fundamentals
Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few
More informationJAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
More information13 File Output and Input
SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to
More informationObject-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
More informationChapter 1. Introduction to Computers, Programs, and Java
Chapter 1 Introduction to Computers, Programs, and Java 1.1 Introduction Java is the Internet program language Why Java? The answer is that Java enables user to deploy applications on the Internet for
More informationChulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
More informationVariables, Constants, and Data Types
Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight
More informationCrash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
More informationAP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
More informationJDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I
More informationBachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
More informationChapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
More informationVB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
More informationComputer Programming I
Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,
More informationTranslating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
More informationTo convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:
Binary Numbers In computer science we deal almost exclusively with binary numbers. it will be very helpful to memorize some binary constants and their decimal and English equivalents. By English equivalents
More informationExample of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
More informationINPUT AND OUTPUT STREAMS
INPUT AND OUTPUT The Java Platform supports different kinds of information sources and information sinks. A program may get data from an information source which may be a file on disk, a network connection,
More informationProgramming and Data Structures with Java and JUnit. Rick Mercer
Programming and Data Structures with Java and JUnit Rick Mercer ii Chapter Title 1 Program Development 2 Java Fundamentals 3 Objects and JUnit 4 Methods 5 Selection (if- else) 6 Repetition (while and for
More informationBasic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
More informationAn Overview of Java. overview-1
An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2
More informationChapter 7D The Java Virtual Machine
This sub chapter discusses another architecture, that of the JVM (Java Virtual Machine). In general, a VM (Virtual Machine) is a hypothetical machine (implemented in either hardware or software) that directly
More informationScanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.
Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input
More informationChapter One Introduction to Programming
Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of
More informationComputer Programming I & II*
Computer Programming I & II* Career Cluster Information Technology Course Code 10152 Prerequisite(s) Computer Applications, Introduction to Information Technology Careers (recommended), Computer Hardware
More informationIntroduction to Python
Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment
More informationLesson: All About Sockets
All About Sockets http://java.sun.com/docs/books/tutorial/networking/sockets/index.html Page 1 sur 1 The Java TM Tutorial Start of Tutorial > Start of Trail Trail: Custom Networking Lesson: All About Sockets
More informationUsing SQL Server Management Studio
Using SQL Server Management Studio Microsoft SQL Server Management Studio 2005 is a graphical tool for database designer or programmer. With SQL Server Management Studio 2005 you can: Create databases
More informationJavaScript: Control Statements I
1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can
More informationComputer Programming Tutorial
Computer Programming Tutorial COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Computer Prgramming Tutorial Computer programming is the act of writing computer
More informationJAVA - FILES AND I/O
http://www.tutorialspoint.com/java/java_files_io.htm JAVA - FILES AND I/O Copyright tutorialspoint.com The java.io package contains nearly every class you might ever need to perform input and output I/O
More informationWe will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
More informationProgramming Languages CIS 443
Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception
More informationInstall Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html
CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install
More informationChapter 3. Input and output. 3.1 The System class
Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use
More informationDivision of Informatics, University of Edinburgh
CS1Bh Lecture Note 20 Client/server computing A modern computing environment consists of not just one computer, but several. When designing such an arrangement of computers it might at first seem that
More informationUsing Files as Input/Output in Java 5.0 Applications
Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead
More informationCS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
More informationCS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java
CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section
More informationGetting Started with the Internet Communications Engine
Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2
More informationBinary Number System. 16. Binary Numbers. Base 10 digits: 0 1 2 3 4 5 6 7 8 9. Base 2 digits: 0 1
Binary Number System 1 Base 10 digits: 0 1 2 3 4 5 6 7 8 9 Base 2 digits: 0 1 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417 = 4 * 10 2 + 1 * 10 1
More information#820 Computer Programming 1A
Computer Programming I Levels: 10-12 Units of Credit: 1.0 CIP Code: 11.0201 Core Code: 35-02-00-00-030 Prerequisites: Secondary Math I, Keyboarding Proficiency, Computer Literacy requirement Semester 1
More informationI PUC - Computer Science. Practical s Syllabus. Contents
I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations
More informationIntroduction to Programming
Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck
More informationBuilding a Multi-Threaded Web Server
Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous
More informationHabanero Extreme Scale Software Research Project
Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead
More informationKeywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
More informationSemantic Analysis: Types and Type Checking
Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors
More informationNumber Representation
Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data
More informationTopics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives
Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,
More informationCSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions
CSC45 AUTOMATA 2. Finite Automata: Examples and Definitions Finite Automata: Examples and Definitions A finite automaton is a simple type of computer. Itsoutputislimitedto yes to or no. It has very primitive
More information1 Introduction. 2 An Interpreter. 2.1 Handling Source Code
1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons
More informationExplain the relationship between a class and an object. Which is general and which is specific?
A.1.1 What is the Java Virtual Machine? Is it hardware or software? How does its role differ from that of the Java compiler? The Java Virtual Machine (JVM) is software that simulates the execution of a
More informationJava CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
More informationThe Hexadecimal Number System and Memory Addressing
APPENDIX C The Hexadecimal Number System and Memory Addressing U nderstanding the number system and the coding system that computers use to store data and communicate with each other is fundamental to
More informationDNA Data and Program Representation. Alexandre David 1.2.05 adavid@cs.aau.dk
DNA Data and Program Representation Alexandre David 1.2.05 adavid@cs.aau.dk Introduction Very important to understand how data is represented. operations limits precision Digital logic built on 2-valued
More informationC++ Language Tutorial
cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain
More informationJ a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
More informationComputing Concepts with Java Essentials
2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann
More informationScoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)
Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking
More informationClasses and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
More informationAP Computer Science Static Methods, Strings, User Input
AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because
More informationThe Java Virtual Machine (JVM) Pat Morin COMP 3002
The Java Virtual Machine (JVM) Pat Morin COMP 3002 Outline Topic 1 Topic 2 Subtopic 2.1 Subtopic 2.2 Topic 3 2 What is the JVM? The JVM is a specification of a computing machine Instruction set Primitive
More informationFiles and input/output streams
Unit 9 Files and input/output streams Summary The concept of file Writing and reading text files Operations on files Input streams: keyboard, file, internet Output streams: file, video Generalized writing
More informationSimple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language
Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from
More information