Table of Contents
What is Java?
Java is a popular object-oriented programming language. It is defined as a complete collection of objects. By using Java, we can develop lots of applications such as gaming, mobile apps, and websites.
Explain in brief the history of Java?
In the year 1991, a small group of engineers called 'Green Team' led by James Gosling, worked a lot and introduced a new programming language called "Java". This language is created in such a way that it is going to revolutionize the world.
In today's World, Java is not only invading the internet, but also it is an invisible force behind many of the operations, devices, and applications.
What is the difference between C and Java?
C- Language | Java |
C language was developed by Dennis M. Ritchie in the year 1972. | Java was developed by James Gosling in the year 1995. |
C is Procedural-Oriented | Java is Object-Oriented |
Functions play a major role in the C language. | Objects play a major role in the Java language. |
It is a middle-level language | It is a high-level language. |
C language does not support OOPS Concepts. | Java supports OOPS concepts, in which Inheritance the main property used for code reusability. |
In C, memory is allocated using Malloc | In Java, memory is allocated using a new keyword. |
The threading concept is not supported by C | Java supports Threading |
It is not portable | It is portable |
Default members of C are public | Default members of Java are private |
Storage classes are supported by C | Storage classes are not supported in Java |
The differences between C and Java are as follows:
What is the reason why Java came into existence?
Java is the first programming language that is used to write code on a virtual machine, so that is the reason why it is called JVM (Java Virtual Machine). This JVM is a new concept that is introduced in Java. It also provides a new feature called code reusability which is not possible in C.
Java | C++ |
Java is platform-independent | C++ is platform dependent |
Goto statement is not supported by Java | C++ supports the goto statement |
Multiple inheritances are supported in java by using interfaces | Multiple inheritances are supported in C++ |
Java doesn't support structures and unions | C++ does support unions and structures |
Java has built-in support for threading | C++ does not provide built-in support for threading |
Java is used for building applications | C++ is used for system programming |
Java uses both interpreter and compiler | C++ uses compiler only |
Compare both C++ and Java?
What are the prominent features of Java?
The following are the notable features in Java:
- Dynamic: Java is more dynamic when compared to C++ and C. Java is designed in such a way that it is adaptable to any the evolving environments.
- Simple: Java is very easy to learn and code.
- Object-oriented: In Java, everything is based on objects.
- Secure: Java provides a secure platform to develop safe and virus-free applications.
- Platform Independent: Unlike C and C++, when we compile Java code it is compiled into platform-independent bytecode rather than the platform-specific machine code.
- Portable: Java provides no implementation aspects for the specifications which make Java portable.
- Multithreaded: By this feature, we can perform multiple tasks simultaneously in Java.
- High-Performance: With the built-in Just-in-Time compiler, Java provides high performance.
- Robust: Java makes more efforts to eliminate errors by concentrating more on runtime checking and compile-time check.
What is a Class in Java?
Class is defined as a template or a blueprint that is used to create objects and also to define objects and methods.
Define Object in Java?
The instance of a class is called an object. Every object in Java has both state and behavior. The state of the object is stored in fields and the behavior of the objects is defined by methods.
How to write a basic Hello World program in Java?
class Mindmajix
{
public static void main(String args[ ]) {
System.out.println("Hello World");
}
}
Define JVM?
JVM is the abbreviation for Java Virtual Machine. It is a virtual machine that provides a runtime environment to write code. JVM is a part of JRE (Java Runtime Environment) and is used to convert the bytecode into machine-level language. This machine is responsible for allocating memory.
Name the memory areas that are allocated by JVM and explain the class loader in JVM?
There are totally five memory areas that are allocated by the JVM, and they are:
- Class Area
- Heap
- Stack
- Native Method Stack
- PC Register
ClassLoader: class loader is a subschema of JVM which is used to load class files. Whenever we run Java programs, the data will be first loaded from the classloader. There are mainly three in-built classloaders in JVM, they are:
- Application Classloader
- Bootstrap Classloader
- Extension Classloader
What is JDK?
Java Development Kit is one of the three prominent technology packages used in Java programming. JDK is used as a standalone component to run the Java programs by JVM and JRE. This kit is used to implement Java platform specifications, including class libraries and compiler.
What do you mean by JRE?
Java Runtime Environment (JRE) is a collection of software tools that are designed for the development of Java applications. This is a part of JDK, but it can be downloaded separately. JRE is mainly responsible for orchestrating the component activities.
Become a member and get full access of SRM PLACEMENT Assests.
What is the significant difference between JVM, JRE, and JDK?
We can understand the difference between JVM, JDK, and JRE by the following diagram:
- JVM: Java Virtual Machine is the main part of Java programming, which provides platform independence. JRE and JDK both contain JVM in order to run our Java programs.
- JDK: This development kit is mainly used for developing programs.
- JRE: Java Runtime Environment is mainly used for running Java programs.
Define the JIT compiler in Java?
Just In Time Compiler is the component of JRE, which is used to compile the bytecodes of the particular method into the native machine code. This compiled code of the method is directly called by JVM without interpreting it
Define variables in Java and explain with example?
Variables in Java can be defined as a basic storage unit of a program. It is a storage unit that holds the value during the program execution. Always the variable is assigned with a datatype.
For Example:
int a = 10;
What are the different types of variables in Java?
There are mainly three different types of variables available in Java, and they are:
- Static Variables
- Local Variables
- Instance Variables
Static Variables: A variable that is declared with the static keyword is called a static variable. A static variable cannot be a local variable, and the memory is allocated only once for these variables.
Local Variables: A variable that is declared inside the body of the method within the class is called a local variable. A local variable cannot be declared using the static keyword.
Instance Variables: The variable declared inside the class but outside the body of the method is called the instance variable. This variable cannot be declared as static and its value is instance-specific and cannot be shared among others.
Example:
class A{
int num=30;//instance variable
static char name=pranaya;//static variable
void method(){
int n=90;//local variable
}
}//end of class
What is Typecasting?
Typecasting in Java is done explicitly by the programmer; this is done to convert one data type into another data type.
Widening (automatically) – conversion of a smaller data type to a larger data type size.
byte -> short -> char -> int -> long -> float -> double
Narrowing (manually) – converting a larger type to a smaller size type
double -> float -> long -> int -> char -> short -> byte
- What is Type Conversion?
Type conversion can be defined as converting one data type to another data type automatically by the compiler.
There are two types of type conversions, and they are:
- Implicit type conversion
- Explicit type conversion.
What are the data types in Java?
Datatypes in Java specify the values and sizes that can be stored in the variables. There are mainly two types of data types; they are:
- Primitive Data Types
- Non-primitive Data Types
Become a member and get full access of SRM PLACEMENT Assests.