1) Explain Object Oriented Programming Concept Objects
1) Explain Object Oriented Programming Concept Objects
Objects
Objects are the basic unit of OOP. They are instances of class, which have data members and use various member
functions to perform tasks.
Class
It is similar to structures in C language. Class can also be defined as user defined data type but it also contains
functions in it. So, class is basically a blueprint for object. It declares & defines what data variables the object will
have and what operations can be performed on the class's object.
Abstraction
Abstraction refers to showing only the essential features of the application and hiding the details. In C++, classes
can provide methods to the outside world to access & use the data variables, keeping the variables hidden from
direct access, or classes can even declare everything accessible to everyone, or maybe just to the classes inheriting it.
This can be done using access specifiers.
Encapsulation
It can also be said data binding. Encapsulation is all about binding the data variables and functions together in class.
Inheritance
Inheritance is a way to reuse once written code again and again. The class which is inherited is called the Base class
& the class which inherits is called the Derived class. They are also called parent and child class.
So when, a derived class inherits a base class, the derived class can use all the functions which are defined in base
class, hence making code reusable.
Polymorphism
It is a feature, which lets us create functions with same name but different arguments, which will perform different
actions. That means, functions with same name, but functioning in different ways. Or, it also allows us to redefine a
function to provide it with a completely new definition. You will learn how to do this in details soon in coming
lessons.
Exception Handling
Exception handling is a feature of OOP, to handle unresolved exceptions or errors produced at runtime.
2) Write steps to execute java program
Step i: Create a folder
C:\SoftwareTestingMaterial
Step ii: write a java program using Notepad or another text editor, create a Java file HelloTesters.java with the
following text:
class HelloTesters
1{
2 public static void main(String[] args)
3 {
4 System.out.println("This is READY!!!");
5 }
}
Source Compiler
Byte
code code
How the interpreter works?
Byte Interpreter
Machine
code code
3) Explain Java Milestones
4) Write the Features of java.
Object Oriented
In Java, everything is an Object. Java can be easily extended since it is based on the Object model.
Platform Independent
Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into
platform specific machine, rather into platform-independent byte code. This byte code is distributed over the web
and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.
Simple
Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.
Secure
With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based
on public-key encryption.
Architecture-neutral
Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on
many processors, with the presence of Java runtime system.
Portable
Being architecture-neutral and having no implementation dependent aspects of the specification makes Java
portable. The compiler in Java is written in ANSI C with a clean portability boundary, which is a POSIX subset.
Robust
Java makes an effort to eliminate error-prone situations by emphasizing mainly on compile time error checking and
runtime checking.
Multithreaded
With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This
design feature allows the developers to construct interactive applications that can run smoothly.
Interpreted
Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development
process is more rapid and analytical since the linking is an incremental and light-weight process.
High Performance
With the use of Just-In-Time compilers, Java enables high performance.
Distributed
Java is designed for the distributed environment of the internet.
Dynamic
Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java
programs can carry an extensive amount of run-time information that can be used to verify and resolve accesses to
objects at run-time.
5) Difference between c++ and java
There are many differences and similarities between the C++ programming language and Java. A list of top
differences between C++ and Java are given below:
Mainly used for C++ is mainly used for system Java is mainly used for application
programming. programming. It is widely used in window,
web-based, enterprise and mobile
applications.
Design Goal C++ was designed for systems and Java was designed and created as an
applications programming. It was an interpreter for printing systems but later
extension of C programming language. extended as a support network computing.
It was designed with a goal of being easy
to use and accessible to a broader audience.
Goto C++ supports the goto statement. Java doesn't support the goto statement.
Multiple C++ supports multiple inheritance. Java doesn't support multiple inheritance
inheritance through class. It can be achieved
by interfaces in java.
Operator C++ supports operator overloading. Java doesn't support operator overloading.
Overloading
Pointers C++ supports pointers. You can write Java supports pointer internally. However,
pointer program in C++. you can't write the pointer program in java.
It means java has restricted pointer support
in java.
Compiler and C++ uses compiler only. C++ is Java uses compiler and interpreter both.
Interpreter compiled and run using the compiler Java source code is converted into
which converts source code into bytecode at compilation time. The
machine code so, C++ is platform interpreter executes this bytecode at
dependent. runtime and produces output. Java is
interpreted that is why it is platform
independent.
Call by Value and C++ supports both call by value and call Java supports call by value only. There is
Call by reference by reference. no call by reference in java.
Structure and C++ supports structures and unions. Java doesn't support structures and unions.
Union
Thread Support C++ doesn't have built-in support for Java has built-in thread support.
threads. It relies on third-party libraries
for thread support.
Documentation C++ doesn't support documentation Java supports documentation comment (/**
comment comment. ... */) to create documentation for java
source code.
Virtual Keyword C++ supports virtual keyword so that we Java has no virtual keyword. We can
can decide whether or not override a override all non-static methods by default.
function. In other words, non-static methods are
virtual by default.
unsigned right C++ doesn't support >>> operator. Java supports unsigned right shift >>>
shift >>> operator that fills zero at the top for the
negative numbers. For positive numbers, it
works same like >> operator.
Inheritance Tree C++ creates a new inheritance tree Java uses a single inheritance tree always
always. because all classes are the child of Object
class in java. The object class is the root of
the inheritance tree in java.
{
long n,fact=1;
n=Long.parseLong(args[0]);
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
System.out.println("fact="+fact);
}
}
Documentation You can write a comment in this section. Comments are beneficial for the programmer because
Section they help them understand the code. These are optional, but we suggest you use them because
they are useful to understand the operation of the program, so you must write comments within
the program.
Package You can create a package with any name. A package is a group of classes that are defined by a
statement name. That is, if you want to declare many classes within one element, then you can declare it
within a package. It is an optional part of the program, i.e., if you do not want to declare any
package, then there will be no problem with it, and you will not get any errors. Here, the package
is a keyword that tells the compiler that package has been created.
It is declared as:
package package_name;
Import This line indicates that if you want to use a class of another package, then you can do this by
statements importing it directly into your program.
Example:
import calc.add;
Interface Interfaces are like a class that includes a group of method declarations. It's an optional section
statement and can be used when programmers want to implement multiple inheritances within a program.
Class Definition A Java program may contain several class definitions. Classes are the main and essential
elements of any Java program.
Main Method Every Java stand-alone program requires the main method as the starting point of the program.
Class This is an essential part of a Java program. There may be many classes in a Java program,
and only one class defines the main method. Methods contain data type declaration and
executable statements.