Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Sri Lanka Institute of Information Technology Faculty of Computing IT1120 - Introduction to Programming Dr.Junius Anjana Year 01 and Semester 01 Year 01 and Semester 01 1 / 39 IP Delivery Team Malabe...

Sri Lanka Institute of Information Technology Faculty of Computing IT1120 - Introduction to Programming Dr.Junius Anjana Year 01 and Semester 01 Year 01 and Semester 01 1 / 39 IP Delivery Team Malabe Dr. Junius Anjana - [email protected] (LIC) Dr. Kalpani Manathunga - [email protected] Dr. Namalie Walgampaya - [email protected] Dr. Dharshana Kasthurirathna - [email protected] Dr. Mahima Weerasinghe - [email protected] Dr. Dinuka Sahabandu - [email protected] Ms. Shalini Rupasinghe - [email protected] Ms. Thilini Jayalath - [email protected] Mr. Vishan Jayasinghearachchi - [email protected] Ms. Dushanthi Kuruppu - [email protected] Year 01 and Semester 01 2 / 39 IP Delivery Team Metro Ms. Anjalie Gamage - [email protected] Matara Ms. Suriyaa Kumari - [email protected] Kandy UNI Mr. Krishantha Ranaweera - [email protected] Kurunegala Ms. Chathurika Herath - [email protected] Northern UNI Mr. Sinthujan Ragunathan - [email protected] Year 01 and Semester 01 3 / 39 IP Module Outline Modes of Delivery Lectures – 2 hours per week Tutorials – 1 hour per week Labs – 2 hours per week Assessments Weekly Lab Submissions - 10% Mid Exam – 20% (1 Hour) Practical Test – 20% (1 Hour) Final Exam – 50% (2 Hours) Module Pass Requirement To pass this module, students need to obtain a 50% in all ’Continuous Assessments’ and an overall mark that would qualify for a ’C’ grade or above. Year 01 and Semester 01 4 / 39 Recommended Books K. Sierra, B. Bates, T. Gee, Head First Java, 3rd edition, O’Reilly Media, Inc., 2022, ISBN: 9781491910771 L.A. Robertson, Simple Program Design, A Step-by-Step Approach, 5th edition, Cengage Learning, 2006, ISBN: 9781423901327 H. Schildt, Java: The Complete Reference, 12th edition, 2021, McGraw Hill, ISBN: 1260463419 Year 01 and Semester 01 5 / 39 Lecture 1 Introduction Basic operations of a computer, Evolvement of Programming Languages, Translators, First Java Program Year 01 and Semester 01 6 / 39 What is a computer? A computer is a machine for processing data to produce information. What does the computer do? Store large amounts of data. Process large amount of data quickly. Protects data and resources. Data Analysis. Enables communication Networking How do you instruct the computers to do these tasks? Computers perform all these tasks through a combination of hardware and software working together in a systematic way. Year 01 and Semester 01 7 / 39 What is a software? A set of instructions used to operate a computer to produce a specific result. A software acts as a bridge between the user and the computer’s hardware, allowing us to perform tasks, solve problems, and create or manage data. The process of writing software / computer programs is called programming These software / computer programs are written by a programmer A set of rules that tell a computer what operations to perform are called programming language Year 01 and Semester 01 8 / 39 Software Development Life Cycle Software development is the process of creating computer programs. It involves several key steps. Analysis - Understand/Define the problem Design - Plan the solution Test the solution - Does the design works (In theory) Fix the solution - Correct the design where it failed Implement - Write and document the code Test - Compile, Debug and test Deploy - Release the software for users to install and use Maintain - Address user feedback and make enhancements Year 01 and Semester 01 9 / 39 Analysis - Understand/Define the problem Understanding what issue or need the software will solve. Start with a ‘top level’ general English description of the problem; State what data is required to solve the problem: The input data. State what results will be calculated: The output data. What actions need to be taken to generate the results : The processes/tasks Year 01 and Semester 01 10 / 39 Exercise 1 Analyze the following problem: Write a program to find the summation of two integers input from the keyboard. Output the result to the screen. Input : Two integers Task/Process : Find the sum of two integers Output : The sum Year 01 and Semester 01 11 / 39 Exercise 2 Analyze the following problem: Write a program to find the area of a circle when the radius is entered from the keyboard. Output the result to the screen. Input : Task/Process : Output : Year 01 and Semester 01 12 / 39 Exercise 3 Analyze the following problem: In an experiment, the heights of 5 people were recorded and the average height was computed. Due to negligence the height of two people has been lost. The lab assistant distinctly remembers that the two missing heights were almost the same. You are required to input the heights of the known three people and the calculated average. Find and print the missing height. Input : Task/Process : Output : Year 01 and Semester 01 13 / 39 Design – Plan the solution Use algorithms to prepare a solution Algorithm: A step-by-step set of instructions designed to solve a particular problem. The key characteristics of an algorithm State instructions precisely, without ambiguity State instructions in order Algorithms are represented by flowcharts and pseudocodes. Year 01 and Semester 01 14 / 39 Pseudocodes Pseudocode is a simplified, informal way of writing algorithms in a form that resembles programming language, but without the strict syntax and semantics of a real programming language. Using pseudocode, you can explain how a program would work in plain English, instead of using a specified programming language. Pseudocodes are written in a way that anyone can understand, even if they don’t know how to code. Year 01 and Semester 01 15 / 39 Pseudocodes Year 01 and Semester 01 16 / 39 Pseudocode Year 01 and Semester 01 17 / 39 The Logical Constructs / Control structures Three basic constructs that controls the flow of an algorithm; Sequence Selection Iteration Sequence Control Structure Sequence is a linear progression where one task is performed sequentially after another. Solution steps must follow each other in a logical sequence Statements are executed in the same order as they are written. Year 01 and Semester 01 18 / 39 Exercise Write pseudocodes for the following problems: 1 Print “Hello world!” to the screen. 2 Find the summation of two integers input from the keyboard. Output the result to the screen. 3 Find the area of a circle when the radius is entered from the keyboard. Year 01 and Semester 01 19 / 39 Exercise Write pseudocodes for the following problems: 1 Print “Hello world!” to the screen. 2 Find the summation of two integers input from the keyboard. Output the result to the screen. Year 01 and Semester 01 20 / 39 1 Find the area of a circle when the radius is entered from the keyboard. Year 01 and Semester 01 21 / 39 Design - Test the solution Review the requirements and understand what the software is supposed to do. Perform the desk check – Use some known input values and check whether algorithm produce the desired output Do not rely on just one test case. Test the algorithm for all the possible cases Identifying errors and bugs at early stage will save the time Design - Fix the solution Read the problem definition again to identify missing points Refine the algorithm to accommodate the changes Perform the desk check again Repeat these steps until the desk check is passed Year 01 and Semester 01 22 / 39 Implement – Write and document the code Convert the algorithm description into implementation of programming language Ex. Java , C Programmers need to know the semantics and syntax of the selected programming language. Programmers write the code according to the design specifications, following coding standards and best practices. The code can be easily maintained by writing a documentation. Year 01 and Semester 01 23 / 39 Evolution of Programming languages Programming languages can be mainly divided into two categories. Low-level programming languages Machine Language Assembly Language High-level programming languages Year 01 and Semester 01 24 / 39 Machine Language Consist of 1 s and 0 s Machine dependent Computer can directly understand its own machine language Year 01 and Semester 01 25 / 39 Assembly Languages English-like abbreviations called mnemonics formed the basis Clearer to humans but incomprehensible to computers Need to translate to machine language using translator programs called assemblers Example : load salary add bonus store total Year 01 and Semester 01 26 / 39 High Level Programming Languages Instructions look almost like English and mathematical notations Substantial tasks can be accomplished from a single statement Easy for humans to understand Translator programs convert high-level programming languages into machine language C, C++, Python, Visual Basic and Java are some of the high level programming languages. Example: total = salary + bonus; Year 01 and Semester 01 27 / 39 Program Code Translation Translator Assemblers (convert assembly language programs to machine language) Compilers (convert high-level language programs to machine language) Interpreters (convert high-level language programs to machine language) Year 01 and Semester 01 28 / 39 Compiling Compilation is the process whereby the source code file is translated into machine code at once as a complete unit. If no syntax errors found in the source code, then machine code file is created for execution. With just one error the machine code file is not created. Interpreting Interpreting is the process whereby the source code file is translated line by line into machine code. If syntax errors exist, the program partially executes since the execution halts as soon as a syntax error is encountered. Year 01 and Semester 01 29 / 39 Traditional Methods : Compile → Execute Year 01 and Semester 01 30 / 39 History of Java The early 1990s, Sun Microsystems engineers (including James Gosling) wanted a new programming language. They designed Java to be simple, secure, and flexible. They wanted it to work on any computer, not just one kind. In 1995, Java was released to the public. By the late 1990s, Java became popular because it could run on different computers and was good for web development. In the 2000s, Java became widely used for big business applications, web apps, and even Android phone apps. Today, Java is still a popular choice for programmers, especially for large projects. Year 01 and Semester 01 31 / 39 How Java works... How Java becomes platform independent... Here’s the process: 1 Java source code: You write your program instructions in Java programming language. 2 Translation to bytecode: A java compiler translates your source code into a special machine code called bytecode. 3 Enter into the JVM: The bytecode goes into the JVM, a program on your computer that acts like a special translator machine. 4 Interpret the Bytecode: The JVM interprets the bytecode and turn it into native machine language code that your specific computer can follow. 5 Running the Program: The computer follows the native machine code running your Java program. Since JVM produces the native machine code, the same Java program can run on different computers as long as they have a JVM. This makes Java very versatile. Year 01 and Semester 01 32 / 39 Pseudocode to Java code Year 01 and Semester 01 33 / 39 Creating a JAVA program Analyze the given problem, design and write your algorithm first. (Pseudocode) A text file with the extension of.java must be created. This file stores the human readable java program. (Source code) The.java file / source code name must be the same as the class name. Ex. MyFirstProgram.java Year 01 and Semester 01 34 / 39 The Java compiler (known as javac) is used to compile the source code into the bytecode. The command : javac MyFirstProgram.java If the source code contains errors, they’re displayed, no bytecode created. If no errors, the bytecode is created as MyFirstProgram.class The Java interpreter (known as java) translate the bytecode and executes the resulting native machine code. The command: : java MyFirstProgram Year 01 and Semester 01 35 / 39 Java Architecture Year 01 and Semester 01 36 / 39 More examples Year 01 and Semester 01 37 / 39 Exercise 1 Write a pseudocode to display your name and your school. Convert it to a java program. 2 What is the output of the below pseudocode? MAIN DEFINE age AS INTEGER age = 18 PRINT age ENDMAIN 3 Convert the above pseudocode to a Java program. Year 01 and Semester 01 38 / 39 Thank You! Year 01 and Semester 01 39 / 39

Use Quizgecko on...
Browser
Browser