Basics of Computer Fundamentals PDF
Document Details
Uploaded by SpiritualGulf730
St. Peter Inter College
Tags
Summary
This document introduces the basic concepts of computer fundamentals, focusing on programming languages, specifically Java. It covers topics such as programs, programming languages, and object-oriented programming (OOP).
Full Transcript
# Basics of Computer Fundamentals ## Introduction A computer is a versatile machine capable of performing different tasks, from simple mathematical operations to complex ones, and from simple designs to multimedia animations. A computer cannot perform these functions on its own, but needs a set of...
# Basics of Computer Fundamentals ## Introduction A computer is a versatile machine capable of performing different tasks, from simple mathematical operations to complex ones, and from simple designs to multimedia animations. A computer cannot perform these functions on its own, but needs a set of instructions called **Programs**. These programs are translated into machine codes by a translator (interpreter or compiler). A program written in a human-readable form is known as the **Source Code**, whereas the program converted by the translator into a code that a computer understands, is known as the **Object Code**. The language used to write these instructions is called **Programming language**, and the person who creates these programs is known as a **Programmer**. Nowadays, different programming languages are available to develop programs for specific areas of application. ## Java and BlueJ In the modern era of networks and the internet, all applications being developed must have a global outlook. You need software that works anywhere on any platform and with other applications as well. **Java programming language** is a machine-independent language, meaning that a Java program written on one computer will run on any other computer even if the hardware configuration or the operating system is different. Java is also used as a language for creating internet-based applications. It creates small application modules, which can be embedded into web pages. These modules are called **Applets**, which enable a user to interact with the web pages. **BlueJ** is an Integrated Development Environment (IDE) used for beginners to write, edit, and execute Java programs. It allows students to write programs using an interactive visual environment, which gives them a good understanding of the programming concept. BlueJ includes: - an editor that you use to write your programs. - a debugger that helps you find your mistakes. - a viewer that you use to see the parts of your program. - an easy way to run Java programs. - an easy way to view documentation. BlueJ is a Java development environment that is developed and maintained by a joint research group at Deakin University, Melbourne, Australia, and the University of Kent in Canterbury, UK, explicitly as an environment for teaching introductory **Object-Oriented Programming**. ## Object-Oriented Programming (OOP) An **Object-Oriented Programming** language is a way of separating the program into a number of objects, i.e., self-contained application components that work together in order to complete a task. The basic concept of OOP is to create objects, reuse them throughout the program, and manipulate these objects to get results. The core concepts of OOP are discussed below: ### Objects Objects are real-world entities or items. They can be either non-living entities, such as pen, book, table, chair, car, scooter, calculator, phone, and computer, or living entities, like dog, cat, and plant, etc. Every individual can also be considered as an object. Real-world objects have two characteristics: - **State**: describes the properties of the object, i.e., brand name, model, color, price, etc. - **Behaviour**: describes what the object does (its function) - for example, a pen is used for writing. ### Class A class represents a group of objects of the same kind. A Class is like an object constructor, or a "blueprint" for creating objects. A class defines data and functions common to all objects of a certain kind. A class consists of two aspects: variables and functions. The variables form the state of an object, and the functions of a class use these variables to perform various operations. Thus, the functions form the behaviour of an object. Once a class is defined, you can create any number of objects belonging to that class that share the common state and behaviour. Hence, a class is known as a factory that produces similar objects. An object belonging to a particular class is called an instance of that class. ## Features of OOP The various features of the Object-Oriented Programming that make them different from other programming languages are: ### Abstraction Abstraction is a very important feature of Object-Oriented Programming. It is used to manage the complexity of a system; it provides only the essential features of the system to the user and hides all the complex processes. **ATM Example**: While using an ATM machine, you insert your debit or credit card in the provided slot, and follow the instructions that appear on the screen. After providing the correct PIN number and entering the desired amount, money is collected from the machine. In the above given example, only a user has the right to interact with the interface using the provided tools. He has no idea about the processes running in the background, and the functions interacting with each other. ### Encapsulation Encapsulation is the technique of binding both data and functions together to keep them safe from any unauthorized access and misuse. It ensures that a user cannot access the data without proper authorization. It also ensures that a user can have access only to those functions for which he is authorized, while other functions remain unaffected. **ATM Example**: Using the example of an ATM machine, data can be accessed by using the given function. However, the most important point to note is that while using an ATM you can only access the data that belongs to you. You cannot see the account balance of any other customer. ### Inheritance Inheritance is the feature using which an object in one class acquires the properties and behaviour of objects of another class. This means you can create new classes that are built upon existing classes and can reuse the methods and fields of the parent class. This property brings the concept of Object-Oriented Programming, a step closer to our lives, as it reflects the real-life concept of heredity in programming. Heredity is defined as the transfer of characteristics from parents to their children. **Bird Example**: A class of Birds can be broadly classified as 'Flying Birds' and 'Non-Flying Birds'. The principle behind this sort of classification is that each derived class shares the common characteristics with the class from which it is derived. ### Polymorphism The word Polymorphism means "many forms". Polymorphism helps the programmer to use the same function name for more than one purpose. **Mobile Phone Example**: A mobile phone has the polymorphic ability, meaning it can have one name, but many functions. ## Basic Concepts of a Programming Language The following are the basic concepts that you follow while writing programs in Java or BlueJ: ### Tokens The smallest element of a Java program is called a Token. These are the basic building blocks, which can be put together to construct programs. A token can be a reserved word (int or while), an identifier (sum or i), a constant (5 or 'KIPS'), punctuator ({ or ;), or an operator (+ or %). ### Identifiers An identifier is a name given to different components of a Java program. Identifiers are used to denote class name, method name, and variable name. These are defined by the Java programmer. **Rules for naming identifiers:** - An identifier may be composed of any combination of letters (A-Z) or (a-z), underscore (_), or dollar sign ($). - An identifier always starts with a letter or underscore. - An identifier should not be a keyword. - An identifier can be of any length. ### Keywords Keywords are the reserved words of a Java program with some special meaning, and can be used for that purpose only. The keywords cannot be used as identifiers, that is, variable name, class name, or method name. ### Constants Constants mean fixed values that do not change during the execution of a program. These values can be digits or character constants. For example, 12, -22.5, 7.5, "BlueJ", "KIPS". Constants are also referred to as Literals. - **Numeric Constants**: These values can be integer constants or real constants, such as 12, -5, 2334, -786 (integer constants), and 1.55, 0.756 (real constants). - **Character Constants**: These constants can be single character constant or string (multi-character) constants. A single character constant is enclosed in single quotes. For example, 'P', '4', 's', whereas, a string constant is a sequence of characters enclosed within double quotes. For example, "Kips", "Welcome to the World of Java", etc. ### Data Types Data types are defined as the data storage format that a variable can store to perform some specific operation. To utilise the maximum amount of memory, Java provides a large number of data types. The main data types in Java are as follows: | Data Type | Size | Description | |---|---|---| | **Integer** <br> int | 2 to 4 bytes (16 to 32 bits) | 34, 89, 78, -98, -76, etc.| | **Fractional** <br> float, double| 4 or 8 bytes (32 to 64 bits)| 45.89, -98.876, 88.2, etc.| | **Character** <br> char | 2 bytes (16 bits)| 'A', 'B', 'c', 'd', etc. <br> "Kips", "India", etc.| | **Boolean** <br> boolean | 1 bit| True, False| ### Variables A variable is a named location in the memory, which stores data temporarily. The data stored in the variables can change, or vary, during the program execution. A variable is assigned with a unique name. The name is a sequence of letters and digits, but the first character always starts with a letter or underscore. You cannot give any space in between the variable names. For example, totalCost, y2014, acc_bal, d_o_b, my_name, _my_name, etc. Each variable must be declared before it is used in a program. The variable declaration consists of two parts: the data type of the variable and the name of the variable.