Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

4.

Operators: Symbols used to perform operations on values, such as addition, subtraction, and
comparison.
UNIT 1 INTRODUCTION TO PROGRAMMING 5. Control Structures: Statements used to control the flow of a program, such as if-else
statements, loops, and function calls.
6. Algorithm: A step-by-step procedure for solving a problem or performing a task.
7. Function: A self-contained block of code that performs a specific task and can be called from
1.1 What is program? other parts of the program.
1.2 Levels of programming languages 8. Comment: A piece of text in a program that is ignored by the compiler or interpreter, used to
1.3 Programming methodologies – structured and object-oriented add notes or explanations to the code.
1.4 Java History 9. Debugging: The process of finding and fixing errors or bugs in a program.
1.5 Features of Java 10. IDE: Integrated Development Environment, a software application that provides a
comprehensive development environment for coding, debugging, and testing.
Example : Apache NetBeans
11. Libraries and Frameworks: Collections of pre-written code that can be used to perform
common tasks and speed up development.
12. Paradigms / Methodology: The programming style or philosophy used in the language, such
1.1 WHAT IS PROGRAM? as structural, procedural, object-oriented, or functional.

Characteristics of a programming Language –


• A programming language must be simple, easy to learn and use, have good readability, and
→ A Computer program is a list of logical instructions for the computer to follow in performing a task. be human recognizable.
• Abstraction is a must-have Characteristics for a programming language in which the ability to
→ A computer program is a step by step set of instructions that a computer has to work through in
a logical sequence in order to carry out a particular task. define the complex structure and then its degree of usability comes.
• A portable programming language is always preferred.
• Programming language’s efficiency must be high so that it can be easily converted into a
Features of a good computer program : machine code and its execution consumes little space in memory.
• A programming language should be well structured and documented so that it is suitable for
1. Has instructions to process data types including numeric and alphanumeric data. application development.
• Necessary tools for the development, debugging, testing, maintenance of a program must be
2. Uses operations to process data which include arithmetic, relational/comparison, and logical
operations. provided by a programming language.
• A programming language should provide a single environment known as Integrated
3. Performs input and output operations, must provide instructions for inputting data into memory and Development Environment(IDE).
outputting information. • A programming language must be consistent in terms of syntax and semantics.

4. Must count and accumulate totals for reporting purposes. The area in internal memory to record
number of times an event, activity, or condition is encountered is called a counter, to record subtotal
or total of certain numeric value is the accumulator.
1.2 LEVELS OF PROGRAMMING LANGUAGES
5. Has capability to store data temporarily in and retrieve it from internal memory for use. i.e., as
variables, constants, dictionaries, tuples and arrays of data.
Basically, there are two main categories of computer languages, namely Low Level Language and High Level
PROGRAMMING LANGUAGE Language.
→ A programming language is a set of instructions and syntax which is used to create software
programs. 1] Low Level Languages
→ A programming language is a formal language that specifies a set of instructions for a computer to
perform specific tasks. → Low level languages are the basic computer instructions or better known as machine codes.
→ Its used to write software programs and applications, and to control and manipulate computer
systems. → A computer cannot understand any instruction given to it by the user in English or any other high level
language. These low level languages are very easily understandable by the machine.
Some of the basic terminologies used in programming language :
→ The main function of low level languages is to interact with the hardware of the computer. They
1. Syntax: The specific rules and structure used to write code in a programming language. help in operating, syncing and managing all the hardware and system components of the computer.
2. Data Types: The type of values that can be stored in a program, such as numbers, strings, and They handle all the instructions which form the architecture of the hardware systems.
boolean.
3. Variables: Named memory locations that can store values.

Prepared by : Prof. Lavleena Stephens Prepared by : Prof. Lavleena Stephens


A] Machine Language
→ The language was first developed to interact with the first generation computers. low high

→ Imagine them as the “native tongue” of the computer, the language closest to the hardware itself.
Each unique computer has a unique machine language.
→ A machine language program is made up of a series of binary patterns (e.g., 01011100) which
represent simple operations that can be accomplished by the computer (e.g., add two operands, move
data to a memory location).
LEVEL OF EXECUTION TIME
→ Machine language programs are executable, meaning that they can be run directly. COMPLEXITY
→ Programming in machine language requires memorization of the binary codes and can be difficult for
the human programmer.

B] Assembly Language
→ This is the second generation programming language. It is a development on the machine language,
where instead of using only numbers, we use English words, names, and symbols.
high low
→ The machine language instructions are replaced with simple pneumonic abbreviations (e.g., ADD,
MOV). Thus assembly languages are unique to a specific computer (machine).
→ Prior to execution, an assembly language program requires translation to machine language. This Programming Languages
translation is accomplished by a computer program known as an Assembler. Assemblers are written
for each unique machine language.
Four commonly used assembly languages are CISC, RISC, VLIW, and DSP.
→ It is the most basic computer language necessary for any processor.

2] High Level Language

→ High-level languages, i.e., programming languages like C,C++, JAVA etc., are more English-like and,
therefore, make it easier for programmers to “think” in the programming language.
→ High-level languages also require translation to machine language before execution. This translation 1. First-Generation Language :
is accomplished by either a compiler or an interpreter. Also called machine languages/ 1GL. This language is machine-dependent. The machine language
→ Compilers translate the entire source code program before execution. (Eg: C++, Java) statements are written in binary code (0/1 form) because the computer can understand only binary
Interpreters translate source code programs one line at a time. (Eg: Python) language.
→ Interpreters are more interactive than compilers.
Advantages Disadvantages
→ The important feature about such high level languages is that they allow the programmer to write
Fast & efficient as statements are directly Difficult to learn binary codes.
programs for all types of computers and systems.
written in binary language.
→ Every instruction in high level language is converted to machine language for the computer to
No translator is required. Difficult to understand – both programs &
comprehend.
where the error occurred.

2. Second Generation Language :


Also called assembler languages/ 2GL. Assembly language contains human-readable notations that can
be further converted to machine language using an assembler.
Assembler – converts assembly level instructions to machine-level instructions.
Programmers can write the code using symbolic instruction codes that are meaningful abbreviations of
mnemonics. It is also known as low-level language.
Prepared by : Prof. Lavleena Stephens Prepared by : Prof. Lavleena Stephens
Advantages Disadvantages Programming Languages From Lowest to Highest Level
It is easier to understand if compared to Assembler is required.
machine language. • Machine Code (Binary): Composed of 0’s and 1’s that refer to simple states, 1 being ‘on’ and 0
Modifications & location of errors are This language is architecture /machine- being ‘off’. This binary machine language is the lowest programming language level.
easy. dependent, with a different instruction set
• Machine Code (Hexidecimal): Composed of hexadecimal values that strongly correlated to
for different machines.
binary. There is only a single level of abstraction between hexadecimal code and binary.

3. Third-Generation Language : • Assembly Language: A low-level programming language specific to the computer architecture
on which it runs.
The third generation is also called procedural language /3GL. It consists of the use of a series of
English-like words that humans can understand easily, to write instructions. It’s also called High-Level • FORTRAN: The first high-level language invented.
Programming Language. For execution, a program in this language needs to be translated into machine
• BASIC: The second high-level language invented.
language using a Compiler/ Interpreter.
• C Language: This was high-level when invented but is now regarded as more of a middle-level
Examples: C, PASCAL, FORTRAN, COBOL, etc.
language. Many newer languages are built on top of the C language.
Advantages Disadvantages
• C++: A cross-platform language used to create high-performance applications.
Use of English-like words makes it a Compiler/ interpreter is needed.
human-understandable language. • Perl: Created to be a highly capable, feature-rich programming language
Lesser number of lines of code as Different compilers are needed for
• Java: A high-level programming language and computing platform.
compared to the above 2 languages. different machines.
• JavaScript: A scripting language used to create dynamically updating content.
Same code can be copied to another
machine & executed on that machine by • PHP: A widely-used general-purpose scripting language used for the web.
using compiler-specific to that machine.
• C#: A modern, object-oriented, and type-safe programming language.
• Python: A high-level programming language that reads close to English. Built on the C language.
4. Fourth Generation Language :
The fourth-generation language is also called a non – procedural language/ 4GL. It enables users to • SQL: A high-level query language for accessing structured data from databases.
access the database. These languages are also user-friendly to understand & implement. • Prolog: Used for Artificial Intelligence, this is the language with the highest level of abstraction
Examples : SQL, Foxpro, Focus, etc. at the moment.

Advantages Disadvantages
Easy to understand & learn. Memory consumption is high.
Less time is required for application Has poor control over Hardware.
creation.
It is less prone to errors. Less flexible.

5. Fifth Generation Language :


The fifth-generation languages are also called 5GL. It is based on the concept of artificial intelligence. It
uses the concept that rather than solving a problem algorithmically, an application can be built to solve it
based on some constraints, i.e., we make computers learn to solve any problem. Parallel Processing &
superconductors are used for this type of language to make real artificial intelligence.
Examples: PROLOG, LISP, etc.
Advantages Disadvantages
Machines can make decisions. Complex and long code.
Programmer effort reduces to solve a More resources are required & they are
problem. expensive too.
Easier than 3GL or 4GL to learn and use.

Prepared by : Prof. Lavleena Stephens Prepared by : Prof. Lavleena Stephens


1.3 PROGRAMMING METHODOLOGIES Imperative Programming
Declarative Programming

In this, programs specify how it is to be done. In this, programs specify what is to be done.
Programming Methodology deals with analysis, design & implementation of program.

Here, analysis : analysis of a problem, design : design algorithms and flowcharts, and implementation : It simply describes the control flow of
It simply expresses the logic of computation.
writing and executing the program on a suitable platform. computation.

Its main goal is to describe how to get it or Its main goal is to describe the desired result
accomplish it. without direct dictation on how to get it.

Its advantages include effective code, which can be


Its advantages include ease to learn and read, the
applied by using ways, easy extension, high level
notional model is simple to understand, etc.
of abstraction, etc.

Its type includes procedural programming,


Its type includes logic programming and functional
object-oriented programming, parallel
programming.
processing approach.

In this, the user is allowed to make decisions


In this, a compiler is allowed to make decisions.
and commands to the compiler.

It has many side effects and includes mutable It has no side effects and does not include any
variables as compared to declarative mutable variables as compared to imperative
programming. programming.

It gives full control to developers that are very It may automate repetitive flow along with
important in low-level programming. simplifying code structure.
Imperative Programming : it is a type of programming paradigm that describes how the program
executes. Developers are more concerned with how to get an answer step by step. It comprises the In imperative programming, the programmer is In declarative programming, the system optimizes
sequence of command imperatives. In this, the order of execution is very important and uses both responsible for optimizing the code for the code based on the rules and constraints
mutable and immutable data. performance specified by the programmer.
Examples: Java, C, C++, Pascal, PHP, Python, Ruby, Fortran
In imperative programming, variables can be In declarative programming, variables are typically
Declarative Programming : it is a type of programming paradigm that describes what programs to be mutable. immutable.
executed. Developers are more concerned with the answer that is received. It declares what kind of
results we want and leave programming language aside focusing on simply figuring out how to produce
them. In simple words, it mainly focuses on end result. It expresses the logic of computation.

Examples: SQL, Miranda, Prolog, Lisp, Many markup languages (e.g., HTML)

Prepared by : Prof. Lavleena Stephens Prepared by : Prof. Lavleena Stephens


Some of the major programming methodologies used : Difference between Structured Programming v/s Object Oriented Programming

1. Structured Programming :
Structured Programming, as name suggests, is a technique that is considered as precursor to OOP and Structured Programming Object-Oriented Programming
usually consists of well-structured and separated modules. In this programming, user can create its
own user-defined functions as well as this methodology tries to resolve issues that are associated with Also called Modular Programming, it is a It relies on concept of objects that contain data and
unconditional transfers to allow programmers follow logic of programs. It also requires more discipline subset of procedural programming. code.
at the design and logical structuring stage.
Example : Pascal, ALGOL, C, Java, Modula-2, etc.
Programs are divided into small programs or
Programs are divided into objects or entities.
functions.
2. Object-Oriented Programming :
Object-Oriented Programming, as name suggests, is a different approach to programming that brings It is all about facilitating creation of programs It is all about creating objects that usually contain
together data and functions that execute on them. It basically supports encapsulation, abstraction, with readable code and reusable components. both functions and data.
inheritance, polymorphism, etc. It also includes data hiding feature therefore it is more secure. This
model is based on real life entities that focuses on by whom task is to be done rather than focusing on
what to do. Its main aim is to improve and increase quality, Its main aim is to improve and increase both
Example : JAVA, C#, C++, Python, Ruby, etc. clarity, and development time of computer quality and productivity of system analysis and
program. design.
3. Procedural Programming :
A procedural language follows a sequence of statements or commands in order to achieve a desired It simply focuses on representing both structure
output. Each series of steps is called a procedure, and a program written in one of these languages will have It simply focuses on functions and processes and behaviour of information system into tiny or
one or more procedures within it. that usually work on data. small modules that generally combines data and
Example : C, Ada, Pascal, Fortran, COBOL, etc. process both.

4. Functional programming : In this, methods are written globally and code


In this, method works dynamically, make calls as
Rather than focusing on the execution of statements, functional languages focus on the output of lines are processed one by one i.e., Run
per need of code for certain time.
mathematical functions and evaluations. Each function–a reusable module of code–performs a specific sequentially.
task and returns a result. The result will vary depending on what data you input into the function.
Example : Scala, Erlang, Haskell, Elixir, F#, etc. It generally follows “Top-Down Approach”. It generally follows “Bottom-Up Approach”.
5. Logic programming languages :
Instead of telling a computer what to do, a logic programming language expresses a series of facts and rules to It provides less flexibility and abstraction as It provides more flexibility and abstraction as
compared to object-oriented programming. compared to structured programming.
instruct the computer on how to make decisions.
Example : Prolog, Absys, Datalog, Almo-0, etc. It is more difficult to modify and reuse It is less difficult to modify and reuse object-
structured program code as compared to object- oriented programs code as compared to structured
oriented programs. programs.
Other types of languages used :
• Scripting languages : It gives more importance of code. It gives more importance to data.
Programmers use scripting languages to automate repetitive tasks, manage dynamic web content, or
support processes in larger applications.
Example : PHP, Ruby, bash, Perl, Node.js, etc.

Prepared by : Prof. Lavleena Stephens Prepared by : Prof. Lavleena Stephens


Difference between Procedural Programming v/s Object Oriented Programming
1.4 JAVA HISTORY

Procedural Oriented Programming Object-Oriented Programming


The Creation of Java :
In procedural programming, the program is divided In object-oriented programming, the program is
into small parts called functions. divided into small parts called objects. → James Gosling, Mike Sheridan, and Patrick Naughton at Sun Microsystems (which is now a
subsidiary of Oracle Corporation) initiated the Java language project in June 1991.
→ The small team of sun engineers called Green Team. Firstly, it was called "Greentalk" by James
Procedural programming follows a top-down Object-oriented programming follows a bottom- Gosling, and the file extension was .gt.
approach. up approach. → After that, it was called Oak and was developed as a part of the Green project.
→ Between the initial implementation of Oak in the fall of 1992 and the public announcement of Java in
There is no access specifier in procedural Object-oriented programming has access the spring of 1995, many more people contributed to the design and evolution of the language.
programming. specifiers like private, public, protected, etc. → Bill Joy, Arthur van Hoff, Jonathan Payne, Frank Yellin, and Tim Lindholm were key
contributors to the maturing of the original prototype.
→ In 1995, Time magazine called Java as one of the Ten Best Products of 1995.
Adding new data and functions is not easy. Adding new data and function is easy.
The Need of Java language :
Procedural programming does not have any proper Object-oriented programming provides data
way of hiding data so it is less secure. hiding so it is more secure. → Java was originally designed for interactive television and small, embedded systems in electronic
appliances like set-top boxes, but it was too advanced technology for the digital cable television
In procedural programming, overloading is not Overloading is possible in object-oriented industry at the time.
possible. programming. → However, it was best suited for internet programming. Later, Java technology was incorporated by
Netscape.
→ Currently, Java is used in internet programming, mobile devices, games, e-business solutions, etc.
In procedural programming, there is no concept of In object-oriented programming, the concept of
data hiding and inheritance. data hiding and inheritance is used. Why Java was named as "Oak"?

In procedural programming, the function is more In object-oriented programming, data is more → Oak is a symbol of strength and chosen as a national tree of many countries like the U.S.A., France,
important than the data. important than function. Germany, Romania, etc.
→ In 1995, Oak was renamed as "Java" because it was already a trademark by Oak Technologies.
Procedural programming is based on the unreal Object-oriented programming is based on the real
world. world. Why Java Programming was named "Java"?

→ The Green Team gathered to choose a new name. The suggested words were "dynamic",
Procedural programming is used for designing Object-oriented programming is used for "revolutionary", "Silk", "jolt", "DNA", etc.
medium-sized programs. designing large and complex programs. → According to James Gosling, "Java was one of the top choices along with Silk". Since Java was so
unique, most of the team members preferred Java than other names. [Java is an island in Indonesia
Procedural programming uses the concept of Object-oriented programming uses the concept of where the first coffee was produced (called Java coffee). It is a kind of espresso bean.]
procedure abstraction. data abstraction. → Java name was chosen by James Gosling, who is known as the Father of Java, while having a cup of
coffee nearby his office.

Code reusability absent in procedural Code reusability present in object-oriented


programming, programming.
JDK 1.0 was released on January 23, 1996. After the first release of Java, there have been many additional
Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc. 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.

Many java versions have been released till now. The current stable release of Java is Java SE 20 (21st
March, 2023).

Prepared by : Prof. Lavleena Stephens Prepared by : Prof. Lavleena Stephens


Multithreaded : A thread is like a separate program, executing concurrently. We can write Java programs
1.5 FEATURES OF JAVA that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that
it doesn't occupy memory for each thread. It shares a common memory area. Threads are important for multi-
media, Web applications, etc.
The principles for creating Java programming were "Simple, Robust, Portable, Platform-independent,
Secured, High Performance, Multithreaded, Architecture Neutral, Object-Oriented, Interpreted, and Architecture Neutral : Java is architecture neutral because there are no implementation dependent features,
Dynamic". for example, the size of primitive types is fixed.

Java Buzzwords
In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory
for 64-bit architecture. However, it occupies 4 bytes of memory for both 32 and 64-bit architectures in Java.

Simple : Java is very easy to learn, and its syntax is simple, clean and easy to understand. 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
Robust : The English meaning of Robust is strong. Java is robust because: the methods from any machine on the internet.

• It uses strong memory management. Object-oriented : Java is an object-oriented programming language. Everything in Java is an object. Object-
• There is a lack of pointers that avoids security problems. oriented means we organize our software as a combination of different types of objects that incorporate both
data and behaviour.
• Java provides automatic garbage collection which runs on the Java Virtual Machine to get rid of
objects which are not being used by a Java application anymore.
Interpreted : The Java source code first compiled into a binary byte code using Java compiler, then this byte
• There are exception handling and the type checking mechanism in Java. code runs on the JVM (Java Virtual Machine), which is a software based interpreter. So Java is considered as
both interpreted and compiled.
Portable : Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't
require any implementation. 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++. Java supports dynamic
Platform Independent : Java is platform independent because it is different from other languages compilation and automatic memory management (garbage collection).
like C, C++, etc. which are compiled into platform specific machines while Java is a write once, run anywhere
language. A platform is the hardware or software environment in which a program runs. 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: Runtime Environment, and Additional Note :
API(Application Programming Interface).
Tips for learning new programming language:
Java code can be executed on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/OS, etc. 1. Start with the fundamentals: Begin by learning the basics of the language, such as syntax,
Java code is compiled by the compiler and converted into bytecode. This bytecode is a platform-independent data types, variables, and simple statements. This will give you a strong foundation to build
code because it can be run on multiple platforms, i.e., Write Once and Run Anywhere (WORA). upon.
2. Code daily: Like any skill, the only way to get good at programming is by practicing regularly.
Secured : Java is best known for its security. With Java, we can develop virus-free systems. Java is secured Try to write code every day, even if it’s just a few lines.
because: 3. Read the documentation: Every programming language has documentation that explains its
features, syntax, and best practices. Make sure to read it thoroughly to get a better
• No explicit pointer understanding of the language.
4. Join online communities: There are many online communities dedicated to programming
• Java Programs run inside a virtual machine sandbox
languages, where you can ask questions, share your code, and get feedback. Joining these
• Classloader: Classloader in Java is a part of the Java Runtime Environment (JRE) which is used to communities can help you learn faster and make connections with other developers.
load Java classes into the Java Virtual Machine dynamically. It adds security by separating the package 5. Learn from others: Find a mentor or someone who is experienced in the language you’re
for the classes of the local file system from those that are imported from network sources. trying to learn. Ask them questions, review their code, and try to understand how they solve
• Bytecode Verifier: It checks the code fragments for illegal code that can violate access rights to problems.
objects. 6. Practice debugging: Debugging is an essential skill for any programmer, and you’ll need to do
• Security Manager: It determines what resources a class can access such as reading and writing to the a lot of it when learning a new language. Make sure to practice identifying and fixing errors in
local disk. your code.
7. Work on projects: One of the best ways to learn a new language is to work on a project that
High-performance : Java is faster than other traditional interpreted programming languages because Java interests you. It could be a simple game, a web application, or anything that allows you to
bytecode is "close" to native code. Java is an interpreted language that is why it is slower than compiled apply what you’ve learned that is the most important part.
languages, e.g., C, C++, etc.

Prepared by : Prof. Lavleena Stephens Prepared by : Prof. Lavleena Stephens

You might also like