What we’ll Learn Simple Programming Logic Program Development Cycle Integrated Development Environments(IDEs) Compilers and Interpreters Types of Errors Programming Paradigms Introduction to Java Principles of Good Programming
Compilers and Interpreters Programs that are written in a high-level language must be translated into machine language A compiler is a program that translates a high-level language program into a separate machine language program The machine language program can then be executed any time it is needed
Compilers and Interpreters An Interpreter is a program that both translates and executes the instructions in a high-level language program. As the interpreter reads each individual instruction in the program, it converts it to machine language instructions and then immediately executes them
Errors Syntax error a mistake such as a misspelled key word, a missing punctuation character, or the incorrect use of an operator. Logical error The logical error is an error that leads to an undesired output. These errors produce the incorrect output, but they are error-free, known as logical errors. Semantic error errors that occurred when the statements are not understandable by the compiler.
Compile Time vs Run-Time errors Compile-time Runtime The compile-time errors are the errors which are produced at the compile-time, and they are detected by the compiler. The runtime errors are the errors which are not generated by the compiler and produce an unpredictable result at the execution time. In this case, the compiler prevents the code from execution if it detects an error in the program. In this case, the compiler does not detect the error, so it cannot prevent the code from the execution. It contains the syntax and semantic errors such as missing semicolon at the end of the statement. It contains the errors such as division by zero, determining the square root of a negative number.
What does a programmer do? Understanding the problem, planning the logic, Coding the program, Translating the program into machine language, Testing the program, Putting the program into production, and Maintaining it.
Tools Used to Write Programs 1.Text Editor A text editor is a type of computer program that edits plain text Text editors are embedded in operating systems and software development packages, Used to change files such as configuration files, documentation files and used to write program source codes.
Integrated Development Environment A software application that provides comprehensive facilities to computer programmers for software development. IDEs present a single program in which all development is done. It provides many features for authoring, modifying, compiling, deploying and debugging software The package should contain at least: Source Code editor Compiler Build Automation Tools Debugger
Benefits of Using IDE Faster Set-Up Developers have the same set of capabilities in one place, without the need for constantly switching tools. Faster development tasks Tighter integration of all development tasks improves developer productivity Improves Organisation IDE’s tools and features helps developers organize resources, prevent mistakes and take shortcuts.
Programming Paradigms Procedural Programming Derived from structured programming, based upon the concept of calling procedure. e.g FORTRAN, ALGOL, COBOL, BASIC, Pascal and C. OOP Based upon the concept of objects. Objects contain data in the form of attributes and code in the form of methods. e.g Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl, Objective-C, Dart, Swift, Scala.
BASIS OF COMPARISON OBJECT ORIENTED PROGRAMMING (OOP) PROCEDURAL ORIENTED PROGRAMMING (POP) Division Of Program In object oriented programming, program is divided into parts referred to as objects . In procedural oriented programming, program is divided into small parts referred to as functions . Data Movement Objects can move and communicate with each other through member function. Data can move freely from function to function in the system. Importance Importance is given to the data rather than procedures or functions because it works as a real world . Importance is not given to data but to functions as well as sequence of actions to be done. Approach Object oriented programming follows Bottom Up approach. Procedural oriented programming follows Top Down approach.
BASIS OF COMPARISON OBJECT ORIENTED PROGRAMMING (OOP) PROCEDURAL ORIENTED PROGRAMMING (POP) Code Reusability The existing code in object oriented programming can be reused by the feature referred to as inheritance. There is no such feature in procedural oriented programming. Addition of New Data And Function In object oriented programming, adding new data and function is easy. Adding new data and function is not easy in procedural oriented programming. Problem Size It is suitable for solving big problems. It is not suitable for solving big problems. Data Access In object oriented programming, data cannot move easily from function to function, it can be kept public or private so we can control the access of data. In procedural oriented programming, most function uses global data for sharing that can be accessed freely from function to function in the system. Examples Examples of object oriented programming languages include: C++, Java, VB.NET, C#.NET and Python. C, VB, Fortran and Pascal are common examples of procedure oriented languages.
BASIS OF COMPARISON OBJECT ORIENTED PROGRAMMING (OOP) PROCEDURAL ORIENTED PROGRAMMING (POP) Virtual Classes Concept of virtual function appears during inheritance. No concept of virtual classes. Most Important Attribute Data is more important than function. Function is more important than data. Access Modes In Object oriented programming, there are three accessing modes “public”, “private”, “protected’’ that are used as an accessing share to access attributes or functions. In procedural oriented programming, there is no specific accessing mode to access attributes or functions in the program.
Introduction To Java James Gosling (a Canadian computer scientist), at Sun Labs, around 1992 Invented Java. Used to build visually interesting graphical user interface (GUI) and Web-based applications. Java is supported by many operating system, Java is cross-platformed OR platform independent.
Properties Of Java 1. JAVA IS A ROBUST LANGUAGE -The main features of java that makes it robust are garbage collection, Exception Handling and memory allocation. 2. JAVA IS SECURE - A lot of security futures are built into java that makes it secure. That is why several security flaws are almost impossible to exploit in Java (examples of such security flaws arestack corruption or buffer overflow). 3. MULTITHREADING -. Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilisation of CPU. 4. PORTABLE - “Write once, run anywhere” (WORA) is a slogan developed by Sun Microsystems to describe the ability of one Java program version to work correctly on multiple platforms.
Editions of Java Java Platform, Standard Edition (Java SE) is the Java platform for developing client- side applications, which run on desktops, and applets, which run in web browsers Java Platform, Enterprise Edition (Java EE) is the Java platform built on top of Java SE, which is used exclusively to develop enterprise-oriented server applications. Server- side applications include servlets, which are Java programs that are similar to applets but run on a server rather than a client Java Platform, Micro Edition (Java ME) is also built on top of Java SE. It is the Java platform for developing MIDlets , which are Java programs that run on mobile information devices, and Xlets , which are Java programs that run on embedded devices ( eg ATMs, printers, calculators, thermostats .....)
Java Program Execution -A Java bytecode is a machine instruction for a Java processor. A file of bytecodes is a machine language program for a Java processor. The javac program is a compiler (a translator) that translates the source program into a bytecode file called Hello.class .
Java Environment JDK: Java Development - Kit, The JDK is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler ( javac ), an archiver (jar), a documentation generator ( javadoc ) and other tools needed in Java development. JRE: Java Run-time Environment is an environment where Java applications only be ran and not developed (client system). It is part of the Java Development Kit (JDK), and provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files. JVM: Java Virtual Machine, is the environment responsible for the actual execution of a Java program
Principles of Good Programming DON’T REPEAT YOURSELF As soon as you start repeating yourself (e.g. a long expression, a series of statements, same concept) create a new abstraction. ABSTRACTION Each significant piece of functionality in a program should be implemented in just one place in the source code. AVOID REDUNDANCE You should try not to add functionality until you need it. SIMPLICITY Simple code takes less time to write, has fewer bugs and is easier to modify.
Principles of Good Programming EASILY READABLE The code should be easily read and understood with a minimum of effort required. Extension/Modification Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. In other words, do not write classes that people can modify. Write classes that people can extend. Code Re-Usability Reusing code improves code reliability and decreases development time. Avoid Premature Optimization Minimize Coupling All modules should be independent as far as possible”Maintainability Code Should be Maintainable