Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

Chapter 1 - Introduction To Computers and Java - OL Academy

Uploaded by

Mother Amarath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Chapter 1 - Introduction To Computers and Java - OL Academy

Uploaded by

Mother Amarath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Last Updated : 14/09/2021

1.1 COMPUTER BASIC

Computer system can be divided into two parts:

part1 - Hardware :
is a physical components of a computer such as CPU, Memory, Monitor, Printer, keyboard
and mouse.

part2 : Software:
is a set of instructions for the computer to follow, we called as program, such as Operating
System, Applications, Programming Language.

Part1 - Hardware :
It has four main categories: Processor(CPU), input devices, output devices, and Memory (Stor-
age).

2
1 - The processor
Also called central processing unit (CPU) : It’s act as the brain of the devices for proces-
ing and executing instructions.

1 - Memory
Memory holds programs, data for the computer to process, and the result of the computer’s inter-
mediate calculations. we have two kinds of memory: main memory and auxiliary memory.

- Random Access Memory (RAM) :


RAM is the main memory in a computer, It is much faster to read from and write to than
other kinds of storage, It is used to store current working data, so they can be quickly reached by
the processor.

- RAM is volatile, that means data will disappears when you shut down your computer.

3
Auxiliary Memory (Secondary memory):
The data in auxiliary memory exists even when the computer’s power is off, It is like a
various storage media on which a computer can stored data and programs.

Examples of Auxiliary Memory:


• Hard disk drive (HDD)
• Solid State disk (SSD)
• CDs, DVDs, flash drives

Bits,Bytes and Addresses


• A bit is a digital with a value of either 0 or 1.
• A byte is a quantity of memory, and it’s the smallest addressable unit of memory.
• 1 byte contains 8 bits, The number of byte is called address.
• Each byte in main memory resides at a numbered location called its address.
• Both main memory and auxiliary memory are measured in bytes.
• all kinds of data encoded and stored using 1s and 0s.

4
5
Files
• It’s a large group of bytes in auxiliary memory (HDD or SSD).
• Files are organized into groups calles Folders, and each file have name.
• Java program are stored in files.
• We are copied Program files from auxiliary memory to main memory in order to be run.

Part2 - Software (program):


- Program is a set of instructions for a computer to follow.
- The input is the data needed by the program.
- The output (Result) produced by following the instructions in the program.

Operating System (OS):


- An operating system is a program that acts as an interface between computer user and computer
hardware, and controls the execution programs, such as Microsoft Windows, Apple Mac OS, Li-
nux.

6
Programming Languages:
- Java, C#, C++, Visual Basic, Python, Ruby are a high level languages.

- Computer hardware does not understand high level languages, can only deals with low level
langues, so must translate an program written with high level language to low level language.

- A compiler is a program that translates a program from a high level language to a low level
language.

- The Java compiler (javac) is a program that translates a java program into byte code.

- When a Java program is compiled, the byte code of the program has the same name, but end-
ing is changed from .java to .class.

- An interpreter is a program that alternates the translation and execution of satements in a pro-
gram written in a high level language. (translate each byte-code instruction into machine code)

- JVM (Java Virtual Machine) : translate the Java byte code to machine code.

- JIT (Just-In-Time) : Compiling bytecodes to native machine code at run time.

- Classes : pieces of code.

- class Loader: The bytecode of various classes connected together to run the program.

7
1.2 A SIP OF JAVA

We have two kinds of java programs: applications and applets.

Application: is just a regular program, meant to be run on your computer.

Applets: is a little application can be sent to another location on the internet and run there.

A First Java Application:


public class FirstProgram
{
public static void main(String[] args)
{
// Write your code here
System.out.println(“Welcome to OL Academy”);
}
}

Some Terminology:

Programmer: The person who writes a program.

User: The person who interacts with the program.

Variable: is something that can store a piece of data.

Statement : An instruction to the computer; it ends with a semicolon.

Syntax: The grammar rules for a programming language.

8
IDE (Integrated Development Enviroment ): Combines a text editor with commands for com-
piling and running Java programs.

Examples: IntelliJ IDEA, Eclipse, NetBeans, Visual Studio.

Printing to the Screen

System.out.println(“Whatever you want to print”);

• System.out is an object for sending output to the screen.


• println is a method to print whatever is in parentheses to the screen.

Compiling a Java Program or Class


• A Java program consists of one or more classes, which must be compiled before running the
program.
• Each class should be in a separate file.
• The name of the file should be the same as the name of the class.
• The Java program can involve any number of classes, but class to run must be contain the
main method somewhere in the file.

The main method:


public static void main(String[] args)
{

}
9
1.3 PROGRAMMING BASICS

Some basics and helpful techniques that experienced programmers have found, they apply to
almost any programming Language.

Object-Oriented Programming (OOP)


- OOP is a programming methodology that views a program as similary consisting of objects that
can act alone or interact with one another. Objects can perform actions which effect themselves
and other objects in the world.

- Treats a program as a collection of objects that interact by means of actions.

Three main design principles are:


• Encapsulation : information hiding.
• Polymorphism : many forms - allows the same progrm instruction to mean different things in
different contexts.
• Inheritance: is a way of organizing classes, The information is shared between classes, a
class at lower level inherits all the characteristics of classes above it in the hierarchy.

Algorithm: is a set of instructions for solving a problem.

Errors : An error in a program is called a bug.

debugging: Eliminating errors.

We have three kinds of errors:


Syntax errors: Grammatical mistakes. Ex: not write a semicolon at the end of statement.
Runtime errors: Error that are detected when your program is running. Ex: divide by 0
Logic errors: Errors which produce incorrect results. Ex: to calculate the hours of 1 week and
multiply number of days by 42 insted of 24.

10
Muliple Choice Questions:

1. This part of the computer fetches instructions, carries out the operations commanded by
the instructions, and produces some outcome or resultant information.
(A) Memory
(B) CPU
(C) secondary storage
(D) input device

2. Each byte in the memory is assigned a unique ___________.


(A) address
(B) CPU
(C) variable
(D) bit

3. Can hold data even when the computer’s power is off.


(A) RAM
(B) main memory
(C) Auxiliary memory
(D) CPU

4. How many bytes does 4 kilobytes represent?


(A) 512
(B) 1024
(C) 4096
(D) 8192

11
5- It is a set of instructions for a computer to follow.
(A) Hardware
(B) Input
(C) Output
(D) Program

6- Java is a ________ programming language.


(A) Low-level
(B) High-level
(C) machine
(D) None of these

7 . A ____________ translates high-level language into low-level language.


(A) programmer
(B) syntax detector
(C) compiler
(D) class loader

8. The input program to a compiler or interpreter is called _____________.


(A) Object code
(B) Byte code
(C) source code
(D) Assembly language code

9- ________ translates Java bytecode into machine language instructions.


(A) JVM
(B) programmer
(C) Compiler
(D) None of these

12
10- The file produced by the Java compiler contains _____________ that are executed by
the Java Virtual Machine.
(A) Bits
(B) Bytes
(C) Bytecode
(D) None of these

11- The information stored in _____________ typically is volatile, that means is disappears
when you shut down your computer.
(A) HDD
(B) SSD
(C) Main memory
(D) Auxiliary memory

12- The smallest addressable unit of memory.


(A) bit
(B) byte
(C) Migabyte
(D) Gigabyte

13- Which of the following is an output device?


(A) Keyboard
(B) Mouse
(C) Scanner
(D) Monitor

14- What unit of storage is used to represent 106 bytes?


(A) KB
(B) MB
(C) GB
(D) TB

13
15-Which type of program acts as an intermediary between a user of a computer and the
computer hardware?
(A) Operating system
(B) User thread
(C) Superuser thread
(D) Application program

16- RAM stands for:


(A) Remote Access Memory
(B) Random Access Memory
(C) Remote Access Memory
(D) Random Access Memory

16- One byte is equivalent to _____________.


(A) 4 bits
(B) 8 bits
(C) 6 bits
(D) 12 bits

17- The most basic circuitry-level computer language, which consists of 1 and 0, is _______.
(A) a high-level language
(B) machine language
(C) Java
(D) C++

18- A Java program is portable means it _____________.


(A) Can run on any machine
(B) Can write on any machine
(C) Can read from as well as write to any machine
(D) All of the above

14
19- Java programs can be executed in computer after
(A) converting them to bytecode
(B) converting them into machine code
(C) can be executed directly
(D) None of the above

20- The process of instructing the computer to solve a problem is called ___________.
(A) Compiling
(B) Programming
(C) Processing
(D) Controlling

21- When a Java program is compiled, the file produced by the compiler ends with the
________ file extension.
(A) .java
(B) .class
(C) .cpp
(D) .exe

22- ________ is a little application that is designed to be transmitted over the Internet and
run in a Web browser
(A) Application
(B) Applet
(C) Machine language
(D) Source code

23- _______ is not an Object-Oriented design principle


(A) Inheritance
(B) Encapsulation
(C) Ploymorphism
(D) Sequence
15
24- Inheritance means _____________.
(A) Many Java methods
(B) Information is put in one place with methods
(C) Information is shared between classes
(D) Write variable names correctly

25- Encapsulation means _____________.


(A) Methods with the same name but different functionality
(B) Information hiding
(C) Information is shared between classes
(D) Writing statements after each other

26- Polymorphism means _____________.


(A) Many forms
(B) Part of a class hidden and another is visible
(C) Information defined in one class can be used by another class
(D) Writing a Java program

27. An algorithm is _____________.


(A) a set of directions for solving a problem
(B) a source program
(C) a programming language
(D) a type of main memory

28. Pseudocode is
(A) used to write an algorithm
(B) a machine language
(C) used to generate a byte code
(D) used to test a program

16
29. A syntax error _____________.
(A) is a grammatical mistake in your program
(B) is the same as a logical error
(C) cannot be discovered
(D) cannot be corrected

30. Runtime errors are _____________.


(A) Grammatical mistakes in a program
(B) Errors that are detected during compilation
(C) Errors that are detected when your program is running, but not during compilation
(D) Errors that do not stop the program from running when they occur.

31. The rules of a programming language constitute its _____________.


(A) objects
(B) logic
(C) format
(D) syntax

32. An error in a program is called a _____________.


(A) mistake
(B) bug
(C) loophole
(D) virus

33. Reused components _____________.


(A) Are likely better tested piece of software, and more reliable than newly created soft-
ware
(B) Does not save time and money
(C) Should not be used to produce new programs.
(D) Are garbage collection data components

17

You might also like