Sei sulla pagina 1di 8

Programming paradigm that views a computer program as a combination of data

structures (called objects) which can exchange information in a standardized manner, and
can be combined with one another as modules or blocks. Each object is independent (can
be changed without affecting other blocks), can run (execute) by itself, and can be
interlocked with other objects. Objects interact by passing information among each other,
and each object contains information about itself (a property called encapsulation) and
the objects it can interact with (a property called Inheritance). Major OOP-oriented
languages are C++, Java, and Smalltalk.

Read more: http://www.businessdictionary.com/definition/object-oriented-programming-
OOP.html#ixzz2WolRHh6P
Object Orientation Languages (OOL) is concerned to develop an application based on
real time while Procedural Programing Languages (PPL) are more concerned with the
processing of procedures and functions.
In OOL, more emphasis is given on data rather than procedures, while the programs are
divided into Objects and the data is encapsulated (Hidden) from the external
environment, providing more security to data which is not applicable or rather possible in
PPL. In PPL, its possible to expose Data and/or variables to the external entities which is
STRICTLY restricted IN OOL.
In OOL, the Objects communicate with each other via Functions while there is no
communication in PPL rather its simply a passing values to the Arguments to the
Functions and / or procedures.
OOL follows Bottom Up Approach of Program Execution while in PPL its Top Down
approach.
OOL concepts includes Inheritance, Encapsulation and Data Abstraction, Late Binding,
Polymorphism, Multithreading, and Message Passing while PPL is simply a
programming in a traditional way of calling functions and returning values.

Java is an object-oriented programming language developed by James Gosling and
colleagues at Sun Microsystems in the early 1990s. Unlike conventional languages which
are generally designed either to be compiled to native (machine) code, or to be
interpreted from source code at runtime, Java is intended to be compiled to a bytecode,
which is then run (generally using JIT compilation) by a Java Virtual Machine.
Java was started as a project called "Oak" by James Gosling in June 1991. Gosling's goals
were to implement a virtual machine and a language that had a familiar C-like notation
but with greater uniformity and simplicity than C/C++. The first public implementation
was Java 1.0 in 1995. It made the promise of "Write Once, Run Anywhere", with free
runtimes on popular platforms. It was fairly secure and its security was configurable,
allowing for network and file access to be limited. The major web browsers soon
incorporated it into their standard configurations in a secure "applet" configuration.
popular quickly. New versions for large and small platforms (J2EE and J2ME) soon were
designed with the advent of "Java 2". Sun has not announced any plans for a "Java 3"
In 1997, Sun approached the ISO/IEC JTC1 standards body and later the Ecma
International to formalize Java, but it soon withdrew from the process. Java remains a
proprietary de facto standard that is controlled through the Java Community Process. Sun
makes most of its Java implementations available without charge, with revenue being
generated by specialized products such as the Java Enterprise System. Sun distinguishes
between its Software Development Kit (SDK) and Runtime Environment (JRE) which is
a subset of the SDK, the primary distinction being that in the JRE the compiler is not
present.

Java is pure object oriented programming language than c++, it uses the concepts of
Classes, Objects, Inheritance, Polymorphism. And the execution of a program is non-
linear.

Java's motto (so to speak) is "write once run anywhere".
When you compile a Java program, an intermediate bytecode is generated, which itself is
interpreted by the Java Virtual Machine. This way you write a program once, and the
virtual machine translates the bytecode into instructions a specific processor can
understand. Execution of a Java program is by consequence a bit slow, because the
intermediate bytecode has to be interpreted.

Java uses a "Garbage Collector" which manages memory automatically so the
programmer doesn't have to handle that.

Variables in Java can be declared anywhere in a program. (Although it is recommended
to declare/define them at the beginning of blocks).
Reuse of code achieved by inheritance.
By default members are private.
During the execution of bytecode by JVM, it does not substitute the entire classes of
package which are imported in the program. It just enters the package and executes the
class and returns result in to the program. Due to this less memory is used by java
program.

C

C uses concept of structures (not object oriented).
In C we use the concept of pointers whereas there are no pointers used in JAVA
In C the programmer needs to manage memory manually. "malloc()" and "free()" are the
fundamental memory allocation library calls.
In C the declaration of variables should be on the beginning of the block.
C supports go to statement, struct and union unlike Java
C is compiled to the machines "native language" so it's execution is much faster than Java's.
No reuse in code and by default members are public.
C programs will have a larger memory footprint than an equivalent program written in pure
machine code, but the total memory use of a C program is much smaller than the a Java
program because C does not require the loading of an execution interpreter like the JVM.
The main differences between Java and C are speed, portability, and object-orientation.


Difference between class and structure:

In class,We can declare and define data members and member functions.But in Structure we can
declare variables and functions.

JAVA:
Java was created for the purpose of making a language that could be implemented on many
different types of computers (cell phone, mac, PC, linux, etc.) C on the other hand can only be
run on a computer of the same type as the one that compiled the program.

One of the costs of this portability in Java is speed. On numerous benchmarks Java still lags
behind C in terms of speed, but that gap is narrowing.

Java is also object-oriented, whereas C is not. Java allows a user to create classes that contain
data and methods. C is not capable of doing that.
1. James Gosling
2. Oak or green project
OBJECT ORIENTED PROGRAMMING CONCEPTS AND PROPERTIES
Encapsulation Encapsulation is capturing data and keeping it safely and securely from
outside interfaces.
Inheritance- This is the process by which a class can be derived from a base class with
all features of base class and some of its own. This increases code reusability.
Polymorphism- This is the ability to exist in various forms. For example an operator can
be overloaded so as to add two integer numbers and two floats.
Abstraction- The ability to represent data at a very conceptual level without any details.
Object:
This is the basic unit of object oriented programming. That is both data and function that operate
on data are bundled as a unit called as object.
Class:
When you define a class, you define a blueprint for an object. This doesn't actually define any
data, but it does define what the class name means, that is, what an object of the class will consist
of and what operations can be performed on such an object.
An instance, in object-oriented programming (OOP), is a specific realization of
any object. An object may be varied in a number of ways. Each realized variation of that
object is an instance. The creation of a realized instance is called instantiation.
In object-oriented programming, a method is a subroutine (or procedure) associated with
a class. Methods define the behavior to be exhibited by instances of the associated
class at program run time. Methods have the special property that at runtime, they have
access to data stored in an instance of the class (or class instance or class
object or object) they are associated with and are thereby able to control the state of the
instance.
[1]
The association between class and method is called binding. A method
associated with a class is said to be bound to the class. Methods can be bound to a class
at compile time (static binding) or to an object at runtime (dynamic binding).
[2]

DATA TYPES
byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum
value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful
for saving memory in large arrays, where the memory savings actually matters. They can
also be used in place of int where their limits help to clarify your code; the fact that a
variable's range is limited can serve as a form of documentation.
short: The short data type is a 16-bit signed two's complement integer. It has a minimum
value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same
guidelines apply: you can use a short to save memory in large arrays, in situations where
the memory savings actually matters.
int: The int data type is a 32-bit signed two's complement integer. It has a minimum
value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral
values, this data type is generally the default choice unless there is a reason (like the
above) to choose something else. This data type will most likely be large enough for the
numbers your program will use, but if you need a wider range of values, use long instead.
long: The long data type is a 64-bit signed two's complement integer. It has a minimum
value of -9,223,372,036,854,775,808 and a maximum value of
9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of
values wider than those provided by int.
float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of
values is beyond the scope of this discussion, but is specified in the Floating-Point Types,
Formats, and Values section of the Java Language Specification. As with the
recommendations for byte and short, use a float (instead of double) if you need to save
memory in large arrays of floating point numbers. This data type should never be used for
precise values, such as currency. For that, you will need to use
the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and
other useful classes provided by the Java platform.
double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its
range of values is beyond the scope of this discussion, but is specified in theFloating-
Point Types, Formats, and Values section of the Java Language Specification. For
decimal values, this data type is generally the default choice. As mentioned above, this
data type should never be used for precise values, such as currency.
boolean: The boolean data type has only two possible values: true and false. Use this data
type for simple flags that track true/false conditions. This data type represents one bit of
information, but its "size" isn't something that's precisely defined.
char: The char data type is a single 16-bit Unicode character. It has a minimum value
of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

If statement
If(boolean_expression)
{
//Statements will execute if the boolean expression is true
}

If else statement.
if(Boolean_expression){
//Executes when the Boolean expression is true
}else{
//Executes when the Boolean expression is false
}

Nested if else statement
if(Boolean_expression 1){
//Executes when the Boolean expression 1 is true
}else if(Boolean_expression 2){
//Executes when the Boolean expression 2 is true
}else if(Boolean_expression 3){
//Executes when the Boolean expression 3 is true
}else {
//Executes when the none of the above condition is true.
}




Switch case
switch(expression){
case value :
//Statements
break; //optional
case value :
//Statements
break; //optional
//You can have any number of case statements.
default : //Optional
//Statements
}


While loop
while(Boolean_expression)
{
//Statements
}

Do While loop
do
{
//Statements
}while(Boolean_expression)
{
//Statements
}

For loop
for(initialization; Boolean_expression; update)
{
//Statements
}

Arrays
- One Dimension
Data type data[fixed number value];
Ex.
int i[5];
- Two Dimension
Data type data[fixed number value][fixed number value];





Bubble sort
public class bubbleSort{
public static void main(String a[]){
int i;
int array[] = {12,9,4,99,120,1,3,10};
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
System.out.println();
int i, j,t=0;
for(i = 0; i < n; i++){
for(j = 1; j < (n-i); j++){
if(a[j-1] > a[j]){
t = a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}
}
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ");
System.out.println();
}

Shell sort
public static void shell(int[] a) {
int increment = a.length / 2;
while (increment > 0) {
for (int i = increment; i < a.length; i++) {
int j = i;
int temp = a[i];
while (j >= increment && a[j - increment] > temp) {
a[j] = a[j - increment];
j = j - increment;
}
a[j] = temp;
}
if (increment == 2) {
increment = 1;
} else {
increment *= (5.0 / 11);
}
}
}



Baloon sort
public class baloonSort{
public static void main(String a[]){
int i;
int array[] = {12,9,4,99,120,1,3,10};
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
System.out.println();
int i, j,temp=0;
for(i = 0; i < n; i++){
for(j = 1; j < (n-i); j++){
if(a[i] > a[j]){
temp = a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ");
System.out.println();
}

Potrebbero piacerti anche