🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

WEEK TWO .pdf

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

Full Transcript

FUNDAMENTAL OF PROGRAMMING CC1O2 | CC1O2L COMPUTER PROGRAMMING Computer program instructions are also called program source code and computer programming is also called program coding. Binary is a series of 1's and 0 fed and interpreted by the computer. PROGRAMMING LANGUAGE Programmi...

FUNDAMENTAL OF PROGRAMMING CC1O2 | CC1O2L COMPUTER PROGRAMMING Computer program instructions are also called program source code and computer programming is also called program coding. Binary is a series of 1's and 0 fed and interpreted by the computer. PROGRAMMING LANGUAGE Programming languages serve as a middle-man of sorts. TYPES OF PROGRAMMING LANGUAGE Low-level Programming language High-level Programming language Low-Level Programming Language A low-level language, often known as a computer's native language, is a sort of programming language. It is very close to writing actual machine instructions, and it deals with a computer's hardware components and constraint. Types of Low-Level Languages Low level language are divided into two types. Machine Language Assembly Language (also called Mid Level Programming Languge) Machine Language This is the default computer language that is built in primitive instructions represented to the computer in binary code. Thus, if you want to instruct a computer, you must write in binary code. Assembly Language Assembly language is a low-level language that helps to communicate directly with computer hardware. It uses mnemonics to represent the operations that a processor has to do. Which is an intermediate language between high-level languages like C++ and the binary language. It uses hexadecimal and binary values, and it is readable by humans. MACHINE LANGUAGE ASSEMBLY LANGUAGE High Level Programming Language High-level languages are programming languages that are used for writing programs or software that can be understood by humans and computers. High-level languages are easier to understand for humans because they use a lot of symbols letters phrases to represent logic and instructions in a program. It contains a high level of abstraction compared to low- level languages. Languages like FORTRAN,C, C++, JAVA, Python, etc., are examples HIGH-LEVEL PROGRAMMING LANGUAGE Source: https://www.cs.mtsu.edu/~xyang/2170/computerLanguages TRANSLATORS We use translators to convert source code into binary language (Machine Language). The binary code translated then becomes what programmers refer to as ‘object code’. Translators can be: Assemblers Assemblers is used to translate the program written in Assembly language into machine code. The source program is an input of an assembler that contains assembly language instructions. COMPILER Compilers convert source code to binary code then execute the binary. If the program runs into an error during the execution process, the compilation stops without creating a binary. The most popular compiled languages are: C, C++, Objective C, Swift, and Pascal. HOW COMPILER WORKS? Interpreter Interpreter are similar to compilers but instead of running the entire program, they convert the code line by line (statement). This means that every line of code runs until an error occurs. Once the program returns an error, the interpreter automatically stops and reports the error. The most popular interpreted languages are: Python, Ruby, JavaScript and Pearl HOW INTERPRETER WORKS? Translators - Hybrid Hybrid translators are a combination of compilers and interpreters. They convert the source code into Bytecode. Runtime engines then translate and execute the bytecode. The main example here is Java that uses the Java Virtual Machine (JVM). Initial Compilation: The source code is Runtime Execution:The intermediate code is first compiled into an intermediate code, then interpreted or further compiled at runtime which is not machine code but a lower-level into machine code that the CPU can execute. code that is portable across different This allows for on-the-fly translation and systems. This step combines elements of execution, similar to interpretation. compilation..java.class Java Compiler Java source Code Java bytecode Pass bytecode to JVM Output JVM Java code is executed in JVM to produce result WHY IS THE LANGUAGE NAMED JAVA? HISTORY OF JAVA PROGRAMMING Created by James Gosling in the early 1990s The team initiated this project to develop a language for digital devices such as set-top boxes, television, etc. Originally C++ was considered to be used in the project but the idea was rejected for several reasons. Gosling endeavored to alter and expand C++ however before long surrendered that for making another stage called Green. James Gosling and his team called their project “Greentalk” and its file extension was.gt and later became to known as “OAK”. The name Oak was used by Gosling after an oak tree that remained outside his office. Later on, it rename as “JAVA” as it was already a trademark by Oak Technologies. Gosling and his team did a brainstorm session and after the session, they came up with several names such as JAVA, DNA, SILK, RUBY, etc The name Java originates from a sort of espresso bean, Java. Gosling came up with this name while having a coffee near his office. Java was created on the principles like Robust, Portable, Platform Independent, High Performance, Multithread, etc. and was called one of the Ten Best Products of 1995 by the TIME MAGAZINE. Java Programming Java is a general, all-purpose computer programming language that is circumstantial, class-based, object-oriented, and specially designed to have few application dependencies as possible. First public version, Java 1.0 was released in 1995 Oracle called this open JDK (Java Development Kit) As of June 2024, Java 22 is the latest released Java version. In September 2024, Java 23 will follow. Sun was acquired by the Oracle Corp. in 2010 (Steermanship for java) IMPORTANT TERMS IN THE CONTEXT OF JAVA PROGRAMMING JDK ( Java Development Kit) The Java Development Kit is a software package that includes everything needed for developing Java applications. It contains the Java Compiler, various development tools, libraries, and documentation. The JDK is required if you want to write, compile, and build Java programs. It includes the JRE as well, since you need the runtime environment to test your applications during development. JRE (Java Runtime Environment) The Java Runtime Environment is a software package that provides the necessary runtime components to run Java applications. It includes the Java Virtual Machine (JVM), along with libraries and other components required for executing Java programs. JRE is intended for users who want to run Java applications without necessarily developing them. In essence, it provides the environment in which Java code can be executed. JVM (Java Virtual Machine) The Java Virtual Machine is a crucial component of the Java platform. It's responsible for executing Java bytecode, which is the compiled form of Java source code. The JVM is platform independent, meaning that you can write Java code once and run it on any system with the appropriate JVM installed. It manages memory, handles garbage collection, and provides other runtime services necessary for Java applications to run efficiently In summary, the JRE provides the runtime environment to execute Java applications, the JVM executes Java bytecode and manages runtime operations, the JDK is used for developing Java applications and includes the compiler, the compiler translates human-readable Java source code into bytecode, and the JVM (partly) acts as an interpreter to execute bytecode efficiently. THE PROGRAM DEVELOPMENT PROCESS The Java compiler translates your Java program into a language called bytecode. This bytecode is not the machine language for any particular computer, but it is similar to the machine language of most common computers. The Java Virtual Machine JVM is an interpreter that translates and executes bytecode Java bytecode runs on any computer that has a JVM You normally will give two commands, one to compile your Java program into bytecode and one to run your program. PHASES OF PROGRAMMING WRITE COMPILE RUN The programmer write Java compiler takes java JVM executes the the code using Java as program as input and bytecode generated by programming language generate java bytecode compiler as output. ERRORS AND DEBUGGING Compiler and interpreter issue one or more error messages each time they encounter an invalid program statement that is, a statement containing a syntax error, or misuse of the language. The programmer can correct the error and attempt another translation by compiling or interpreting the program again. Locating and repairing all syntax errors is the first part of the process of debugging a program freeing the program of all errors illustrates the steps a programmer takes while developing an executable program. ERRORS AND DEBUGGING Programmers call some logical errors semantic errors. For example, if you misspell a programming language word, you commit a syntax error, but if you use a correct word in the wrong context, you commit a semantic error. Syntax errors are discovered when you compile a program, but often you can identify logical errors only when you examine a program’s first output INTEGRATED DEVELOPMENT ENVIRONMENT (IDE) A place to write, run and debug code and also convert it to machine code. IDE are like any other program on your computer except used for the facilitation of code. Examples: Netbeans, Eclipse, IntelliJ, visual studios, sublime etc.. Built in Error checking Auto fill for frequently used words. LABORATORY GETTING STARTED: INSTALLING JDK AND NETBEANS JDK Download link: https://www.oracle.com/ph/java/technologies/downloads/#jdk22-windows Click and Downloaded file and Install: Setting Java Path in Environmental Variable: Go to the file location and locate java > jdk-18.0.2.1 > bin and then copy the path Setting Java Path in Environmental Variable: Search for Edit system environment variables in your pc Setting Java Path in Environmental Variable: Click Environment Variables. Next, Select path and then edit Setting Java Path in Environmental Variable: Click new, paste the copied file path and then click OK Check if you have successfully install it on your computer: Open your Cmd (win + r) and type cmd When the dialog opens type this command: java –version thenhit enter. Installation of Netbeans: Click the downloaded file and run it. Click next and accept the Terms of Agreement https://netbeans.apache.org/front/main/download/ Click the downloaded file and run it. Click next and accept the Terms of Agreement Install Netbeans: Wait for the installation to finish and then click finish. Open the application ALGORITHM, PSEUDOCODE & FLOWCHART ALGORITHM A set of step-by-step instructions that describes how to perform a task. Step 1: Start Step 2: Declare variables num1, num2 and sum Step 3: Input values num1 and num2 Step 4: Add num1 and num2 and assign the result to sum using the formula (sum= num1 + num2) Step 5: Display sum Step 6: End PSEUDOCODE Begin A compact and informal high- level description of a program. Initialize num1, num2, sum It is a methodology that allows Read num1, num2 the programmer to represent the implementation of an Compute sum as sum=num1 + num2 algorithm Write sum End FLOWCHART A flowchart is a visual representation of the sequence of steps and decisions needed to perform a process. Each step in the sequence is noted within a diagram shape. Steps are linked by connecting lines and directional arrows. GUIDELINES IN FLOWCHART Flowchart starts with a Terminal Symbol Flowchart can have only one start and one stop symbol General flow of processes is top to bottom or left to right Symbols of flowchart must be connected with arrow Arrow should not cross each other EXAMPLE#1 Create a simple program that display “Hello World” ALGORITHM FLOWCHART Step 1: Start Step 2: Display “Hello World” Start Step 3: End Print “Hello World” PSEUDOCODE Begin Print “Hello World” End End EXAMPLE#2 Create a simple program that add three integers and display the sum. ALGORITHM Step 1: Start Step 2: Initialize variables num1, num2, num3, sum Step 3: Calculate the sum of three numbers (sum=num1 + num2 + num3) Step 4: Display result in “sum” Step 5: End EXAMPLE#2 Create a simple program that add three integers and display the sum. PSEUDOCODE Begin Initialize num1, num2, num3, sum Calculate sum= num1 + num2 + num3 Print sum End FLOWCHART Start Initialize num1 ,num2, num3 sum=num1+num2+num3 End Print Sum EXAMPLE#3 Create a simple converter that converts kilograms to grams where the user inputs a number. ALGORITHM Step 1: Start Step 2: Declare variables kilograms, grams Step 3: Input the value in kilograms Step 4: Convert the value from kilograms to grams by multiplying it by 1000 Step 5: Display result in grams Step 6: Stop EXAMPLE#2 Create a simple program that add three numbers entered by the user PSEUDOCODE Begin Declare variables kilograms, grams. Input value in kilograms Convert grams=kilograms*1000 Print grams End Start Declare variable kilograms FLOWCHART Input value in kilograms grams=kilograms*1000 Print grams End PERFORMANCE TASK #1 In one whole yellow paper, create a step-by-step procedure to solve a given problem (algorithm, pseudocode, and flowchart) 1. Write a program that display name, age and course that entered by the user. 2. Write a program that add three integers and calculate the average. 3. Write a program that converts Celsius to Fahrenheit where the user inputs a number 4. Write a program that add three integers entered by the user and then increment the sum by 5.

Use Quizgecko on...
Browser
Browser