Selected Sections of Applied Informatics LABORATORY 0
|
|
- Matilda Hilda Andrews
- 5 years ago
- Views:
Transcription
1 SSAI 2018Z: Class 1. Basics of Java programming. Page 1 of 6 Selected Sections of Applied Informatics LABORATORY 0 INTRODUCTION TO JAVA PROGRAMMING. BASIC LANGUAGE INSTRUCTIONS. CONSOLE APPLICATION. CONDITION, LOOP INSTRUCTIONS. PROGRAM ARGUMENTS. TABLIC
2 SSAI 2018Z: Class 1. Basics of Java programming. Page 2 of 6 I. Opening a new Java Application project in NetBeans IDE2 1. Open the NetBeans IDE environment by clicking the icon on the desktop.. 2. From the File menu, select New Project... or click the second button on the toolbar to the left.. 3. In the New Project window, select Java in the Categories: Java panel and in the Projects: Java Application panel and confirm with Next > button. 4. In the New Java Application window, fill in the dialog boxes as shown below (case sensitive): In the filed Project Name: type the name of the project Projekt1 In the filed Project Location: select the Z:\ folder as the destination of your project. Check the option: Create Main Class. Give the main project class named Projekt1 a name Klasa1 (instead of Main) by entering projekt1.klasa1 in the lower text field (projekt1 is the name of a Java class package); confirm with Finish button Remember the following generally accepted rules: name of the primary class must match the name of the file that stores its program, the class name must start with a letter and must not contain space characters, class names are usually written in capital letters. 5. In the Files window, view the structure and contents of the Netbeans project folders that were created for an empty Java Application in the Z folder: 6. Start an empty Java application with the F6 function key. After a successful compilation, a build folder will be created. In the Files window, look at its contents. Folder Projekt1\src\projekt1 already contains the source file of the project called Klasa1.java Folder build will be created after a successful compilation and will contain subfolders classes, and then project1, which will contain byte code of our application. Folder Projekt1\build\classes\projekt1 will contain a file named Klasa1.class II. The first program in Java 1. Type the following instructions into the Netbeans editor window public class Klasa1 { public static void main (String[] args) { System.out.println("Hallo in Java"); 2. Run the F11 project compilation and check for errors. 3. Run the program by pressing F6 and observe the results of the execution in the Output window. As a result, a welcome is displayed: Hallo in Java III. Arguments of the programme 1. Return to editing the source text of the program. Before the main() method's curly brackets close, declare two text variables a and b, and then assign to them the program arguments contained in two consecutive elements of the args array. The program's argument can be any character string that does not contain spaces. String a, b;
3 SSAI 2018Z: Class 1. Basics of Java programming. Page 3 of 6 a= args[0]; b= args[1]; 2. In the following instructions, display the values of the variables a and b: System.out.println(a); System.out.println(b); 3. Save your changes and restart the program. If you do not provide any argument, an execution error occurs, i.e. an exception, and the following message appears in the command window: Exception in thread "main" java.lang.arrayindexoutofboundsexception: denoting an attempt to refer to a non-existent element of the args array. Such an exceptional situation in the program should be predicted and handled, what we will do later in the exercise. 4. Define the arguments of the program. To do this, enter the Properties of the project using the pop-up menu. In the "Project Properties" dialog box, go to the [Run] tab. In the "Arguments" field, enter any integers separated by a space: Add an instruction displaying the sum of arguments a and b: System.out.print("Sum of arguments: "); System.out.println(a+b); then compile and run the program and analyse the result. IV. Display results in the Output window; constants and text variable 1. Delete the current content of the method main(). 2. Inside the main() method, type calling a method for displaying text: "Welcome to NetBeans". (If the line numbering is not displayed, you can select from the menu command View Show Line Numbers.) 3. If the instruction is incorrectly typed (e.g. case-insensitive), the following button will appear instead of the line number. Then point the mouse cursor over this button and a description of the error will appear in the explanation window. (Usually the beginning of the red toothed underline in a line indicates where the error occurred.) 4. At the end of the main() method, before the curly bracket that closes it, declare the String class object variable text and assign it a specific string (text string): String text = " The Java language was created by SUN. "; 5. In the next line add the instruction: System.out.println(text); 6. Start the program and check its operation.. V. Arguments and numeric variables; conversion of text to numbers; calculation of expressions and display of the result
4 SSAI 2018Z: Class 1. Basics of Java programming. Page 4 of 6 1. Return to program editing and continue to declare three variables k,m, n, type int, which will be used to store integers. Assign the k variable a constant value of 10. Assign the variables m and n to the first two arguments of the program using the parseint() conversion method of the Integer class.: int k = 10; int m = Integer.parseInt(args[0]); int n = Integer.parseInt(args[1]); 2. Run the program without arguments. Because no elements are passed to the args array on the command line, an execution error (exception) will occur, represented by the class ArrayIndexOutOfBoundsException (exceeding the range of array indices). 3. To prevent exceptions that may occur when displaying non-existent arguments, place the instructions in V.1 inside the part try of instructions try-catch: try{ int m = Integer.parseInt(args[0]); int n = Integer.parseInt(args[1]); System.out.println(m); System.out.println(n); catch (ArrayIndexOutOfBoundsException e) { System.out.println("No args"); (The program will try to display arguments in some modes, and in case of failure it will go to the catch part, which will intercept the exception of exceeding the range of the array and display a message.) 4. In the Projects window, right-click the name of the Project1 project. Then select Properties. In the Project Properties - Project1 window, in the Categories: panel, highlight the Run category. In the Arguments: field, type two integers separated by spaces as program arguments 5. Save changes and run the program. 6. Execute the program by providing text arguments instead of numeric ones. The given arguments cannot be converted to integers, which will result in an exception to the NumberFormatException class (incorrect format of the number). 7. Return to program edition. In the instruction try-catch add secont part: catch, which will handle exceptions to this class: catch (ArrayIndexOutOfBoundsException e) { System.out.println("No args"); catch (NumberFormatException e) { System.out.println("Incorrect argument! Enter two integers. "); 8. At the end of the try part, declare an integer variable named sum and assign the sum of three variables to it with the following instruction: int sum =k+ m + n; 9. In the next line add an instruction displaying the text "sum=" and the contents of the variable sum, the result of the summation: System.out.print("sum = "); System.out.println(sum); 10. Save the changes, compile the program and execute it with two integers separated by a space Below the sum, display the product of the variables k, m. n - in order to do so, go to the edition of the program, complete it with the appropriate instructions Check the operation of the program in case of correct and incorrect arguments. VI. Standard input/output: reading text from the keyboard and displaying in the Output window.t 1. In the NetBeans environment, create a new project using the File New Project menu command. In the New Project dialog box, select Java in the panel Categories: Java, and Java Application in the Projects panel. In the New Java Application window, give the project the name Projekt21 and the main class the name WeWy. As the destination of the project, select the working folder Z:\. At the beginning of the main() method, create a field representing a buffer reader that will read single lines of text from the keyboard BufferedReader we = new BufferedReader(new InputStreamReader(System.in)); 2. By command Fix Imports from the pop-up menu import BufferedReader and InputStreamReader classes from the java.io package of Java library resources. Import clauses will appear in the initial part of the program. In order to read the values of subsequent data from the keyboard, we will use the readline() of we object. Before reading the next data we will display a hint for the user. Below the reader's declaration add instructions: System.out.print("Your Name and Surname:"); String student = we.readline() ; Method readline()as an input/output operation may generate class execution errors (exceptions) IOException so a compilation error occurs: unreported exception java.io.ioexception; must be caught or declared to be thrown. Click on the error button and select Add throws clause for java.io.ioexception This will result addition to the header of the method main() frphrase throws IOException and transferring the handling of this error to the system.
5 SSAI 2018Z: Class 1. Basics of Java programming. Page 5 of 6 3. Start the program, then click to move the cursor to the Output window and enter your data, ending it with the ENTER key.. 4. Enter the album number and average note as the next data; these will be the values of two numeric variables - total and real.. int Index = Integer.parseInt(we.readLine()); float note = Float.parseFloat(we.readLine()); 5. Before each instruction to read the data, add an instruction that displays a hint for the user. 6. Add an instruction to display the entered data. Start the program. Observe the effect of incorrect entry of an album number or rating (e.g. letter instead of a number, comma instead of a dot). 7. To handle an exception generated by an erroneous entry, enclose the following instructi try-catch the instructions for converting text into numbers assigned to variables in point I.6 Index and note. In part catch recognize the class exception NumberFormatException and add an instruction that will display a message " incorrect number format". Check the operation of this exception. VII. Assignment instructions and data types. Data conversion. Arithmetic operations. Use of mathematical functions. 1. In the next example we will program calculations for numbers loaded from the keyboard. We make them in a new project, created as a copy of the project Projekt21. In the Projects window, right-click the Projekt21 name and select Copy from the popup menu. In the dialog box, enter the name of the new Project22 projectexpand the folders of a new project and change the name of the main class to Calculations, by clicking on the class name WeWy with the right mouse button and by selecting the following commands Refactor Rename. Double-click on the name of the Calculation class, open it in the NetBeans editor and modify it. 2. Delete the instruction to read the name and change the instruction displaying these data to the following (enter your data): System.out.println("Program author: xxxx yyyyyyyy"); 3. Change the instructions for reading the album number and rating to reading two integers (type int), modify the hints before reading each of the data: int a = Integer.parseInt(we.readLine()); int b = Integer.parseInt (we.readline()); 4. In the following lines display the sum, difference, product and quotient of numbers a and b: System.out.println("arithmetic operations on numbers " +a+ "and " +b); System.out.println("sum ="+ (a+b)); System.out.println("differential ="+ (a-b)); System.out.println("multiplication ="+a*b); System.out.println("quotient ="+a/b); 5. Where two integers are subdivided, provision must be made for the situation of subdivision by zero, which gives rise to a class exception. ArithmeticExceptionTo handle it, add after an existing phrase catch another phrase catch the character: catch(arithmeticexception e) {System.out.println("Calculation error!"); 6. Run the program and check its operation 7. Then change the type of variables a and b to the real type (double), replacing the instructions in point 3 as follows: double a = Double.parseDouble(we.readLine()); double b = Double.parseDouble(we.readLine()); 8. Run the program and check its operation 9. Inside block try... catch add further instructions to illustrate the use of built-in mathematical functions: System.out.println("square root from the number a = "+Math.sqrt(a)); System.out.println("3rd power of numbers b = "+Math.pow(b,3)); System.out.println("sinus lof number b = "+Math.sin(b)); System.out.println("Rounding of a number = "+Math.round(3.234)); System.out.println("Rounding of a number = "+Math.round(3.654)); 10. Then calculate and display the distance of the point with coordinates (a, b) from the point (-1, 1) by yourself. Check the operation of the program. VIII. Iterative sum calculation; entering, summing up and displaying program arguments, example of a conditional if instruction 1. Create another new project of the Java Application type, give the project a name Projekt23 and the main class - the name Sum. As a project destination, select a working folder Z:\
6 SSAI 2018Z: Class 1. Basics of Java programming. Page 6 of 6 2. In the content of the method main() declare the variable sum of the total type and give it its initial value 0 by means of an instruction: int sum = 0; 3. Then use the for loop to calculate the sum of the natural numbers in the range 1, 10 : for (int i = 1; i <=10; i++) { sum +=i; In the following iteration steps, the value of the variable and loop control will change from 1 (int i declaration = 1;) to 10 (condition and <= 10;) with step 1 (i++ increment operation). 4. Add an instruction displaying the calculated sum, with the comment "The sum of numbers from 1 to 10 is ". Start the program and check the displayed summation result. 5. The next task of the program will be to display the arguments of the program and calculate the sum of arguments, which are integers. Enter the program arguments by entering several integers separated by spaces in the line Arguments (command Properties Run). 6. Add an instruction displaying the number of entered program arguments in text form: "Programme has"+ args.length +" arguments" (the args.length property specifies the number of arguments) 7. Then display the values of these arguments in the for: for (int k = 0; k<args.length; k++) { System.out.println((k+1) + ": " + args[k]); 8. Correct possible errors and start the program. 9. Add another for instruction to iteratively calculate the sum of all arguments of the program that are integers: for (int i = 0; i <args.length; i++) { // i change with respect to the indexes of the array args m = Integer.parseInt(args[i]); // value of i-element assigned to a variable m sum +=m; // to add another argument to the sum Remember to clear the variable sum and declare the variable m first. Note: The args.length property specifies the length of the args array, which is the current number of arguments it contains. 10. Then add an instruction displaying the calculated sum of arguments with an appropriate comment. 11. Right-click in the code editor window and from the popup menu, select Format (or use the keyboard shortcut <Alt+Shift+F>) to align your instructions. 12. Then we will use the conditional if instruction to check if the number of arguments is even or not. int t = args.length; if( t % 2 == 0 ) System.out.println("The given number of arguments is even."); else System.out.println("The given number of arguments is odd."); 13. Correct errors and run the program.
Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the
Description Exception Handling in Java An Exception is a compile time / runtime error that breaks off the program s execution flow. These exceptions are accompanied with a system generated error message.
More informationLesson 3: Accepting User Input and Using Different Methods for Output
Lesson 3: Accepting User Input and Using Different Methods for Output Introduction So far, you have had an overview of the basics in Java. This document will discuss how to put some power in your program
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationData Types and the while Statement
Session 2 Student Name Other Identification Data Types and the while Statement In this laboratory you will: 1. Learn about three of the primitive data types in Java, int, double, char. 2. Learn about the
More informationC16b: Exception Handling
CISC 3120 C16b: Exception Handling Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/28/2018 CUNY Brooklyn College 1 Outline Exceptions Catch and handle exceptions (try/catch)
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More information6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.
Page 1 of 5 6.170 Laboratory in Software Engineering Java Style Guide Contents: Overview Descriptive names Consistent indentation and spacing Informative comments Commenting code TODO comments 6.170 Javadocs
More informationA Guide Illustrating the Core Java Equivalent to Selected Tasks Done Using the HSA Class Library
HSA to Core Java A Guide Illustrating the Core Java Equivalent to Selected Tasks Done Using the HSA Class Library The examples below compare how tasks are done using the hsa Console class with how they
More informationMore on Exception Handling
Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationMore on Exception Handling
Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationIntroduction Unit 4: Input, output and exceptions
Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Introduction Unit 4: Input, output and exceptions 1 1.
More informationLecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos.
Lecture 05: Methods AITI Nigeria Summer 2012 University of Lagos. Agenda What a method is Why we use methods How to declare a method The four parts of a method How to use (invoke) a method The purpose
More informationRecursion. General Algorithm for Recursion. When to use and not use Recursion. Recursion Removal. Examples
Recursion General Algorithm for Recursion When to use and not use Recursion Recursion Removal Examples Comparison of the Iterative and Recursive Solutions Exercises Unit 19 1 General Algorithm for Recursion
More informationInput from Files. Buffered Reader
Input from Files Buffered Reader Input from files is always text. You can convert it to ints using Integer.parseInt() We use BufferedReaders to minimize the number of reads to the file. The Buffer reads
More informationLecture 11.1 I/O Streams
21/04/2014 Ebtsam AbdelHakam 1 OBJECT ORIENTED PROGRAMMING Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 2 Outline I/O Basics Streams Reading characters and string 21/04/2014 Ebtsam AbdelHakam
More information( &% class MyClass { }
Recall! $! "" # ' ' )' %&! ( &% class MyClass { $ Individual things that differentiate one object from another Determine the appearance, state or qualities of objects Represents any variables needed for
More informationWOSO Source Code (Java)
WOSO 2017 - Source Code (Java) Q 1 - Which of the following is false about String? A. String is immutable. B. String can be created using new operator. C. String is a primary data type. D. None of the
More informationWorkbook 5. Remember to check the course website regularly for announcements and errata: Managing errors with Java Exceptions
Introduction Workbook 5 The implementation of PatternLife you wrote last week is brittle in the sense that the program does not cope well when input data is malformed or missing. This week you will improve
More informationCreating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.
First Program (02) Creating a Java program and understanding the basic concepts. Creating a Program in JCreator It is usually a good idea to create a folder where you re going to save your Java programs.
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of February 23, 2013 Abstract Handling errors Declaring, creating and handling exceptions
More informationInf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java
Organisational issues Inf1-OOP Course Overview Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics January 11, 2014 Why Java? Hello, World! in Java Built-in Types Integers Floating-Point
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationProgramming - 2. Common Errors
Common Errors There are certain common errors and exceptions which beginners come across and find them very annoying. Here we will discuss these and give a little explanation of what s going wrong and
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of February 23, 2013 Abstract Handling errors Declaring, creating and handling exceptions
More informationFull file at Chapter 2 - Inheritance and Exception Handling
Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a
More informationCSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013
CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013 Name: This exam consists of 7 problems on the following 6 pages. You may use your single- side hand- written 8 ½ x 11 note sheet during the
More informationICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit
ICOM 4015 Advanced Programming Laboratory Chapter 1 Introduction to Eclipse, Java and JUnit University of Puerto Rico Electrical and Computer Engineering Department by Juan E. Surís 1 Introduction This
More informationJava Exception Handling
Java Exception Handling Handling errors using Java s exception handling mechanism Approaches For Dealing With Error Conditions Use branches/decision making and return values Use Java s exception handling
More informationTools : The Java Compiler. The Java Interpreter. The Java Debugger
Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,
More informationFull file at
Chapter 1 Primitive Java Weiss 4 th Edition Solutions to Exercises (US Version) 1.1 Key Concepts and How To Teach Them This chapter introduces primitive features of Java found in all languages such as
More informationMSc/ICY Software Workshop Exception Handling, Assertions Scanner, Patterns File Input/Output
MSc/ICY Software Workshop Exception Handling, Assertions Scanner, Patterns File Input/Output Manfred Kerber www.cs.bham.ac.uk/~mmk 21 October 2015 1 / 18 Manfred Kerber Classes and Objects The information
More informationTopic 6: Exceptions. Exceptions are a Java mechanism for dealing with errors & unusual situations
Topic 6: Exceptions Exceptions are a Java mechanism for dealing with errors & unusual situations Goals: learn how to... think about different responses to errors write code that catches exceptions write
More informationInf1-OP. Course Overview. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. February 26, School of Informatics
Inf1-OP Course Overview Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics February 26, 2018 Administrative Stuff Who to contact for help? Lecturer: Volker
More informationReading Input from Text File
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 5 Reading Input from Text File Eng. Mohammed Alokshiya November 2, 2014 The simplest
More informationWeek 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O
Week 12 Streams and File I/O Overview of Streams and File I/O Text File I/O 1 I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or a file
More informationCS 152: Data Structures with Java Hello World with the IntelliJ IDE
CS 152: 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: Electrical and Computer Engineering building
More informationInf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens
Organizational Issues Inf1-OOP Course Overview Ewan Klein, Perdita Stevens School of Informatics January 12, 2013 Why Java? Hello, World! in Java Built-in Types Integers Floating-Point Numbers Type Conversion
More informationCS1092: Tutorial Sheet: No 3 Exceptions and Files. Tutor s Guide
CS1092: Tutorial Sheet: No 3 Exceptions and Files Tutor s Guide Preliminary This tutorial sheet requires that you ve read Chapter 15 on Exceptions (CS1081 lectured material), and followed the recent CS1092
More informationFor more details on SUN Certifications, visit
Exception Handling For more details on SUN Certifications, visit http://sunjavasnips.blogspot.com/ Q: 01 Given: 11. public static void parse(string str) { 12. try { 13. float f = Float.parseFloat(str);
More informationSoftware and Programming 1
Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 17 January 2019 SP1-Lab1-2018-19.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon
More informationReview of Basic Java
Review of Basic Java 1 Background The course is a follow-on to your first programming course in Java. It is assumed you are already familiar with the basic elements of Java (such as Console, print, int,
More informationJAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly
More informationArrays. 1 Index mapping
Arrays 1 Index mapping You are expected already to have a good understanding of arrays. We examine some array techniques in more detail, beginning with index mapping. Index mapping is a technique for compact
More informationC17: File I/O and Exception Handling
CISC 3120 C17: File I/O and Exception Handling Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/24/2017 CUNY Brooklyn College 1 Outline Recap and issues Exception Handling
More informationExcep&ons and file I/O
Excep&ons and file I/O Exception in thread "main" java.lang.numberformatexception: For input string: "3.5" at java.lang.numberformatexception.forinputstring(numberformatexception.java:48) at java.lang.integer.parseint(integer.java:458)
More informationCOMP 110/401 APPENDIX: INSTALLING AND USING ECLIPSE. Instructor: Prasun Dewan (FB 150,
COMP 110/401 APPENDIX: INSTALLING AND USING ECLIPSE Instructor: Prasun Dewan (FB 150, dewan@unc.edu) SCOPE: BASICS AND BEYOND Basic use: CS 1 Beyond basic use: CS2 2 DOWNLOAD FROM WWW.ECLIPSE.ORG Get the
More informationWho and what can help? Inf1-OP. Lecturer: Timothy Hospedales TA: Natalia Zon
Who and what can help? Inf1-OP Lecturer: Timothy Hospedales TA: Natalia Zon Course Overview Web: http://www.inf.ed.ac.uk/teaching/ courses/inf1/op/ Timothy Hospedales, adapting earlier version by Perdita
More informationObject Oriented Programming
Object Oriented Programming Java lecture (10.1) Exception Handling 1 Outline Exception Handling Mechanisms Exception handling fundamentals Exception Types Uncaught exceptions Try and catch Multiple catch
More informationJava Exception Handling
Java Exception Handling Handling errors using Java s exception handling mechanism Approaches For Dealing With Error Conditions Use conditional statements and return values Use Java s exception handling
More informationException in thread "main" java.lang.arithmeticexception: / by zero at DefaultExceptionHandling.main(DefaultExceptionHandling.
Exceptions 1 Handling exceptions A program will sometimes inadvertently ask the machine to do something which it cannot reasonably do, such as dividing by zero, or attempting to access a non-existent array
More informationSimple Java Reference
Simple Java Reference This document provides a reference to all the Java syntax used in the Computational Methods course. 1 Compiling and running... 2 2 The main() method... 3 3 Primitive variable types...
More informationLoops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 6 Loops
More informationExceptions and I/O: sections Introductory Programming. Errors in programs. Exceptions
Introductory Programming Exceptions and I/O: sections 80 83 Anne Haxthausen a IMM, DTU 1 Exceptions (section 80) 2 Input and output (I/O) (sections 81-83) a Parts of this material are inspired by/originate
More informationIntroductory Programming Exceptions and I/O: sections
Introductory Programming Exceptions and I/O: sections 80 83 Anne Haxthausen a IMM, DTU 1 Exceptions (section 80) 2 Input and output (I/O) (sections 81-83) a Parts of this material are inspired by/originate
More informationEXCEPTIONS. Fundamentals of Computer Science I
EXCEPTIONS Exception in thread "main" java.lang.numberformatexception: For input string: "3.5" at java.lang.numberformatexception.forinputstring(numberformatexception.java:48) at java.lang.integer.parseint(integer.java:458)
More informationAdvanced Computer Programming
Programming in the Small I: Names and Things (Part II) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University
More informationLecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166
Lecture 20 Java Exceptional Event Handling Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics What is an Exception? Exception Handler Catch or Specify Requirement Three Kinds of Exceptions
More informationAdding Existing Source Code in NetBeans CS288, Autumn 2005 Lab 002
Adding Existing Source Code in NetBeans CS288, Autumn 2005 Lab 002 Purpose This document will show how to incorporate existing source code within a NetBeans project. It will also introduce the concept
More informationC++ Support Classes (Data and Variables)
C++ Support Classes (Data and Variables) School of Mathematics 2018 Today s lecture Topics: Computers and Programs; Syntax and Structure of a Program; Data and Variables; Aims: Understand the idea of programming
More informationExpress Yourself. What is Eclipse?
CS 170 Java Programming 1 Eclipse and the for Loop A Professional Integrated Development Environment Introducing Iteration Express Yourself Use OpenOffice or Word to create a new document Save the file
More informationIntroduction to C# Applications
1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making
More information2 Getting Started. Getting Started (v1.8.6) 3/5/2007
2 Getting Started Java will be used in the examples in this section; however, the information applies to all supported languages for which you have installed a compiler (e.g., Ada, C, C++, Java) unless
More informationProgramming Problems 15th Annual Computer Science Programming Contest
Programming Problems 15th Annual Computer Science Programming Contest Department of Mathematics and Computer Science Western Carolina University March 0, 200 Criteria for Determining Scores Each program
More informatione) Implicit and Explicit Type Conversion Pg 328 j) Types of errors Pg 371
Class IX HY 2013 Revision Guidelines Page 1 Section A (Power Point) Q1.What is PowerPoint? How are PowerPoint files named? Q2. Describe the 4 different ways of creating a presentation? (2 lines each) Q3.
More informationCAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE
CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What
More information12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started
More informationCS 251 Intermediate Programming Java I/O Streams
CS 251 Intermediate Programming Java I/O Streams Brooke Chenoweth University of New Mexico Spring 2018 Basic Input/Output I/O Streams mostly in java.io package File I/O mostly in java.nio.file package
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationChapter 5 Some useful classes
Chapter 5 Some useful classes Lesson page 5-1. Numerical wrapper classes Activity 5-1-1 Wrapper-class Integer Question 1. False. A new Integer can be created, but its contents cannot be changed. Question
More information3. NetBeans IDE 6.0. Java. Fall 2009 Instructor: Dr. Masoud Yaghini
3. NetBeans IDE 6.0 Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Installing the NetBeans IDE First NetBeans IDE Project IDE Windows Source Editor Customizing the IDE References Installing the
More informationInput & Output in Java. Standard I/O Exception Handling
Input & Output in Java Standard I/O Exception Handling Java I/O: Generic & Complex Java runs on a huge variety of plaforms to accomplish this, a Java Virtual Machine (JVM) is written for every type of
More informationVARIABLES, DATA TYPES,
1-59863-275-2_CH02_31_05/23/06 2 C H A P T E R VARIABLES, DATA TYPES, AND SIMPLE IO In this chapter, you learn how to use variables, data types, and standard input/output (IO) to create interactive applications.
More information1. An operation in which an overall value is computed incrementally, often using a loop.
Practice Exam 2 Part I: Vocabulary (10 points) Write the terms defined by the statements below. 1. An operation in which an overall value is computed incrementally, often using a loop. 2. The < (less than)
More informationByte and Character Streams. Reading and Writing Console input and output
Byte and Character Streams Reading and Writing Console input and output 1 I/O basics The io package supports Java s basic I/O (input/output) Java does provide strong, flexible support for I/O as it relates
More information3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)
GETTING STARTED: YOUR FIRST JAVA APPLICATION 15 3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS) GETTING STARTED: YOUR FIRST JAVA APPLICATION Checklist: The most recent version of Java SE Development
More informationIntroduction. Key features and lab exercises to familiarize new users to the Visual environment
Introduction Key features and lab exercises to familiarize new users to the Visual environment January 1999 CONTENTS KEY FEATURES... 3 Statement Completion Options 3 Auto List Members 3 Auto Type Info
More informationJava Exception Handling
Java Exception Handling Handling errors using Java s exception handling mechanism Approaches For Dealing With Error Conditions Use branches/decision making and return values Use Java s exception handling
More information1. Download the JDK 6, from
1. Install the JDK 1. Download the JDK 6, from http://java.sun.com/javase/downloads/widget/jdk6.jsp. 2. Once the file is completed downloaded, execute it and accept the license agreement. 3. Select the
More informationEng. Mohammed S. Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 3 Selections
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationPrinciples of Computer Science I
Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120A - Fall 2004 Lecture Unit 7 Review Chapter 4 Boolean data type and operators (&&,,) Selection control flow structure if, if-else, nested
More informationLab 5: Java IO 12:00 PM, Feb 21, 2018
CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Lab 5: Java IO 12:00 PM, Feb 21, 2018 1 The Java IO Library 1 2 Program Arguments 2 3 Readers, Writers, and Buffers 2 3.1 Buffering
More informationChapter 4 Introduction to Control Statements
Introduction to Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives 2 How do you use the increment and decrement operators? What are the standard math methods?
More informationJava Exception Handling
Java Exception Handling Handling errors using Java s exception handling mechanism Approaches For Dealing With Error Conditions Use branches/decision making and return values Use Java s exception handling
More informationCOMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output
COMP 213 Advanced Object-oriented Programming Lecture 19 Input/Output Input and Output A program that read no input and produced no output would be a very uninteresting and useless thing. Forms of input/output
More informationBBM 102 Introduction to Programming II Spring Exceptions
BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom
More informationDM550 / DM857 Introduction to Programming. Peter Schneider-Kamp
DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ CALLING & DEFINING FUNCTIONS 2 Functions and
More informationCOMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions
COMP 213 Advanced Object-oriented Programming Lecture 17 Exceptions Errors Writing programs is not trivial. Most (large) programs that are written contain errors: in some way, the program doesn t do what
More informationSome Patterns for CS1 Students
Some Patterns for CS1 Students Berna L. Massingill Abstract Students in beginning programming courses struggle with many aspects of programming. This paper outlines some patterns intended to be useful
More information1 Ctrl + X Cut the selected item. 2 Ctrl + C (or Ctrl + Insert) Copy the selected item. 3 Ctrl + V (or Shift + Insert) Paste the selected item
Tips and Tricks Recorder Actions Library XPath Syntax Hotkeys Windows Hotkeys General Keyboard Shortcuts Windows Explorer Shortcuts Command Prompt Shortcuts Dialog Box Keyboard Shortcuts Excel Hotkeys
More informationIntroduction to C/C++ Programming
Chapter 1 Introduction to C/C++ Programming This book is about learning numerical programming skill and the software development process. Therefore, it requires a lot of hands-on programming exercises.
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationIT 374 C# and Applications/ IT695 C# Data Structures
IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation
More informationCSEN 202 Introduction to Computer Programming
CSEN 202 Introduction to Computer Programming Lecture 4: Iterations Prof. Dr. Slim Abdennadher and Dr Mohammed Abdel Megeed Salem, slim.abdennadher@guc.edu.eg German University Cairo, Department of Media
More informationA very simple program. Week 2: variables & expressions. Declaring variables. Assignments: examples. Initialising variables. Assignments: pattern
School of Computer Science, University of Birmingham. Java Lecture notes. M. D. Ryan. September 2001. A very simple program Week 2: variables & expressions Variables, assignments, expressions, and types.
More informationAfter completing this appendix, you will be able to:
1418835463_AppendixA.qxd 5/22/06 02:31 PM Page 879 A P P E N D I X A A DEBUGGING After completing this appendix, you will be able to: Describe the types of programming errors Trace statement execution
More informationI pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.
Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone
More information4 WORKING WITH DATA TYPES AND OPERATIONS
WORKING WITH NUMERIC VALUES 27 4 WORKING WITH DATA TYPES AND OPERATIONS WORKING WITH NUMERIC VALUES This application will declare and display numeric values. To declare and display an integer value in
More informationLecture 4: Exceptions. I/O
Lecture 4: Exceptions. I/O Outline Access control. Class scope Exceptions I/O public class Malicious { public static void main(string[] args) { maliciousmethod(new CreditCard()); } static void maliciousmethod(creditcard
More informationSection 2: Introduction to Java. Historical note
The only way to learn a new programming language is by writing programs in it. - B. Kernighan & D. Ritchie Section 2: Introduction to Java Objectives: Data Types Characters and Strings Operators and Precedence
More information