Вы находитесь на странице: 1из 5

Programming Approach

Programming in HLL can be done in one of the following two approaches:


a) Procedural Programming Approach
b) Object Oriented Programming Approach.
a) Procedural or Structured Programming: Developing a language with a process centric
approach is called procedural programming. It concentrates on HOW to solve the problem. It
focuses on the methods/processes for which the software is being built. This approach refers
to breaking up the complex problem into smaller problems and then solving each by using
modules (functions or procedures) which act on the data. These functions are tightly
interdependent on each other. Example: BASIC,COBOL, C, Pascal.
Drawbacks:
i) The modules or parts of the whole program strongly depend on each other. So, a module
cannot be reused by other programs.
ii) The procedural program code is not flexible to change. The program written in a
procedural language completely needs to be changed as all the parts of a program are linked
and dependent on each other.
iii) Solutions to real world problems cannot be directly depicted using this language.
b) Object Oriented Programming: OOP simulates the real world in software. Real world
consists of identifiable entities or objects. These objects have their peculiar characteristics
and behavior. Examples of real-world objects are books, pens, students, chair, and car and so
on. This approach concentrates on “WHAT”- “What is the object that will get affected by this
problem?” and then the approach works on the attributes/state and behavior/methods of that
object. Examples: Smalltalk, C++, Java.
Advantages:
i) This approach models the real world quite accurately as the programs written in the
language are focused on the objects rather than the procedure.
ii) It is extremely reusable as these objects can be invoked in different programs.
iii) Programs written in OOP are simple to change when the requirements for the application
changes.
iv) The principles of OOP prevent the objects from being mishandled and are kept safe from
unauthorized access.

1
JAVA
(An Object-Oriented Programming Language)
History of Java
Sun Micro systems began for software to run on TV and VCR sets i.e. Interactive TV and
VCR sets. A team of software engineers led by James Gosling, Patric Naughton, Chris
Warth, Ed Frank and Mike Sheridan laid specifications for these projects in 1991. By
September 1992, the basic system was drafted. These interactive sets were called set-top
boxes. The hardware was called 7(Seven), OS was called Green and the programming
language was called OAK.
Between the initial implementation of OAK in the fall of 1992 and the public announcement
of Java in 1995, many more people contributed to the design and the evolution of the
language. Bill Joy, Arther van Hoff, Jonathan Payne, Frank Yellin and Tim Lindholm were
key contributors to the maturing of the older prototype.
Hot Java was the first commercial product to be developed completely in Java. On May 23,
1995, Java was commercially released. The advent of Internet gave a tremendous boost to
this language. Java Programs can be embedded in HTML pages and downloaded by Web
browser to bring live animations and interaction to web clients. The power of Java is not
limited to web applications. Java is a general-purpose programming language. It has full
programming features and can be used to develop standalone applications.
Characteristics of Java
1) It is simple : No programming language is simple, but java is bit simple as compared to
other OOP language such as C++.
2) It is object oriented : Java is called OOP language because Java is centered on creating
objects, manipulating objects and making objects working together.
3) It is distributed : Distributed computing involves several computers on a network
working together. Java is designed to make distributed computing easy. Networking
capability is inherently integrated into Java.
4) Java is compiled as well as interpreted: One needs an interpreter and a compiler to run
Java programs. The programs are compiled into Java Virtual Machine Code called
bytecode. The bytecode is machine independent and can run on any machine that has java
interpreter.
5) Java is highly case sensitive: Java is highly case aware. Instructions written in java are
different when written in the lower case and the upper case.
6) It is robust: Robust means reliable. No programming language can assure reliability.

2
Java puts a lot of emphasis on early checking of possible errors as java compilers can
detect many problems that would throw show up at execution time in other languages. It
has a runtime exception handling feature to provide programming support for robustness.
Java can catch and respond to an exceptional situation so that the program can continue
its normal execution and terminate gracefully when a runtime error occurs.
7) It is secure : Java being an Internet programming language is used in a networked and
distributed environment. You can download a java applet, run it on your computer and it
will cause no damage to your system.
8) It is architecturally neutral- The most remarkable feature of java is that it is
architectural neutral (Platform Independent). You can write one program that runs on
any platform with JVM (Java Virtual Machine). You can run Java Applets from a Web
Browser, but java is more than just a web applet. You can also run stand-alone java
applications directly from operating system by using a java interpreter.
9) It is portable: Java programs can run on any platform without having to be recompiled.
This is one positive aspect of portability.
10) It is multithreaded : Multithreading is capability for a program to perform several tasks
simultaneously within a program. E.g. downloading a video file while playing a video file
would be considered multithreading. It is smoothly integrated in Java.
11) It is a dynamic and one of the most high-performance languages today.
JAVA APPLICATIONS
Java programs can be one of the two types: standalone applications and applets.
Applications are stand-alone programs like any program written using high-level language.
Applications can be executed from any computer with a Java interpreter and are ideal for
developing software. Applets are special kind of Java programs that can run directly from
Java compatible Web browser. Applets are suitable for deploying (installing) Web projects.
Java Program Structure (For standalone programs only)
Probably, the best way to start learning a programming language is to write a simple
program. [* Please consider the program structure as a mandatory syntax requirement,
the
details of what is it will be learnt by you in due course of time]
/* program to -- Welcome to Java*/
class Welcome
{
public static void main(String args[])

3
{
System.out.println(“Welcome to Java”);
}
}
Let us now examine the parts of this sample program:
i) /* program… welcome to java*/
The text enclosed with /* …*/ is called comment. Comments or remarks are non
executable statements purely for enhancing the program readability.
ii) class Welcome
Every java program should begin with the “class” keyword. Java being OOP, classes
contain attributes/data members and behavior/methods of the objects. Methods may
contain other executable statements. Here a class/program with the name Welcome is
defined. It is also called the initial class since it defines the program name. The file
name of this program should be Welcome.java- i.e. same name as that of the class.
Although there can be many classes in a Java program, there can by only one initial
class in a Java program. An initial class contains the main function inside it.
iii) public static void main(String args[])
This is the syntax of the “main” method, it cannot be changed. It is the most important
method because it is from this method that the application begins executing the program.
(Cannot have any other name) If there are several methods in a program, the program
will only begin executing from the main method. If there are many classes within a Java
program, the execution will only begin from the initial class (the class that contains the
main method) If there is no main method in the class, no execution will take place. Thus
the main method is also called the driver method. On reaching the end of main, the
program terminates and the control passes back to the operating system.
Let us now understand each keyword of this method declaration:
public- “main” is the first method called by the Java environment when a program is
executed so it has to be accessible from the Java environment (JDK software). This
method has to be publicly available otherwise how can it be accessed outside the
program. Hence the access specifier has to be public.
static- static methods are class methods that do not need the creation of any object to
work with the method.
void – Functions or methods can return a value. void means nothing. The main
method does not return any value; hence it is declared void.

4
String args[ ]- Functions or methods can also take in arguments or parameters to
work on them. The main method can take arguments in this form.
iii) { } The pair of curly braces called the block of code marks the scope of the main
method and the scope of the class. They indicate the boundaries.
iv) System.out.println(“Welcome to Java”);
This statement prints “Welcome to Java” on the standard output device which is
generally, the monitor. This is the statement to print the desired output that is present in the
brackets (“ … ”). Here, System – computer, out – output device(monitor) , println – print the
output and the control go to the next line.
Exercise I : Write programs in Java to:
i) Print your name
ii) Print your name and address
iii) Print your name , school name and class name
iv) Print a pattern like “****”
“***”
“*”
v) Print the message “hello world!”.

Вам также может понравиться