Java PDF
Java PDF
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.