Computer-Programming-Reviewer.pdf

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

Full Transcript

PROGRAMMING CONCEPTS: Logic ○ The systematic study of reasoning that provides standards by which valid reading can be recognized Programming ○ Computer process data under the control set of instruction Programmer ○ Computer program guide the computer th...

PROGRAMMING CONCEPTS: Logic ○ The systematic study of reasoning that provides standards by which valid reading can be recognized Programming ○ Computer process data under the control set of instruction Programmer ○ Computer program guide the computer through orderly sets of actions by people. Programming Language ○ A set of rules that provides a way of telling a computer what operation to perform FIVE (5) BASIC PROGRAMMING ELEMENTS Input ○ getting data and commands into the computer Output ○ getting your results out of the computer Arithmetic ○ performing mathematical calculations on your data Conditional ○ testing to see if a condition is true or false Looping ○ cycling through a set of instructions until some condition is met PROGRAMMING CYCLE The computer is basically a problem-solving tool. Once it is properly provided with a valid program, the computer becomes self-operational, that is, it requires no human intervention during processing. To use this tool effectively, the programmer usually has to perform the following set of well defined steps. 1. Defining the Problem a. One of making sure what has to be done or what problem has to be solved. A careful analysis of that need should involve both prospective users of the information and one or more trained systems designers or programmers, who can perceive b. The full nature of the information need and how the computer can be used to respond to it 2. Planning the Solution a. This is the next step, after the problem has been defined, select the best method for solving the problem. This commonly involves determining the sequence of processing steps within individual programs b. To save on time and effort, the programmer refers to a pictorial representation, the program flow chart c. The flow chart is an all-purpose tool and a program blueprint. The programmer constructs the flow chart to lay out the Program logic 3. Coding the Solution a. Once the programmer is satisfied that all processing steps have been identified and all alternatives and exceptions provided for, the program is then made b. The program flow chart serves as a guide in coding 4. Checking out the program a. Experience will prove that a program seldom executes successfully the first time b. Even the simplest programs contain errors, and even experienced programmers make mistakes 5. Documentation a. After a program has been fully tested and implemented, the programmer must write up the full specifications for all users i. The technical documentation package should include: 1. Complete statement of the problem 2. Description of the program logic and copies flow charts 3. Final source listing 4. List and description or error tests along with the disposition of these errors. 5. Operating instructions, including program and data structures and test data used. 6. Input and output specifications. 7. Schedules to be maintained. Flowchart Symbols Flowchart is a diagram which visually presents the flow of data through processing systems. This means by seeing a flow chart one can know the operations performed and the sequence of these operations in a system. Algorithms are nothing but a sequence of steps for solving problems. So a flow chart can be used for representing an algorithm A flowchart, will describe the operations (and in what sequence) are required to solve a given problem. You can see a flow chart as a blueprint of a design you have made for solving a problem Flowchart using Loops or Iteration Looping ○ is used when it is desired to make the same calculation on more than one set of data ○ it consists of repeating a program, or a section of a program, and substituting new data for each repetition Counters ○ is set up in a program loop to keep track of the number of times the program segment is repeated ○ the program can then be terminated after the completion of a predetermined number of passes Flowchart – Steps in Control Loop Initialization ○ the value of a counter used is initially set equal to zero ( or one ). This process is always done outside the loop Test for Limit Conditions ○ before logic flows gets ○ out of a loop, a loop-terminating condition must first be satisfied. The process of testing is usually found either at the beginning or at the end of a loop Incrementation ○ After each loop is executed, 1 is added to the counter. Thus the counter reflects the number of times the operation has been performed. Note that process of incrementation is always done within the loop Introduction to Java Java is a programming language and a platform. Java is a high level, robust, object-oriented and secure programming language Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, so James Gosling and his team changed the name from Oak to Java Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has a runtime environment (JRE) and API, it is called a platform The history of Java is very interesting. Java was originally designed for interactive television, but it was too advanced technology for the digital cable television industry at the time Currently, Java is used in internet programming, mobile devices, games, e-business solutions, etc. Following are given significant points that describe the history of Java James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. The small team of sun engineers called Green Team Initially it was designed for small, embedded systems in electronic appliances like set-top boxes Firstly, it was called "Greentalk" by James Gosling, and the file extension was.gt After that, it was called Oak and was developed as a part of the Green project Why Oak? Oak is a symbol of strength and chosen as a national tree of many countries like the U.S.A., France, Germany, Romania, etc In 1995, Oak was renamed as "Java" because it was already a trademark by Oak Technologies Why had they chosen the name Java for Java language? The team gathered to choose a new name. The suggested words were "dynamic", "revolutionary", "Silk", "jolt", "DNA", etc Java is an island in Indonesia where the first coffee was produced (called Java coffee). It is a kind of espresso bean. Java name was chosen by James Gosling while having a cup of coffee nearby his office Notice that Java is just a name, not an acronym Initially developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995. In 1995, Time magazine called Java one of the Ten Best Products of 1995 JDK 1.0 was released on January 23, 1996. After the first release of Java, there have been many additional features added to the language. Now Java is being used in Windows applications, Web applications, enterprise applications, mobile applications, cards, etc. Each new version adds new features in Java Recent version of JAVA is Java SE 18 Since Java SE 8 release, the Oracle corporation follows a pattern in which every even version is released in March month and an odd version released in September month. FEATURES OF JAVA The primary objective of Java programming language creation was to make it portable, simple and secure programming language The features of Java are also known as Java buzzwords The principles for creating Java programming were: "Simple, Robust, Portable, Platform-independent, Secured, High Performance, Multithreaded, Architecture Neutral, Object-Oriented, Interpreted, and Dynamic" Simple Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to Sun Microsystem, Java language is a simple programming language because: ○ Java syntax is based on C++ (so easier for programmers to learn it after C++) ○ Java has removed many complicated and rarely-used features, for example, explicit pointers, operator overloading, etc ○ There is no need to remove unreferenced objects because there is an Automatic Garbage Collection in Java Object-oriented Java is an object-oriented programming language. Everything in Java is an object. Object-oriented means we organize our software as a combination of different types of objects that incorporate both data and behavior Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules Basic concepts of OOPs are: ○ Object ○ Class ○ Inheritance ○ Polymorphism ○ Abstraction ○ Encapsulation Platform Independent Java is platform independent because it is different from other languages like C, C++, etc. which are compiled into platform specific machines while Java is a write once, run anywhere language The Java platform differs from most other platforms in the sense that it is a software-based platform that runs on top of other hardware-based platforms. It has two components: ○ JRE (Java Runtime Environment) ○ API (Application Programming Interface) Java code can be executed on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/OS, etc. Java code is compiled by the compiler and converted into bytecode This bytecode is a platform-independent code because it can be run on multiple platforms, i.e., Write Once and Run Anywhere (WORA) Secured Java is best known for its security. With Java, we can develop virus-free systems. Java is secured because: ○ No explicit pointer ○ Java Programs run inside a virtual machine sandbox Class Loader: ○ Class loader in Java is a part of the Java Runtime Environment (JRE) which is used to load Java classes into the Java Virtual Machine dynamically. It adds security by separating the package for the classes of the local file system from those that are imported from network sources Bytecode Verifier: ○ It checks the code fragments for illegal code that can violate access rights to objects Security Manager: ○ It determines what resources a class can access such as reading and writing to the local disk Robust The English meaning of Robust is strong. Java is robust because: ○ It uses strong memory management ○ There is a lack of pointers that avoids security problems Architecture-neutral Java is architecture neutral because there are no implementation dependent features, for example, the size of primitive types is fixed Portable Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't require any implementation High-performance Java is faster than other traditional interpreted programming languages because Java bytecode is "close" to native code. It is still a little bit slower than a compiled language (e.g., C++). Java is an interpreted language that is why it is slower than compiled languages, e.g., C, C++, etc Distributed Java is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are used for creating distributed applications. This feature of Java makes us able to access files by calling the methods from any machine on the internet Multi-threaded A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads Dynamic Java is a dynamic language. It supports the dynamic loading of classes. It means classes are loaded on demand. It also supports functions from its native languages, i.e., C and C++ PHASES OF JAVA The first step in creating a Java program is by writing your programs in a text editor. Examples of text editors you can use are notepad, vi, emacs, etc. This file is stored in a disk file with the extension.java After creating and saving your Java program, compile the program by using the Java Compiler. The output of this process is a file of Java bytecodes with the file extension.class The.class file is then interpreted by the Java interpreter that converts the bytecodes into the machine language of the particular computer you are using INTEGRATED DEVELOPMENT ENVIRONMENT (IDE) An IDE is a programming environment integrated into a software application that provides a GUI builder, a text or code editor, a compiler and/or interpreter and a debugger Top 10 Best Java IDEs ○ Intellij IDEA ○ Eclipse IDE ○ Apache NetBeans ○ Android Studio ○ AIDE Android IDE ○ Codenvy ○ BlueJ ○ GreenFoot ○ DrJava ○ JCreator JAVA CODES class Simple{ public static void main(String args[]) { System.out.println("Hello World"); } } Save the above file as Simple.java. To compile: javac Simple.java To execute: java Simple Compilation Flow When we compile Java program using javac tool, the Java compiler converts the source code into byte code From Java Code (Simpple.java) to Compiler to Bytecode(Simple.class) Parameters used in First Java Program class keyword is used to declare a class in Java. public keyword is an access modifier that represents visibility. It means it is visible to all. static is a keyword. If we declare any method as static, it is known as the static method. The core advantage of the static method is that there is no need to create an object to invoke the static method void is the return type of the method. It means it doesn't return any value. main represents the starting point of the program. String[] args or String args[] is used for command line arguments. System.out.println() is used to print statements. Here, System is a class, out is an object of the PrintStream class, println() is a method of the PrintStream class JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn't physically exist. It is a specification that provides a runtime environment in which Java bytecode can be executed It can also run those programs which are written in other languages and compiled to Java bytecode JVMs are available for many hardware and software platforms. JVM, JRE, and JDK are platform dependent because the configuration of each OS is different from each other. However, Java is platform independent. There are three notions of the JVM: specification, implementation, and instance The JVM performs the following main tasks: Loads code Verifies code Executes code Provides runtime environment JRE (Java Runtime Environment) It is also written as Java RTE. The Java Runtime Environment is a set of software tools which are used for developing Java applications. It is used to provide the runtime environment. It is the implementation of JVM. It physically exists. It contains a set of libraries + other files that JVM uses at runtime The implementation of JVM is also actively released by other companies besides Sun Micro Systems JDK (Java Development Kit) The Java Development Kit (JDK) is a software development environment which is used to develop Java applications and applets. It physically exists. It contains JRE + development tools JDK is an implementation of any one of the below given Java Platforms released by Oracle Corporation: ○ Standard Edition Java Platform ○ Enterprise Edition Java Platform ○ Micro Edition Java Platform JAVA COMMENTS Comments are notes written to a code for documentation purposes. Those text are not part of the program and do not affect the flow of the program. Java supports three types of comments: ○ C++-Style Comments starts with //. All the text after // are treated as comments. For example: // This is a C++ style or single line comments ○ C-Style Comments also called multiline comments starts with a. All text in between the two delimiters are treated as comments. Unlike C++ style comments, it can span multiple lines For example: Comments are notes written to a code for documentation purposes. Those text are not part of the program and does not affect the flow of the program. Java supports three types of comments: ○ Special Javadoc Comments Special Javadoc comments are used for generating HTML documentation for your Java programs. You can create javadoc comments by starting the line with. Like C-style comments, it can also span lines. It can also contain certain tags to add more information to your comments For example: ○ JAVA STATEMENTS AND BLOCKS A statement is one or more lines of code terminated by a semicolon. ○ An example of a single statement is, System.out.println(“Hello world”); A block is one or more statements bounded by an opening and closing curly braces that groups the statements as one unit. Block statements can be nested indefinitely. Any amount of white space is allowed. ○ Example: public static void main( String[] args ) { System.out.println("Hello"); System.out.println("world"); } JAVA IDENTIFIERS Identifiers are tokens that represent names of variables, methods, classes, etc ○ Examples: Hello, main, System, out Java identifiers are case-sensitive ○ This means that the identifier: Hello is not the same as hello. ○ Identifiers must begin with either a letter, an underscore “_”, or a dollar sign “$” ○ Letters may be lower or upper case. Subsequent characters may use numbers 0 to 9 ○ Identifiers cannot use Java keywords like class, public, void, etc JAVA KEYWORDS Keywords are predefined identifiers reserved by Java for a specific purpose. You cannot use keywords as names for your variables, classes, methods …etc List of Java Keywords: JAVA LITERALS Literals are tokens that do not change or are constant. The different types of literals in Java are: ○ Integer Literals - Integer literals come in different formats: decimal (base 10), hexadecimal (base 16), and octal (base 8). ○ Floating-Point Literals - Floating point literals represent decimals with fractional parts. An example is 3.1416. Floating point literals can be expressed in standard or scientific notations ○ Boolean Literals - Boolean literals have only two values, true or false ○ Character Literals - Character Literals represent single Unicode characters. A Unicode character is a 16-bit character set that replaces the 8-bit ASCII character set ○ String Literals - String literals represent multiple characters and are enclosed by double quotes. An example of a string literal is, “Hello World” DATA TYPES Data types specify the different sizes and values that can be stored in the variable. There are two types of data types in Java: ○ Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double ○ Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays VARIABLES A variable is an item of data used to store state of objects. A variable has a data type and a name. The data type indicates the type of value that the variable can hold. The variable name must follow rules for identifiers DATA TYPES & VARIABLES Types of Variable Local Variable ○ A variable declared inside the body of the method is called a local variable. You can use this variable only within that method and the other methods in the class aren't even aware that the variable exists. A local variable cannot be defined with "static" keyword Instance Variable ○ A variable declared inside the class but outside the body of the method, is called an instance variable. It is not declared as static. It is called an instance variable because its value is instance-specific and is not shared among instances Static variable ○ A variable that is declared as static is called a static variable. It cannot be local. You can create a single copy of the static variable and share it among all the instances of the class. Memory allocation for static variables happens only once when the class is loaded in the memory

Use Quizgecko on...
Browser
Browser