2) What Are The Differences Between C++ and Java?
2) What Are The Differences Between C++ and Java?
o A: Simple: Java is easy to learn. The syntax of Java is based on C++ which
makes easier to write the program in it.
o Object-Oriented: Java follows the object-oriented paradigm which allows us
to maintain our code as the combination of different type of objects that
incorporates both data and behavior.
o Secured: Java is secured because it doesn't use explicit pointers. Java also
provides the concept of ByteCode and Exception handling which makes it
more secured.
o Interpreted: Java uses the Just-in-time (JIT) interpreter along with the
compiler for the program execution.
o High Performance: Java is faster than other traditional interpreted
programming languages because Java bytecode is "close" to native code. It is
still a little bit slower than a compiled language (e.g., C++).
o Multithreaded: We can write Java programs 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.
A: JVM
JVM is an acronym for Java Virtual Machine; it is an abstract machine which provides
the runtime environment in which Java bytecode can be executed. It is a specification
which specifies the working of Java Virtual Machine.
JRE
JRE stands for Java Runtime Environment. It is the implementation of JVM. The 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.
JDK
JDK is an acronym for Java Development Kit. It is a software development
environment which is used to develop Java applications. It contains JRE +
development tools
5)What gives Java its 'write once and run anywhere'(WORA) nature?
The bytecode. Java compiler converts the Java programs into the class file (Byte
Code) which is the intermediate language between source code and machine code.
This bytecode is not platform specific and can be executed on any computer.
7) What is an object?
A: Object is an instance of the class having the instance variables as the state of the
object and the methods as the behavior of the object. The object of a class can be
created by using the new keyword.
(explicit return type: The constructor is used to initialize an object and it must have
no return value)
The pointer is a variable that refers to the memory address. They are not used in Java
because they are unsafe(unsecured) and complex to understand.
In other words, If a subclass provides the specific implementation of the method that
has been declared by one of its parent class, it is known as method overriding.
Example:
class Animal{
void eat(){System.out.println("eating...");}
}
class Dog extends Animal{
void eat(){System.out.println("eating bread...");}
}
Method Overloading:
If a class has multiple methods having same name but different in parameters, it is known
as Method Overloading.
Example:
class OverloadingExample{
static int add(int a,int b){return a+b;}
static int add(int a,int b,int c){return a+b+c;}
}
A: Inheritance
When one object acquires all the properties and behaviors of a parent object, it is
known as inheritance. It provides code reusability. It is used to achieve runtime
polymorphism.
Polymorphism
If one task is performed in different ways, it is known as polymorphism.
Abstraction
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as
encapsulation. A java class is the example of encapsulation.
16) What is final keyword in java?
A: