You are on page 1of 52

Unit 1: Introduction to Computer

and Java
Assist.Prof. S.B.Mehta
Computer Science and Engineer

Presented by : Prof. S.B.Mehta


Computer Hardware and Software
Every computer is composed of two basic components: hardware and
software.
Hardware refers to the physical elements of a computer. Computer
hardware consists of interconnected electronic devices that we can use to
control computer’s operation, input and output. Examples: of hardware in a
computer are the Processor, Memory Devices, Monitor, Printer, Keyboard,
Mouse, and the Central Processing Unit.

Presented by : Prof. S.B.Mehta


Computer Software
Software is a collection of instructions, procedures, documentation that performs
different tasks on a computer system. we can say also Computer Software is a
programming code executed on a computer processor.
Software instructions are programmed in a computer language, translated into
machine language, and executed by computer.
Software can be categorized into two types −
1. System software
2. Application software
System Software
System software operates directly on hardware devices of computer. It provides a
platform to run an application. It provides and supports user functionality.
Examples : of system software include operating systems such as Windows,
Linux, Unix, etc.

Application Software
An application software is designed for benefit of users to perform one or more
tasks. Examples : of application software include Microsoft Word, Excel,
PowerPoint, Oracle, etc.

Presented by : Prof. S.B.Mehta


Difference between Hardware & Software
Hardware Software

Hardware is a physical parts computer that cause Software is a set of instruction that tells a computer
processing of data. exactly what to do.

t is manufactured. It is developed and engineered.

Hardware can not perform any task without software. software can not be executed without hardware.

As Hardware are physical electronic devices, we can We can see and also use the software but can’t actually
see and touch hardware. touch them.

It has four main categories: input device, output It is mainly divided into System software,
devices, storage, and internal components. Programming software and Application software.

Hardware is not affected by computer viruses. Software is affected by computer viruses.

It can not be transferred from one place to another


But, it can be transferred.
electrically through network.

If software is damaged, its backup copy can be


If hardware is damaged, it is replaced with new one.
reinstalled.

Ex: Keyboard, Mouse, Monitor, Printer, CPU, Hard Ex: Ms Word, Excel, Power Point, Photoshop, MySQL
disk, RAM, ROM etc. etc.

Presented by : Prof. S.B.Mehta


Operating System
An Operating System (OS) is an interface between a computer user and computer
hardware. An operating system is a software which performs all the basic tasks like file
management, memory management, process management, handling input and output,
and controlling peripheral devices such as disk drives and printers.

Presented by : Prof. S.B.Mehta


Memory Concept
It is used to store data and instructions. Computer memory is the storage space in the
computer, where data is to be processed and instructions required for processing are
stored.
The memory is divided into large number of small parts called cells. Each location or
cell has a unique address, which varies from zero to memory size minus one. For
example, if the computer has 64k words, then this memory unit has 64 * 1024 = 65536
memory locations. The address of these locations varies from 0 to 65535.

The memory of the computer is divided into two categories:


1. Primary Memory
2. Secondary Memory

Presented by : Prof. S.B.Mehta


Memory Concept Conti…
Primary Memory: This is the main memory of the computer. CPU can directly read or
write on this memory. It is fixed on the motherboard of the computer.
• Primary memory is further divided in two types:
1.RAM(Random Access Memory)
2.ROM(Read Only Memory)

Secondary Memory:
This memory is permanent in nature. It is used to store the different programs and the
information permanently (which were temporarily stored in RAM). It holds the
information till we erase it.
Different types of secondary storage devices are:
Hard Disc, Compact Disc, DVD, Pen Drive, Flash Drive, etc.

Presented by : Prof. S.B.Mehta


Memory Unit
Memory unit is the amount of data that can be stored in the storage unit. This storage
capacity is expressed in terms of Bytes.

S.No. Unit & Description


Bit (Binary Digit)
1 A binary digit is logical 0 and 1 representing a passive or an active state of a
component in an electric circuit.
Nibble
2
A group of 4 bits is called nibble.
Byte
3 A group of 8 bits is called byte. A byte is the smallest unit, which can
represent a data item or a character.
Word
A computer word, like a byte, is a group of fixed number of bits processed as
a unit, which varies from computer to computer but is fixed for each
4 computer.
The length of a computer word is called word-size or word length. It may be
as small as 8 bits or may be as long as 96 bits. A computer stores the
information in the form of computer words.

Presented by : Prof. S.B.Mehta


Memory Unit Conti..
The following table lists some higher storage units −

S.No. Unit & Description


Kilobyte (KB)
1
1 KB = 1024 Bytes
Megabyte (MB)
2
1 MB = 1024 KB
GigaByte (GB)
3
1 GB = 1024 MB
TeraByte (TB)
4
1 TB = 1024 GB
PetaByte (PB)
5
1 PB = 1024 TB

Presented by : Prof. S.B.Mehta


Data Hierarchy Computer Organization…
• Data Hierarchy refers to the systematic organization of data, often in
a hierarchical form. Data organization involves fields, records, files and so on.
• Different Level of Data Hierarchy

Presented by : Prof. S.B.Mehta


Programming Language
• The languages that are used to write a program or set of instructions are
called "Programming languages".
• Computer programming languages are used to to communicate
instructions to a computer. They are based on certain syntactic and
semantic rules, which define the meaning of each of the programming
language constructs.
• Programmers use different programming language to develop software
for different purposes
• Eg.
1.Scientific Application(Calculators)
2.Entertainment(Games)
3.Multimedia Application(Music Player)
4.Business Solution(Inventory Control System)
5.Web Development(Web sites) etc.

Presented by : Prof. S.B.Mehta


Type of Programming Language
There are basically two types of computer programming languages given
below:

1. Low Level Language


a) Machine Language
b) Assembly Language

2. High Level Language


a) Procedure Oriented Language
b) Object Oriented Language

Presented by : Prof. S.B.Mehta


Low Level Language
• The programming languages that are very close to machine code (0s and 1s) are
called low-level programming languages".
• The program instructions written in these languages are in binary form.
• It is Machine dependent
• Not portable
• It is difficult to understand by human/user
• It require deep understanding of Computer Architecture to write program in it.

The examples of low-level languages are:


✓ Machine language
✓ Assembly language

Presented by : Prof. S.B.Mehta


Machine Language
• It is also called as binary language or 0,1 language .
• It is native language of computers
• It is Machine dependent
• Not portable
• It is difficult to understand by human/user
• It is difficult to write program in it.
• Machine language does not require any language translator .
• It is directly executed by computers.
• Program written in Machine language is called Object Code .

Presented by : Prof. S.B.Mehta


Assembly Language
• Assembly language is a middle-level language (second generation programming
language)
• It consists of a set of instructions in a specific format called commands
• It is also called as symbolic language.
• It is abstraction of Machine language.
• Instructions consist of Mnemonics.
• The computer should have Assembler to translate assembly level program to
machine level program.

Presented by : Prof. S.B.Mehta


High Level Language
• The high level language is simple and easy to understand and it is similar to English
language.
• User Friendly
• Well defined way of writing program
• Easy to write and debug
• Not directly executed on computers
• Requires Translators
• Machine Independent
• For example, COBOL, FORTRAN, BASIC, C, C+, Python, etc.
• Eg. if age < 18 { printf("You are not eligible to vote"); } else{ printf("You are
eligible to vote"); }

The high level programming languages are further divided into:


1. Procedural oriented languages
2. Object oriented programming languages

Presented by : Prof. S.B.Mehta


Procedural oriented Language
• Procedural languages are also known as third generation languages (3GLs). In a
procedural language,
• Program is designed using procedures.
• In procedural programming languages, the program instructions are written in a
sequence or in a
• specific order in which they must be executed to solve a specific problem
• For example, COBOL, FORTRAN, Pascal, ADA, C language etc.

Presented by : Prof. S.B.Mehta


Object oriented Language
• In object oriented programming, the software is developed by using a set of
interfacing object.
• An object is a component of program that has a set of modules and data structure.
• The modules are also called methods and are used to access the data from the object.
• Example: C++, Java, Python, C#, smalltalk etc.

Presented by : Prof. S.B.Mehta


Difference between Procedure & Object Oriented Programming

Procedure Oriented Programming Object Oriented Programming

In procedural programming, program is divided into In object oriented programming, program is divided
small parts called functions. into small parts called objects.

Object oriented programming follows bottom up


Procedural programming follows top down approach.
approach.

There is no access specifier in procedural Object oriented programming have access specifier
programming. like private, public, protected etc.

Adding new data and function is not easy. Adding new data and function is easy.

Procedural programming does not have any proper Object oriented programming provides data hiding so
way for hiding data so it is less secure. it is more secure.

In procedural programming overloading is not Overloading is possible in object oriented


possible. programming.

In procedural programming function is more important In object oriented programming,data is more important
than data. than Function

Procedural programming is based on unreal world. Object oriented programming is based on real world.

Examples: C, FORTRAN, Pascal, Basic etc Examples: C++, Java, Python, C#, smalltalk etc.
Presented by : Prof. S.B.Mehta
Object oriented Technology

Presented by : Prof. S.B.Mehta


Features of OOP
• It emphasis more on data rather than procedure.
• The programs are divided into objects thus making it easy to work with.
• Data structures are designed in such a way that they characterize the objects.
• Functions that work on the data of an object are placed together in the data structure.
• Data is hidden and cannot be accessed by external functions without permission.
• Communication between objects can take place with the help of functions.
• Adding new data and functions has become easy.
• Follows the bottom-up approach in program design.

Presented by : Prof. S.B.Mehta


Introduction to Java
• Java is an object-oriented programming language with its runtime environment. It is a
combination of features of C and C++ with some essential additional concepts.
• JAVA was developed by Sun Microsystems in the year 1991.It was developed by
James Gosling and Patrick Naughton and his team.
• The first publicly available version of Java (Java 1.0) was released in 1995. Sun
Microsystems was acquired by the Oracle Corporation in 2010.
• This language was initially called ‘OAK’.
• “James Gosling “ with his team started developing this language and name is changed
to “JAVA”.
• Initially designed for small, embedded system in electronic appliances like set-top
boxes. Java is used in mobile devices, internet programming, games, e-business, etc.
• The principles for creating java were simple, robust, secured, high performance,
portable, multi-threaded, interpreted, dynamic, etc.
• Java code that runs on one platform does not need to be recompiled to run on another
platform; it's called write once, run anywhere(WORA).

Presented by : Prof. S.B.Mehta


Java Version History
• JDK Alpha and Beta (1995)
• JDK 1.0 (January 23, 1996)
• JDK 1.1 (February 19, 1997)
• J2SE 1.2 (December 8, 1998)
• J2SE 1.3 (May 8, 2000)
• J2SE 1.4 (February 6, 2002)
• J2SE 5.0 (September 30, 2004)
• Java SE 6 (December 11, 2006)
• Java SE 7 (July 28, 2011)
• Java SE 8 (March 18, 2014)
• Java SE 9 (21st Sep 2017)
• Java SE 10 (20th March 2018)

J2SE: Java 2 standard edition (used for developing desktop applications)


J2EE : Java 2 enterprise edition for applications (used for applications which run on
servers, for example web sites)
JDK: Software development environment used for developing Java applications and
applets.
Presented by : Prof. S.B.Mehta
Type of Java Application
1. Web Application - Java is used to create server-side web applications. Currently,
Servlet, JSP, Struts, JSF, etc. technologies are used.
2. Standalone Application - It is also known as the desktop application or window-
based application. An application that we need to install on every machine or server
such as media player, antivirus, etc. AWT and Swing are used in java for creating
standalone applications.
3. Enterprise Application - An application that is distributed in nature, such as banking
applications, etc. It has the advantage of high-level security, load balancing, and
clustering. In Java, EJB is used for creating enterprise applications.
4. Mobile Application - Java is used to create application software for mobile devices.
Currently, Java ME is used for building applications for small devices, and also Java
is a programming language for Google Android application development.

Presented by : Prof. S.B.Mehta


Difference between Java and C
SR.N JAVA C
O
1 Java is object oriented language C is procedure oriented
and to define classes and object programming language
2 Java does not contains the data C support the user define data
type’s struct and union types struct and union

3 Java does not support pointer C support concept of pointer


4 Java does not support C support the preprocessor like
preprocessor like #define , #define , #include so on
#include so on
5 Java does not define the type C support the type modifiers
modifiers keywords keywords auto,extern,register,
auto,extern,register, singed and singed and unsigned
unsigned

Presented by : Prof. S.B.Mehta


Difference between Java and C++
SR.N JAVA C++
O
1 Java is true object oriented C++ is procedure oriented
language programming language(C)
and Object oriented language
2 Java does not support C++ support operator
operator overloading overloading
3 Java does not support pointer C++ support concept of
pointer
4 Java does not support C++ support the preprocessor
preprocessor like #define , like #define , #include so on
#include so on
5 Java does not have template C++ has template classes
classes

Presented by : Prof. S.B.Mehta


Difference between Java and C++ Conti…
SR.NO JAVA C++
6 Multiple inheritance of classes is not C++ support Multiple
supported in java. Interface is used to inheritance of classes
implement it.

7 Java does not support Global C++ support global variables.


Variables. Every variable and method
is declared within a class and forms
part of that class
8 Java does not support pointer C++ support concept of pointer
9 Java replace the destructor function C++ has the destructor
with a finalize() function function.
10 There are no header files in java C++ includes header files in
program.

Presented by : Prof. S.B.Mehta


Java Components
• Bytecode : It is Highly optimize set of instruction excuted at run time
• Java Virtual Machine
• Java Development Kit

Presented by : Prof. S.B.Mehta


Java Virtual Machine(JVM)

Presented by : Prof. S.B.Mehta


Java Run Time (JRE)
• 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.

Presented by : Prof. S.B.Mehta


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.

Presented by : Prof. S.B.Mehta


Features of Java
• Compiler and Interpreted
• Java is Platform independent and Portable.
• Object Oriented
• Robust and Secure
• Distributed
• Familiar,Simple and Small
• Distributed
• Multithreaded and interactive
• High Performance

Presented by : Prof. S.B.Mehta


Java Development Kit conti..
• javac(Java Compiler)
e.g c:\javac filename.java
• java(Java Interpreter)
e.g. c:\java filename
• appletviewer(for viewing java applets)
• javap(java disassembler)
• javah(for c-header files)
• javadoc(for creating HTML documents)
• jdb(Java debugger)

Presented by : Prof. S.B.Mehta


Popular Java Editors
• Notepad - On Windows machine, you can use any simple
text editor like Notepad (Recommended for this tutorial),
TextPad.
• Netbeans - is a Java IDE that is open source and free which
can be downloaded from http://www.netbeans.org/index.html
• Eclipse - is also a java IDE developed by the Eclipse open
source community and can be downloaded
from http://www.eclipse.org/

Presented by : Prof. S.B.Mehta


Popular Java Editors
• Notepad - On Windows machine, you can use any simple
text editor like Notepad (Recommended for this tutorial),
TextPad.
• Netbeans - is a Java IDE that is open source and free which
can be downloaded from http://www.netbeans.org/index.html
• Eclipse - is also a java IDE developed by the Eclipse open
source community and can be downloaded
from http://www.eclipse.org/

Presented by : Prof. S.B.Mehta


Data Type in Java

Presented by : Prof. S.B.Mehta


Data Type in Java
Integer Type:

TYPE SIZE MINIMUM VALUE MAXIMUM VALUE


byte 1 byte -128 127
short 2 byte -31,768 32,767
int 4 byte -2,147,483,648 2,147,483,64
long 8 byte -9,223,372,036,854,775,808 9,223,372,036,854,775,808

Presented by : Prof. S.B.Mehta


Data Type in Java
Floating Type:
Float type value initialize : for example: float a=2.5f

TYPE SIZE MINIMUM VALUE MAXIMUM VALUE


float 4 byte -3.4e 3.4e+038
double 8 byte 1.7e -308 1.7e +308

Presented by : Prof. S.B.Mehta


Data Type in Java
boolean Type:
• The Boolean data type is used to store only two possible values: true and false.
This data type is used for simple flags that track true/false conditions.

• The Boolean data type specifies one bit of information, but its "size" can't be
defined precisely.

• Example: boolean one = false

Presented by : Prof. S.B.Mehta


Data Type in Java

Presented by : Prof. S.B.Mehta


First Program in Java :Printing a Line of Text
FileName : Simple.java

class Simple
{
public static void main(String args[])
{
System.out.println("Hello Java");
}
}

save this file as Simple.java

To compile: javac Simple.java


To execute: java Simple

Output : Hello Java


Presented by : Prof. S.B.Mehta
Parameters used in First Java Program
• class keyword is used to declare a class in java.
• public keyword is an access modifier which 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. The main method is executed by the JVM, so it doesn't require
to create an object to invoke the main method. So it saves memory.
• 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 It is an array where each element of it is a string, which has been named as
"args". If your Java program is run through the console, you can pass the input parameter,
and main() method takes it as input.
• System.out.println() This statement is used to print text on the screen as output, where
the System is a predefined class, and out is an object of the PrintWriter class defined in
the system. The method println prints the text on the screen with a new line. You can
also use print() method instead of println() method. All Java statement ends with a
semicolon.

Presented by : Prof. S.B.Mehta


Program in Java :Addition of two integer number
FileName : Arith.java

class Arith
{
public static void main(String args[])
{
int a=10,b=20, c;
c=a+b;
System.out.println(“Addition is :“ + c);
}
} save this file as Arith.java

To compile: javac Arith.java


To execute: java Arith

Output : Addition is :30


Presented by : Prof. S.B.Mehta
Program in Java :Displaying Text with printf:
printf () method is also quite frequently used for displaying text that needs to
be formatted. The printf () method requires a format String and a set of other
arguments whose number depends on the format String.

For example: consider the following two equivalent statements assuming that
the
variable str holds the String "Java":

System.out.println ("Welcome to "+str);


System.out.printf ("Welcome to %s", str);

% sign is known as the conversion character. Format specifiers are provided


with additional information depending on the formatting that we wish to apply.
Different format specifiers are used to print different types of text.

Presented by : Prof. S.B.Mehta


Format specifier
Different format specifiers are used to print different types of text. The table
below summaries the most commonly used.
Format specifier Description
%d Displays a decimal (base 10 ) integer
%f Display a floating point value in
decimal format
%e or %E Display a floating point number in
exponential notation
%c or %C Display characters
%s or %S Display Strings
%b or %B Display boolean values
%% %%

Presented by : Prof. S.B.Mehta


Example:
Displaying Text with printf
String name1="Sai";
String name2="Gautham";
int marks1=100;
int marks2=99;
System.out.format("%-10s - %4d\n",name1,marks1);
System.out.format("%-10s - %4d\n",name2,marks2);
The output would be
Sai - 100
Gautham - 99
We can also specify the precision of the data to be printed. Precision defines
the number of decimal digits that are to be printed when we use it with a
floating point number. Precision is specified by placing a dot (.) followed by a
number indicating the required precision.

System.out.format("%.3f",34.789456);

The output would be


34.789
Presented by : Prof. S.B.Mehta
Java Operator Precedence

Presented by : Prof. S.B.Mehta


Java Unary Operator
The Java unary operators require only one operand. Unary operators are used to perform
various operations i.e.:
• incrementing/decrementing a value by one
• negating an expression
• inverting the value of a boolean
class OperatorExample
{
Output:
public static void main(String args[])
{ 10
int x=10; 12
12
System.out.println(x++);//10 (11) 10
System.out.println(++x);//12
System.out.println(x--);//12 (11)
System.out.println(--x);//10
}
}

Presented by : Prof. S.B.Mehta


Classes for accepting User Define Input:
Scanner Class :Java Scanner class allows the user to take input from the
console. It belongs to java.util package. It is used to read the input of primitive
types like int, double, long, short, float, and byte. It is the easiest way to read
input in Java program.
Scanner sc=new Scanner(System.in);
//program
import java.util.*;
public class Example
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in); // Create a Scanner object
System.out.println("Enter username");
String name = s.nextLine();// Read user input
System.out.println("name is: " + name);;// Output user input
}
}

Presented by : Prof. S.B.Mehta


Scanner Class Method:
There are various methods of Scanner class which can be used for various data
types. Take a look at the below table to know about these methods.
Method Description.
Method Description
nextBoolean() Reads a boolean value from the user
nextByte() Reads a byte value from the user
nextDouble() Reads a double value from the user
nextFloat() Reads a float value from the user
nextInt() Reads an int value from the user
nextLine() Reads a String value from the user
nextLong() Reads a long value from the user
nextShort() Reads a short value from the user

Presented by : Prof. S.B.Mehta


Program in Java :Access Input
import java.util.Scanner;
public class Example
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter name, age and salary");

// String input
String name = s.nextLine();
// Numerical input
int age = s.nextInt();
double salary = s.nextDouble();
// Output input by user
System.out.println("Name: "+ name);
System.out.println("Age: "+ age);
System.out.println("Salary: "+ salary);
}
}

Presented by : Prof. S.B.Mehta


Classes for accepting User Define Input:
BufferedReader:
BufferedReader class is used to read the text from a character-based input
stream. It can be used to read data line by line by readLine() method. It makes
the performance fast. It inherits Reader class.

import java.io.*;
public class BufferedReaderExample
{
public static void main(String args[])throws Exception
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
String name="";
System.out.println("Enter data: ");
name=br.readLine();
System.out.println("data is: "+name);
}
}

Presented by : Prof. S.B.Mehta

You might also like