0% found this document useful (0 votes)
9 views

Java PDF

The document discusses the difference between JDK, JRE, and JVM in Java and defines key concepts like synchronization, threads exceptions, and operators in Java. JDK is for development and includes tools like compilers. JRE is for running applications and includes runtime pieces like the JVM. The JVM executes Java bytecode. Synchronization coordinates thread access to shared resources using locks. Exceptions in threads require careful handling. Common operators in Java perform operations on operands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Java PDF

The document discusses the difference between JDK, JRE, and JVM in Java and defines key concepts like synchronization, threads exceptions, and operators in Java. JDK is for development and includes tools like compilers. JRE is for running applications and includes runtime pieces like the JVM. The JVM executes Java bytecode. Synchronization coordinates thread access to shared resources using locks. Exceptions in threads require careful handling. Common operators in Java perform operations on operands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q1. What is the difference between JDK, JRE, and JVM in Java language? Q4.

Q4. Describe at Least 10 keyword's used in java with there function?


## JDK (Java Development Kit): + Public: The public keyword is an access modifier used to declare that a method,
+ JDK stands for Java Development Kit. It is a software development kit used for class, or field can be accessed by any other class. When a class or method is
developing Java applications. declared as public, it can be accessed from any other class in the same package or
+ JDK includes tools necessary for compiling, debugging, and running Java from any other package. This keyword plays a crucial role in encapsulation, as it
applications. It includes the Java compiler (javac), the Java Virtual Machine (JVM), allows certain members of a class to be accessible from outside the class.
and other tools like the Java Archive (JAR) utility. + Static: The static keyword is used to declare members that belong to the class
+ JDK also includes the Java Runtime Environment (JRE), so when you install JDK, rather than to any instance of the class. When a member (variable or method) is
you automatically get the JRE as well. declared as static, it can be accessed directly using the class name without
+ It is primarily used by developers for writing and compiling Java code. creating an instance of the class. Static variables are shared among all instances of
the class, while static methods can be invoked without creating an object of the
## JRE (Java Runtime Environment): class.
+ JRE stands for Java Runtime Environment. It is a software package that provides + Void: The void keyword is used to specify that a method does not return any
the runtime environment for Java applications to run. value. When a method's return type is declared as void, it means that the method
+ JRE includes the JVM (Java Virtual Machine), libraries, and other components performs some actions but does not produce a result that can be used by the
required to run Java applications but does not include any development tools like calling code. Void methods are commonly used for tasks such as printing output,
compilers. modifying object state, or performing calculations without returning a value.
+ Users who only want to run Java applications but not develop them need to + Final: The final keyword is used to declare constants, methods, or classes that
install the JRE on their systems. cannot be modified or extended. When a variable is declared as final, its value
cannot be changed once initialized. Similarly, when a method is declared as final,
## JVM (Java Virtual Machine): it cannot be overridden by subclasses. Additionally, when a class is declared as
+ JVM stands for Java Virtual Machine. It is an abstract computing machine that final, it cannot be subclassed, providing a way to prevent inheritance or extension
enables a computer to run Java programs. of certain classes.
+ JVM is responsible for executing Java bytecode. It takes the compiled Java code + Class: The class keyword is used to declare a class in Java. Classes are the
(bytecode) and translates it into machine code that the underlying operating building blocks of object-oriented programming in Java, encapsulating data and
system can understand. behavior within a single unit. A class serves as a blueprint for creating objects,
+ JVM provides platform independence by executing Java bytecode on any defining their structure and behavior. It encapsulates fields (variables) for data
platform that has a compatible JVM implementation. storage and methods for performing operations or actions.
+ There are different JVM implementations available, such as Oracle HotSpot, + Extends: The extends keyword is used to establish inheritance between classes
OpenJ9, and GraalVM. in Java. It allows one class (subclass) to inherit properties and methods from
another class (superclass). By using the extends keyword, a subclass can access
Q2. Define Synchronization in java programming? the members (fields and methods) of its superclass, promoting code reusability
In Java programming, synchronization refers to the coordination of multiple and facilitating the creation of hierarchical relationships between classes.
threads to ensure that they access shared resources in a controlled and orderly + Implements: The implements keyword is used to declare that a class
manner. When multiple threads are concurrently accessing shared data or implements one or more interfaces in Java. An interface defines a contract
resources, there is a possibility of data corruption or inconsistency if proper specifying a set of methods that a class must implement. When a class
synchronization mechanisms are not in place.Synchronization in Java is primarily implements an interface using the implements keyword, it must provide concrete
achieved using the synchronized keyword and through the use of explicit locks implementations for all methods declared in the interface. This allows for
provided by the java.util.concurrent.locks package. The synchronized keyword can achieving abstraction and polymorphism in Java, enabling classes to be treated
be applied to methods or code blocks to ensure that only one thread can execute uniformly based on their common interface.
the synchronized code at a time. When a thread enters a synchronized block or + This: The this keyword is a reference to the current object within a class. It can
method, it acquires the intrinsic lock associated with the object being be used to refer to instance variables and methods of the current object,
synchronized. Other threads attempting to execute synchronized code on the disambiguating them from local variables or parameters with the same name. The
same object must wait until the owning thread releases the lock. this keyword is commonly used to access instance variables or methods within
Eg: public class Counter { private int count = 0; public synchronized void constructors, setter methods, or instance methods, providing a way to access the
increment() { count++; } public synchronized int getCount() { return count; } } current object's state and behavior.
+ New: The new keyword is used to dynamically allocate memory for an object at
Q3. Write a note on Threads exception in java? runtime. When an object is created using the new keyword, memory is allocated
In Java, when working with threads, exceptions can occur within the threads' on the heap, and a reference to the newly created object is returned. This
execution. Handling exceptions in multithreaded environments requires careful reference can then be assigned to a variable, allowing the object to be accessed
consideration to ensure proper error handling and thread management. Here's a and manipulated throughout the program. The new keyword is fundamental to
brief note on handling exceptions in Java threads: object creation and instantiation in Java.
+ Unchecked Exceptions: Unchecked exceptions (those extending + Return: The return keyword is used to exit from a method and optionally return
RuntimeException) thrown within a thread will propagate to the top level of the a value to the calling code. When a method encounters a return statement, it
thread's run() method and terminate the thread's execution unless caught within immediately terminates and control is transferred back to the caller. If the
the thread itself. method has a return type other than void, the return statement must provide a
+ Checked Exceptions: Checked exceptions (those not extending value that matches the method's return type. This allows methods to produce
RuntimeException) thrown within a thread must be either caught or declared by results or output that can be used by other parts of the program, enabling data
the run() method using the throws clause. Failure to do so will result in a flow and information
Q Define exchange.
all operator in java programming
compilation error. In Java programming, an operator is a special symbol that performs
+ Thread Group: Java provides a mechanism to handle uncaught exceptions operations on operands. Operators are used to manipulate variables and
through the ThreadGroup class. By overriding the uncaughtException(Thread t, values in expressions. Java supports various types of operators, including
Throwable e) method of ThreadGroup, you can define custom behavior for arithmetic, assignment, comparison, logical, bitwise, and conditional
handling uncaught exceptions in threads belonging to that group. operators.
+ Default Uncaught Exception Handler: Since Java 5, you can also set a default + Arithmetic Operators: Addition +,Subtraction -,Multiplication *,Division
uncaught exception handler for all threads in your application by using the static /,Modulus %,Increment ++,Decrement —-
method + Assignment Operators: Assignment =,Addition assignment
Thread.setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler +=,Subtraction assignment -=,Multiplication assignment *=,Division
assignment /=,Modulus assignment %=
eh). This allows you to define a global exception handling strategy for uncaught
+ Comparison Operators: Equal to ==,Not equal to !=,Greater than
exceptions in threads.
>,Less than <,Greater than or equal to >=,Less than or equal to <=
+ Thread-Specific Exception Handling: In addition to the default uncaught
exception handler, each thread can have its own uncaught exception handler set
by calling + Logical Operators: Logical AND &&,Logical OR ||,Logical NOT !
Thread.setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh).
This allows for more granular control over exception handling within specific
+ Bitwise Operators: Bitwise AND &,Bitwise OR |,Bitwise XOR
threads. ^,Bitwise Complement ~,Left Shift <<,Right Shift >>,Unsigned Right Shift
+ Graceful Shutdown: Proper exception handling in threads is essential for >>>
ensuring a graceful shutdown of your application. Unhandled exceptions can lead
to unpredictable behavior and may leave resources in an inconsistent state.
+ Logging: It's advisable to log any uncaught exceptions to facilitate debugging + Conditional Operator (Ternary Operator): ? :
and troubleshooting. You can use logging frameworks like Log4j or
java.util.logging to log exceptions along with relevant context information.
concepts are fundamental in Java programming and are widely used to create
Q5. What is Applet and Visibility control in java programming? flexible and maintainable code.
1. In Java programming, "Applet" refers to a small application that is designed to
be executed within another application, typically a web browser. Applets were
popular in the early days of the internet for creating interactive web content. Q7. What is Class and Object in java ?
They are Java programs that are embedded within an HTML page and run in a ## Class:
Java-compatible web browser using a Java Virtual Machine (JVM). In Java, a class serves as a blueprint or template for creating objects. It defines
Applets have a few key characteristics: the attributes (also called fields or properties) and behaviors (methods) that
+ Embedded in HTML: Applets are typically embedded within an HTML page objects of that class will possess. Classes encapsulate the data and behavior
using the <applet> or <object> tag. associated with a particular entity or concept in the software.
+ Platform Independence: Like all Java programs, applets are platform- Key characteristics of a class:
independent, meaning they can run on any system that has a Java Virtual + Fields: These are variables that hold data associated with the class.
Machine (JVM) installed. They represent the state of an object. Fields can be of various data types,
+ Security Restrictions: Applets run within a restricted environment known as the including primitive types like int, double, boolean, or reference types like other
"sandbox." This restricts the applet's access to the local system, preventing it objects or arrays.
from performing certain potentially harmful operations such as accessing files on + Methods: Methods are functions defined within a class that
the user's computer. represent the behavior of objects. They can manipulate the class's data (fields)
+ Lifecycle Methods: Applets have lifecycle methods such as init(), start(), stop(), and perform operations specific to that class.
and destroy(), which are called by the browser or applet viewer to manage the + Constructors: Constructors are special methods used for initializing
applet's execution. objects. They are called when an object of the class is created and typically
2. As for "Visibility control" in Java programming, it could refer to various initialize the object's fields to specific values.
mechanisms for controlling the visibility or accessibility of classes, methods, and + Access modifiers: Java provides access modifiers such as public,
fields within Java code. private, and protected to control the visibility of class members (fields and
In Java, visibility control is primarily managed through access modifiers, which methods). This allows for encapsulation and ensures that sensitive data is not
include: directly accessible from outside the class.
+ public: Public members are accessible from any other class. + Inheritance: Java supports inheritance, allowing a class (subclass) to
+ private: Private members are accessible only within the same class. inherit fields and methods from another class (superclass). This facilitates code
+ protected: Protected members are accessible within the same package and by reuse and promotes a hierarchical organization of classes.
subclasses (even if the subclass is in a different package).default (package- + Polymorphism: Polymorphism allows objects of different classes to
private): If no access modifier is specified, the member is accessible only within be treated as objects of a common superclass. This enables flexibility in designing
the same package. and using classes by allowing different implementations of methods to be invoked
These access modifiers allow you to control the visibility of classes, methods, and based on the object's actual type.
fields in Java, helping to enforce encapsulation and maintainability in your code. ## Object:
By appropriately setting access modifiers, you can restrict access to certain parts An object is an instance of a class. It represents a specific entity or instance in the
of your code, which can improve security and prevent unintended usage or program's runtime environment. Objects have state (defined by their fields) and
modification. behavior (defined by their methods) as specified by the class from which they are
instantiated.
Q6. What is Constructor, methodoverloading, methodoverriding in java Key characteristics of an object:
programming? + State: An object's state is determined by the values of its fields.
These fields store the object's data, representing characteristics or properties of
## Constructor in Java:- In Java, a constructor is a special type of method that is the entity being modeled.
automatically invoked when an object is created. Its purpose is to initialize the + Behavior: An object's behavior is defined by the methods it
newly created object. Constructors have the same name as the class in which implements. These methods specify what actions an object can perform or how it
they are defined, and they do not have a return type, not even void. Constructors interacts with other objects in the system.
can take parameters, allowing for different ways to initialize objects.Constructors + Identity: Each object in Java has a unique identity, which
can be classified into two types: default constructors and parameterized distinguishes it from other objects. This identity is established when the object is
constructors. A default constructor is one that takes no arguments, and if no created and remains constant throughout its lifetime.
constructors are explicitly defined in a class, Java provides a default constructor. + Lifecycle: Objects have a lifecycle that includes creation,
Parameterized constructors, on the other hand, accept parameters, allowing for manipulation, and destruction. They are created using constructors, manipulated
custom initialization of objects.Constructors are essential for setting up the initial through method invocations, and eventually destroyed by the Java garbage
state of objects, ensuring they are in a valid state before they are used. They are collector when they are no longer referenced.
particularly useful for initializing instance variables and performing any necessary + Reference: Objects are typically accessed and manipulated through
setup tasks. references. A reference variable holds the memory address of the object rather
than the object itself. This allows multiple variables to refer to the same object,
## Method Overloading in Java: enabling sharing and passing of objects between different parts of the program.
Method overloading in Java refers to the ability to define multiple methods in a Q Discuss various looping statements in java programming.
class with the same name but with different parameter lists. This allows methods 1. for loop:- The for loop is the most commonly used looping statement in Java. It
to perform similar tasks but with different inputs or behaviors. Overloaded iterates over a block of code a fixed number of times. It consists of three parts:
methods must differ in the number or types of their parameters.Java resolves initialization, condition, and increment/decrement.
which overloaded method to invoke based on the number and types of + Initialization: It is the initial condition which is executed once when the loop
arguments passed during the method invocation. The compiler determines the starts. Here, we can initialize the variable, or we can use an already initialized
most appropriate method by matching the arguments with the parameter types variable. It is an optional condition.
of the available overloaded methods.Method overloading provides flexibility and + Condition: It is the second condition which is executed each time to test the
improves code readability by allowing developers to use the same method name condition of the loop. It continues execution until the condition is false. It must
for similar operations. It simplifies the API by grouping related methods under a return boolean value either true or false. It is an optional condition.
single name, making it easier to remember and use. + Increment/Decrement: It increments or decrements the variable value. It is
an optional condition..
## Method Overriding in Java: Syntax: for (initialization; condition; increment/decrement) { // code to be
Method overriding in Java is a feature that allows a subclass to provide a specific executed repeatedly }
implementation of a method that is already defined in its superclass. When a 2. while loop:- The while loop executes a block of code repeatedly as long as a
subclass overrides a method, it provides its own implementation, which is used specified condition is true. It checks the condition before executing the block.
instead of the superclass's implementation when the method is called on an Syntax:
object of the subclass.To override a method in Java, the subclass method must while (condition) { // code to be executed repeatedly }
have the same name, return type, and parameters as the superclass method. This 3. do-while loop:- The do-while loop is similar to the while loop, but it guarantees
ensures that the subclass method is a valid override of the superclass that the block of code is executed at least once, as it checks the condition after
method.Method overriding is essential for achieving polymorphic behavior in executing the block. Syntax: do {// code to be executed repeatedly } while
Java, where a single interface can be used to manipulate objects of different (condition);
classes. It allows subclasses to tailor the behavior of inherited methods to suit 4. for-each loop (Enhanced for loop):- The for-each loop is used for iterating over
their specific needs, promoting code reuse and extensibility.In summary, elements of arrays or collections. It simplifies the syntax of iterating over such
constructors initialize objects, method overloading enables multiple methods data structures and is particularly useful when you want to iterate through all
with the same name but different parameters, and method overriding allows elements without needing to know the index or size of the collection. Syntax:
subclasses to provide their own implementation of inherited methods. These for (datatype variable : array/collection) { / code to be executed for each
element }
5. Nested loops:- Java allows nesting loops within one another, meaning you can each platform, the language is referred to as "Write Once, Run
place one loop inside another loop. This is useful for tasks requiring multiple Anywhere" (WORA).
levels of iteration, such as working with matrices or multidimensional arrays.

Q Define inheritence in java programming?


Inheritance in Java is a mechanism by which a new class can inherit
properties and behaviors (methods) from an existing class, known as the Q. What are the top Java Features?
superclass or parent class. The class that inherits these properties and Java is one the most famous and most used language in the real world, there are
behaviors is called a subclass or child class.The main benefits of many features in Java that makes it better than any other language some of them
inheritance include code reusability, extensibility, and the ability to are mentioned below:
+ Simple: Java is quite simple to understand and the syntax
create hierarchical relationships among classes.In Java, inheritance is
+ Platform Independent: Java is platform independent means we can run the
implemented using the "extends" keyword. same program in any software and hardware and will get the same result.
Here's a basic syntax example: class Superclass { // Superclass + Interpreted: Java is interpreted as well as a compiler-based language.
members (fields and methods) } class Subclass extends Superclass { // + Robust: features like Garbage collection, exception handling, etc that make the
Subclass members (fields and methods) } language robust.
Types of inheritance in Java: + Object-Oriented: Java is an object-oriented language that supports the concepts
+ Single Inheritance: A subclass inherits from only one superclass. of class, objects, four pillars of OOPS, etc.
+ Multilevel Inheritance: A subclass inherits from another subclass, + Secured: As we can directly share an application with the user without sharing
the actual program makes Java a secure language.
creating a chain of inheritance.
+ High Performance: faster than other traditional interpreted programming
+ Hierarchical Inheritance: Multiple subclasses inherit from a single languages.
superclass. + Multiple Inheritance (through interfaces): Java does +Dynamic: supports dynamic loading of classes and interfaces.Distributed:
not support multiple inheritance of classes, but it supports multiple feature of Java makes us able to access files by calling the methods from any
inheritance through interfaces, where a class can implement multiple machine connected.
interfaces. Q Explain different data types in Java.
There are 2 types of data types in Java as mentioned below:
1. Primitive Data Type
Q What are the differences between C++ and Java?
2. Non-Primitive Data Type or Object Data type
C++ and Java are both widely used programming languages, but they 1. Primitive Data Type: Primitive data are single values with no special
have several differences in terms of syntax, memory management, capabilities. There are 8 primitive data types:
performance, platform independence, and more. Here's a comparison of + boolean: stores value true or false
some key differences between the two: + byte: stores an 8-bit signed two’s complement integer
Syntax: + char: stores a single 16-bit Unicode character
+ C++ is a statically typed language with a syntax similar to C, allowing + short: stores a 16-bit signed two’s complement integer
for low-level manipulation of memory and hardware. + int: stores a 32-bit signed two’s complement integer
+ long: stores a 64-bit two’s complement integer
+ Java is also statically typed but has a syntax more similar to C# or other
+ float: stores a single-precision 32-bit IEEE 754 floating-point
high-level languages. It enforces object-oriented principles more + double: stores a double-precision 64-bit IEEE 754 floating-point
rigorously. Memory Management: 2. Non-Primitive Data Type: Reference Data types will contain a memory address
+ In C++, memory management is done manually by the programmer of the variable’s values because it is not able to directly store the values in the
using pointers, memory allocation functions like new and delete, and memory.
libraries like the Standard Template Library (STL). Types of Non-Primitive are mentioned below:
+ Java, on the other hand, has automatic memory management through Strings/ Array/ Class/ Object /Interface
garbage collection. Programmers do not need to explicitly deallocate Q Explain public static void main(String args[]) in Java.
+ public: the public is the access modifier responsible for mentioning who can
memory; instead, the Java Virtual Machine (JVM) handles memory
access the element or the method and what is the limit. It is responsible for
management. Platform Independence: making the main function globally available. It is made public so that JVM can
+ Java was designed with the principle of "write once, run anywhere" invoke it from outside the class as it is not present in the current class.
(WORA), meaning Java code can run on any platform with a JVM + static: static is a keyword used so that we can use the element without initiating
installed, as Java bytecode is platform-independent. the class so to avoid the unnecessary allocation of the memory.
+ C++ code must be compiled separately for each platform, resulting in + void: void is a keyword and is used to specify that a method doesn’t return
platform-dependent binaries. anything. As the main function doesn’t return anything we use void.
Standard Libraries: + main: main represents that the function declared is the main function. It helps
JVM to identify that the declared function is the main function.
+ C++ provides the Standard Template Library (STL) for data structures
+ String args[]: It stores Java command-line arguments and is an array of type
and algorithms, but its standard library is not as extensive as Java's. java.lang.String class.
+ Java's standard library (Java API) offers a wide range of classes and
utilities for various tasks, including networking, file I/O, GUI Q Java Inheritance (Subclass and Superclass)
development (through Swing or JavaFX), and more. In Java, it is possible to inherit attributes and methods from one class to another.
We group the "inheritance concept" into two categories:
Q Is Java Platform Independent if then how? + subclass (child) - the class that inherits from another class
Yes, Java is a Platform Independent language. Unlike many programming + superclass (parent) - the class being inherited from
languages javac compiler compiles the program to form a bytecode To inherit from a class, use the extends keyword.
In the example below, the Car class (subclass) inherits the attributes and methods
or .class file. This file is independent of the software or hardware
from the Vehicle class (superclass):
running but needs a JVM(Java Virtual Machine) file preinstalled in the class Vehicle {
operating system for further execution of the bytecode.Although JVM is protected String brand = "Ford";
platform dependent, the bytecode can be created on any System and public void honk() {
can be executed in any other system despite hardware or software being System.out.println("Tuut, tuut!");
used which makes Java platform independent.One of the most well- }
known and widely used programming languages is Java. It is a }
class Car extends Vehicle {
programming language that is independent of platforms. Java doesn't
private String modelName = "Mustang";
demand that the complete programme be rewritten for every possible public static void main(String[] args) {
platform. The Java Virtual Machine and Java Bytecode are used to Car myCar = new Car();
support platform independence. Any JVM operating system can run this myCar.honk();
platform-neutral byte code. The application is run after JVM translates System.out.println(myCar.brand + " " + myCar.modelName);
the byte code into machine code. Because Java programmes can operate }
on numerous systems without having to be individually rewritten for }
Q What is the Wrapper class in Java?
Wrapper, in general, is referred to a larger entity that encapsulates a smaller Q Exception Handling in Java
entity. Here in Java, the wrapper class is an object class that encapsulates the The Exception Handling in Java is one of the powerful mechanism to handle the
primitive data types. runtime errors so that the normal flow of the application can be maintained.
The primitive data types are the ones from which further data types could be In this tutorial, we will learn about Java exceptions, it's types, and the difference
created. For example, integers can further lead to the construction of long, byte, between checked and unchecked exceptions.
short, etc. On the other hand, the string cannot, hence it is not primitive. What is Exception in Java?
Getting back to the wrapper class, Java contains 8 wrapper classes. They are Dictionary Meaning: Exception is an abnormal condition.
Boolean, Byte, Short, Integer, Character, Long, Float, and Double. Further, custom In Java, an exception is an event that disrupts the normal flow of the program. It
wrapper classes can also be created in Java which is similar to the concept of is an object which is thrown at runtime.
Structure in the C programming language. We create our own wrapper class with
the required data types.
try The "try" keyword is used to specify a block where we should place an
Q What is a Framework in Java?
exception code. It means we can't use try block alone. The try block
Frameworks are sets of classes and interfaces that provide a ready-made
architecture. It is not necessary to define a framework in order to implement new must be followed by either catch or finally.
features or classes. As a result, an optimal object-oriented design includes a
framework containing a collection of classes that all perform similar tasks. The
framework can be used in a variety of ways, such as by calling its methods,
extending it, and supplying “callbacks”, listeners, and other implementations.
Some of the popular frameworks in java are:
Spring/ Hibernate/ Struts/ Google Web Toolkit (GWT)/ JavaServer Faces (JSF) catch The "catch" block is used to handle the exception. It must be

preceded by try block which means we can't use catch block alone. It
Q What is Multithreading and How it is Different from Multitasking?
Multithreading is a specialized form of multitasking. Process-based multitasking can be followed by finally block later.
refers to executing several tasks simultaneously where each task is a separate
independent process is Process-based multitasking.
Example: Running Java IDE and running TextEdit at the same time. Process-based
multitasking is represented by the below pictorial which is as follows:
Thread-based multitasking refers to executing several tasks simultaneously where
each task is a separate independent part of the same program known as a thread. finally The "finally" block is used to execute the necessary code of the
For example, JUnits uses threads to run test cases in parallel. Henceforth,
process-based multitasking is a bigger scenario handling process where threads program. It is executed whether an exception is handled or not.
handle the details. It is already discussed to deeper depth already with visual
aids.

Q java package
A java package is a group of similar types of classes, interfaces and sub- throw The "throw" keyword is used to throw an exception.
packages.Package in java can be categorized in two form, built-in package and
user-defined package.There are many built-in packages such as java, lang, awt,
javax, swing, net, io, util, sql etc.
There are two types of packages in Java
User-defined packages
Build In packages throws The "throws" keyword is used to declare exceptions. It specifies that
Advantage of Java Package
1) Java package is used to categorize the classes and interfaces so that they can there may occur an exception in the method. It doesn't throw an
be easily maintained.
exception. It is always used with method signature.
2) Java package provides access protection.
3) Java package removes naming collision.
The package keyword is used to create a package in java.
package mypack;
public class Simple{ public class JavaExceptionExample{
public static void main(String args[]){ public static void main(String args[]){
System.out.println("Welcome to package"); try{
} int data=100/0;
} }catch(ArithmeticException e){System.out.println(e);}
System.out.println("rest of the code...");
} }
Q Super Keyword in Java
The super keyword in Java is a reference variable which is used to refer Q What is Java?
immediate parent class object. Java is a programming language that was originally meant to run on set-top boxes
Whenever you create the instance of subclass, an instance of parent class is and televisions. It was invented in 1995 for Sun Microsystems, but you can see it
created implicitly which is referred by super reference variable. almost everywhere now, being used for supercomputers and data centers.It’s a
Usage of Java super Keyword fast, secure, and reliable programming language that has simple rules and syntax
super can be used to refer immediate parent class instance variable. based on the C programming languages.Many developers choose Java over
super can be used to invoke immediate parent class method. Python, Ruby, Swift, C, and other modern languages. If you’re looking to be in
super() can be used to invoke immediate parent class constructor. demand, learning Java can be a great first step. Let’s see what’s so basic about
1) super is used to refer immediate parent class instance variable. Java.It’s easy to write and easy to understand. It’s not too difficult to maintain
We can use super keyword to access the data member or field of parent class. It is either. The code is easily debuggable and less complex than any of the C
used if parent class and child class have same fields. languages. It was based on such languages but had much of the complexities
2) super can be used to invoke parent class method removed to allow for a more streamlined coding experience.We use Java
The super keyword can also be used to invoke parent class method. It should be programming everywhere. We use Java to create standalone programs, web
used if subclass contains the same method as parent class. In other words, it is applications, and web services. We can create distributed enterprise applications
used if method is overridden. using Java EE frameworks.
Q What is difference between JavaScript and Java? What is Core Java?
Some of the key differences between JavaScript and Java are: Java SE is also called Core Java. It is the set of libraries that are part of standard
+ Java is Object Oriented Programming Language. But, JavaScript is an Object Oriented Scripting
language. + Java code runs in a virtual
machine or browser (Applets) where JavaScript code runs on browser.
java installation. For example, the Collections framework is part of Core Java. But,
Servlet/JSP is part of Java Enterprise Edition.

You might also like