Edureka Java Ebook

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

MASTERING JAVA WITH EDUREKA

TABLE OF CONTENTS

1. INTRODUCTION TO JAVA PROGRAMMING 3


Why Java programming?
Java Features
Java Applications

2. JAVA INSTALLATION 5
Downloading Java JDK
Java Environment Setup

3. JAVA FUNDAMENTALS 6
JVM, JRE and JDK
Data Types in Java
Variables & Keywords
Operators in Java
Methods in Java
Access Modi ers

4. JAVA FLOW OF CONTROL 9


Decision Making Statements
Iterative Statements

IN: 9606058406
sales@edureka.co
US: 18338555775
MASTERING JAVA WITH EDUREKA

5. OOPS IN JAVA 11
TABLE OF CONTENTS

Classes & Objects


Abstraction
Encapsulation
Inheritance
Polymorphism

6. DATA STRUCTURES IN JAVA 14


Linear Data Structures
Hierarchical Data Structures

7. ADVANCED JAVA CONCEPTS 16


Multithreading in Java
Exception Handling
Java DataBase Connectivity (JDBC)

8. JAVA PRACTICE PROGRAMS 18

9. TOP 30 JAVA INTERVIEW QUESTIONS 19

10. CAREER GUIDANCE 20


How to become a Java Professional?
Edureka's Structured Training Programs

IN: 9606058406
sales@edureka.co
US: 18338555775
3 WWW.EDUREKA.CO/JAVA

Chapter 1

INTRODUCTION TO
JAVA PROGRAMMING

Java has become an important programming language in today’s world with


its universal presence in our day-to-day life. Released by Sun Microsystems in
1995, this class-based object-oriented program is often related to the likes of
C & C++ due to its similarity in coding. Often termed as the programming
language where you can ‘Write Once, Run Anywhere’. This principle of Java
makes it an eye-catching language!

1.1 What is Java Programming?

Java is an object-oriented language with a C/C++-like syntax that is familiar to many programmers.
It is dynamically linked, allowing new code to be downloaded and run, but not dynamically typed.

01 Concurrent 02 OOPs 03 WORA

Java is concurrent where you Java is class-based and an Java is a platform


can execute many statements object-oriented independent programming
instead of sequentially programming language. language that follows the
executing it. logic of “Write Once, Run
Anywhere”.

These are the reasons which attract the programmers the most. Java programs can be executed
across any machine having JRE. JRE is compatible with all devices, say, mobile phones, PCs as well
as any OS like Linux, Windows, Mac, Android, etc. We will learn more about JRE, later in this book.

IN: 9606058406
sales@edureka.co
US: 18338555775
4 WWW.EDUREKA.CO/JAVA

JAVA features

Easy to Learn & Free and Open High-Level


Use Source Language

Highly Object-Oriented Comprehensive Set of


Portable Programming Libraries

JAVA APPLICATIONS

Web Servers Development Game Development Desktop GUI Development

Mobile Application Big Data & Cloud-Based Scientific & Mathematical


Development App Development Code Development

IN: 9606058406
sales@edureka.co
US: 18338555775
5 WWW.EDUREKA.CO/JAVA

Chapter 2

JAVA INSTALLATION
2.1 Downloading Java JDK
S 1. Go to the Java Downloads Page and click on the option of Download
T 2. Choose the download link according to your matching system configuration
E
3. Once the file is downloaded, run the installer and keep clicking on Next, till you finally get a
P
dialog box, which says, you have finished downloading.
S

2.2 Java Environment Setup on Windows

1. Go to 'Start' and search for ‘System’. Click on ‘System’ and go to 'Advanced System Settings'
2. Now, click on ‘Environment Variables’ under the ‘Advanced’ tab
3. Next, under the 'System Variables' choose 'New'
4. Enter the variable name as ‘JAVA_HOME’ and the full path to the Java installation directory as
per your system as shown below:

5. Next, you have to edit the path. For that, select 'path' under 'System Variable' and click on 'Edit'
6. Under ‘Variable value’, at the end of the line, enter the following path – %JAVA_HOME%bin;
7. Now, you can click ‘OK’ and you are done
8. Now to cross-check the installation, just run the following command in Command Prompt, it
should display the installed version of Java in your system

java -version

IN: 9606058406
sales@edureka.co
US: 18338555775
6 WWW.EDUREKA.CO/JAVA

Chapter 3

JAVA FUNDAMENTALS
3.1 JVM, JRE and JDK
Java applications are called WORA (Write once
Run Anywhere) because of their ability to run a
code on any platform. This is done only because of
JVM (Java Virtual Machine). The JVM is a Java
platform component that provides an
environment for executing Java programs. JVM
interprets the bytecode into machine code which
is executed in the machine in which the Java
program runs.
The JRE software builds a runtime environment The Java Development Kit (JDK) is a software
in which Java programs can be executed. The JRE development environment used to develop
is the on-disk system that takes your Java code, Java applications and applets. It contains JRE
combines it with the needed libraries, and starts and several development tools, an
the JVM to execute it. The JRE contains libraries interpreter/loader (java), a compiler (javac),
and software needed by your Java programs to an archiver (jar), a documentation generator
run. JRE is a part of JDK but can be downloaded (javadoc) accompanied with another tool.
separately.

3.2 Data Types in Java


A data type is an attribute of a variable that tells the compiler or interpreter how the programmer
intends to use the variable. It defines the operations that can be done on the data and what type of
values can be stored. According to the properties they possess, they are divided into two groups:

01 Primitive Data Types 02 Non-Primitive Data Types

Boolean Data Type Int Data Type Strings Interface


Byte Data Type Long Data Type Arrays Enumerations
Char Data Type Float Data Type Classes
Short Data Type Double Data Type

IN: 9606058406
sales@edureka.co
US: 18338555775
7 WWW.EDUREKA.CO/JAVA

3.3 Variables and Keywords


Variable in Java is the basic unit of storage. It Keywords are predefined which have a unique
acts as a container and is used to hold data values. meaning and functionality in the Java
The values held by the variable can be changed programming language. These keywords are also
during the execution of the program. Every known as reserved keywords which means they
variable is assigned a data type. Variable is a name cannot be used as a variable name, class, method,
given to a memory location. A variable is declared or any other identifier. There are 57 reserved
by specifying the following parameters: keywords in Java, some which are listed below:
abstract this enum
1. Datatype: Type of data stored in the variable
continue break return
2. Variable name: A unique name of the variable
for implements instanceof
3. Value: The initial value stored in the variable
new throw short
switch import interface
int age = 50 ;
package public static
float weight = 50.60;
private throws void

3.4 Operators in Java


Operators in Java are Type Operators
used for operations
between two values or Arithmetic +, -, *, /, %, **, //
variables. The output
varies according to the Assignment =, +=, -=, *=, %=, **=, //=, |=, ^=, &=
type of operator used in Relational ==, !=, >, <, <=,>=
the operation. We can
call operators as special Logical &&, ||, !
symbols or constructs to
manipulate the values of Unary ++, --, !
the operands. Consider Bitwise &, |, ^, ~
the expression 2 + 3 = 5,
here 2 and 3 are Ternary (Condition) ? (Statement1) : (Statement2);
operands and + is called
operator. Shift <<,>>,>>>

3.5 Methods in Java


A method is basically a set of code which is referred to by name and can be called or invoked at any
point in a program, just by utilizing the method’s name. Each method is given its own name. When
that name is in a program, the execution branches to the body of that method.

IN: 9606058406
sales@edureka.co
US: 18338555775
8 WWW.EDUREKA.CO/JAVA

How to create a method in Java? Every Java program must have the 'main' method.
A method in Java must be declared within a It is the entry point for the Java Compiler, from
specific class. It is defined with the name of the where it starts the execution and follows the
method, followed by parentheses “()”. Java order specified in the rest of the program.
provides some pre-defined methods, such as
public static void main (String args[])
System.out.println(), etc.
public static dataType methodName
public
(dataType x, dataType y) static
{ void
// body main
}
String args[]

3.6 Access Modifiers in Java


Access modifiers in Java are used to specify the access levels for classes, variable methods, and
constructors. It helps in updating the value of a variable. They are also known as access/visibility
modifiers. There are four access modifiers keywords in Java and they are:

DEFAULT ACCESS MODIFIER


1
When no access modifier is specified for a particular class, method or a data member, it is said to be
having the default access modifier. The data members, class or methods which are not declared utilizing
any entrance modifiers, will have default modifier which is accessible only inside a similar bundle. It
means you do not explicitly declare an access modifier for a class, field, method, etc.

PRIVATE ACCESS MODIFIER


2 The methods or data members that are declared as private are only accessible within the class in which
they are declared. Top-level classes or interfaces cannot be declared as private in light of the fact that
'private' signifies “just visible inside the enclosing class“. If a class has a private constructor then you
cannot create the object of that class from outside the class.

PUBLIC ACCESS MODIFIER


3 The public access modifier is specified using the keyword public. It has a broadest scope among all other
access modifiers. Classes, methods or data members which are declared as public are accessible
anywhere throughout the program. There is no restriction on the scope of public data members.

PROTECTED ACCESS MODIFIER


4 The protected access modifier is specified using the keyword protected. The methods or data members
declared as protected are accessible within the same package or subclasses in a different package.
Protected members can be accessed only in the child or derived classes.

IN: 9606058406
sales@edureka.co
US: 18338555775
9 WWW.EDUREKA.CO/JAVA

Chapter 4

JAVA FLOW CONTROL


A control statement in Java determines whether the other statements will be executed or not.

4.1 Decision Making Statements


Statements that determine which statement to execute and when are known as decision-making
statements. The flow of the execution of the program is controlled by the control flow statement.
There are four decision-making statements available in Java.

1 if Statement 2 if..else Statement


The 'if' statement determines whether a In this statement, in case the condition
code should be executed based on the specified is true, then 'if' block is executed.
specified condition. Otherwise, the 'else' block is executed.

if (condition) { if (condition) {
Statement 1; //executed if condition is Statement 1; //executed if condition
true is correct
} Statement 2; //executed irrespective } else Statement 2; /*executed if
of the condition condition is false*/

3 Nested if Statement 4 switch-case Statement


An 'if' present inside another 'if' block is A 'switch' statement in Java is used to
known as a nested 'if' block. It is similar to an execute a single statement from multiple
if..else statement, except they are defined conditions. The switch statement can be
inside another if..else statement. used with short, byte, int, long, enum types.

if (condition1) { switch(expression) {
Statement 1; case x:
if (condition2) { // code block
Statement 2; /*executed 'if' 2nd break;
case y:
condition is correct*/
// code block
} else {
break;
Statement 3; /*executed if second
default:
condition is false*/ // code block
}} }

IN: 9606058406
sales@edureka.co
US: 18338555775
10 WWW.EDUREKA.CO/JAVA

4.2 Iterative Statements


Statements that execute a block of code in a loop until a specified condition is met are known as
Iterative statements. Java provides the user with three types of loops:

1 while Loop 2 do-while Loop


A while loop in Java is used to iterate over a It is similar to a while loop, but in a while
block of code or statements as long as the loop, the condition is evaluated before the
test expression is true. You can use this, in execution of the loop’s body but in a do-
case number of iterations are not specified. while loop, the condition is evaluated after
the execution of the loop’s body.
while (condition) {
/*code block to be executed*/ do { /*code block to be executed*/
} } while (condition)

3 for Loop Example


The for loop in Java is used to iterate and
evaluate a code multiple times. When the public class Edureka {
number of iterations is known by the user, it is public static void
recommended to use the for loop. pyramidPattern(int n) {
for-each
for (int i=0; Loop{
i<n; i++)
for (initialization; condition; increment/decrement)
for (int j=n-i; j>1; j--)
{
statement; { System.out.print(" "); }
} for (int j=0; j<=i; j++ )
{ System.out.print("* "); }
System.out.println();
4 for-each Loop }
}
The traversal of elements in an array can be
done by the for-each loop. The elements
public static void main(String
present in the array are returned one by one.
args[]) //driver function
{ int n = 5;
for (type var : array)
{ pyramidPattern(n);
statements using var; }
}
}

IN: 9606058406
sales@edureka.co
US: 18338555775
11 WWW.EDUREKA.CO/JAVA

Chapter 5

OBJECT-ORIENTED
PROGRAMMING IN JAVA
Object-Oriented Programming (OOP) refers to a type of programming in which programmers define the
data type of a data structure and the type of operations that can be applied to the data structure.  An
object-based application in Java is based on declaring classes, creating objects from them and interacting
between these objects. Let's take a look at the building blocks of object-oriented programming:

5.1 Classes & Objects


Class in Java is a blueprint from which an object is created. It is a logical entity that helps in defining the
behavior and properties of an object. A class can only be accessed from outside via its instance.

01 Built-in Classes 02 User Defined Classes


Built-in classes in Java are the classes that comes As the name suggests, a custom or user-defined
bundled within predefined packages in Java. E.g: class is a class that is created by a user. It will
Java.Lang.String Java.Lang.Exception contain the class members as defined by the
Java.Lang.System Java.Lang.Object user.

Class Elements Class Syntax


A Java class generally consists of the following:
1. Fields <access specifier> class
2. Methods <classname>{
3. Constructors //classbody
4. Blocks }
5. Nested Classes

Object in Java is a real-world entity that has its own property and behavior. These are considered to be
the fundamental concepts of Java and uses classes as its blueprint. A Java program can have as many
objects as required. An object in Java typically consists of the following: 
1. State: This is represented by the attributes and properties of an object.
2. Behavior: This is defined by the methods of an object.
3. Identity: This provides a unique name to an object and enables the communication between them.

IN: 9606058406
sales@edureka.co
US: 18338555775
12 WWW.EDUREKA.CO/JAVA

5.2 Abstraction in Java


Abstraction refers to the quality of dealing with
public interface EduInterface{
ideas rather than events. It basically deals with public void show();
hiding the details and showing the essential public void run();
things to the user. In Java, you can achieve }
abstraction in two ways:
public class eduDemo
1. Abstract Class: Abstract class contains the
implements EduInterface{
‘abstract’ keyword and cannot be instantiated. public void show(){
It  can contain abstract as well as concrete //implementation
methods. }
2. Interface: An interface in Java is a collection of public void run(){
//implementation
abstract methods and static constants. In an
}
interface, each method is public and abstract }
but it does not contain any constructor.

5.3 Encapsulation in Java

Encapsulation refers to the process of wrapping


class Student {
up of data under a single unit. It is the mechanism private String name;
that binds code and the data it manipulates. public String getName() {
Another way to think about encapsulation is, it is return name;
}
a protective shield that prevents the data from public void setName(String name)
being accessed by the code outside this shield. In {
this, the variables or data of a class is hidden this.name = name;
}
from any other class and can be accessed only
}
through any member function of own class in public class Main {
which they are declared. public static void main(String[]
Encapsulation in Java can be achieved by:  args) {
Student s=new Student();
1. Declaring the variables of a class as private. s.setName("Harry Potter");
2. Providing public setter and getter methods to System.out.println(s.getName());
modify and view the values of the variables. }
}

IN: 9606058406
sales@edureka.co
US: 18338555775
13 WWW.EDUREKA.CO/JAVA

5.4 Inheritance in Java


class Animal {
Inheritance is an integral part of Java OOPs void eat() {
System.out.println(“eating…”); }
which lets the properties of one class to be
}
inherited by the other. It basically, helps in class Dog extends Animal {
reusing the code and establish a relationship void bark() {
System.out.println(“barking…”); }
between different classes. }
class Cat extends Animal {
void meow() {
System.out.println(“meowing…”); }
TYPES OF INHERITANCE }
Single Inheritance class TestInheritance3 {
public static void main(String
Multilevel Inheritance args[]){
Cat c=new Cat();
Hierarchical Inheritance c.meow();
c.eat();
Hybrid Inheritance }
}

5.5 Polymorphism in Java

Polymorphism in OOP is the ability of an entity class Calculator


{
to take several forms. In other words, it refers to int add(int x, int y)
the ability of an object (or a reference to an {
object) to take different forms of objects. It return x+y;
}
allows a common data-gathering message to be int add(int x, int y, int z)
sent to each class. Polymorphism encourages a {
return x+y+z;
concept called ‘extendibility’ which means an
}
object or a class can have its uses extended.  }
public class Test
{
public static void main(String args[])
TYPES OF POLYMORPHISM {
Calculator obj = new Calculator();
Static Polymorphism System.out.println(obj.add(100, 200));
System.out.println(obj.add(100, 200,
Dynamic Polymorphism 300));
}
}

IN: 9606058406
sales@edureka.co
US: 18338555775
14 WWW.EDUREKA.CO/JAVA

Chapter 6

DATA STRUCTURES IN JAVA


A Data Structure is a way of storing and organizing data in a computer so that it can be used efficiently.
It provides a means to manage large amounts of data efficiently. These are categorized into two types:

6.1 Linear Data Structures


Linear data structures in Java are those whose elements are sequential and ordered in a way so that
there is only one first element and has only one next element, there is only one last element and has
only one previous element, while all other elements have a next and a previous element.

ARRAYS
1
An array represents a group of similar data type elements, accessed by an index. The size of an array must
be provided before storing data.

2 LINKED LIST
A linked list is a linear data structure with the collection of multiple nodes, where each element stores its
own data and a pointer to the location of the next element. The last link in a linked list points to null,
indicating the end of the chain. An element in a linked list is called a node. The first node is called the head.
The last node is called the tail.

STACKS
3 Stack, an abstract data structure, is a collection of objects that are inserted and
removed according to the last-in-first-out (LIFO) principle. Objects can be inserted
into a stack at any point of time, but only the most recently inserted (that is, “last”)
object can be removed at any time.

QUEUES
4
Queues are also another type of abstract data structure. Unlike a stack, the queue is
a collection of objects that are inserted and removed according to the first-in-first-
out (FIFO) principle. That is, elements can be inserted at any point of time, but only
the element that has been in the queue the longest can be removed at any time.

IN: 9606058406
sales@edureka.co
US: 18338555775
15 WWW.EDUREKA.CO/JAVA

6.2 Hierarchical Data Structures


Hierarchical data structures in Java store elements on the basis of their hierarchy. These types of data
structures are efficient for visualizing and retrieving the data.

BINARY TREE
1
Binary Tree is a hierarchical tree data structure in which each node
has at most two children, which are referred to as the left child and
the right child. Each binary tree has the following group of nodes:
Root Node: It is the topmost node and often referred to as the
main node because all other nodes can be reached from the root
Left Sub-Tree, a sub- binary tree on the LHS of the Root Node
Right Sub-Tree, a sub-binary tree on the RHS of the Root Node

2 BINARY HEAP
Binary Heap is a complete binary tree, which answers to the heap property. In simple terms, it is a variation
of a binary tree with the following properties:
Heap is a complete binary tree: A tree is said to be complete if all its levels, except possibly the deepest,
are complete. This property of Binary Heap makes it suitable to be stored in an array.
Follows heap property: A Binary Heap is either a Min-Heap or a Max-Heap.
Min Binary Heap: For every node in a heap, node’s value is lesser than or equal to values of the children.
Max Binary Heap: For every node in a heap, the node’s value is greater than or equal to values of the
children.

HASH TABLES
3
Imagine that you have an object and you want to assign a key to it to make searching very easy. To store that
key/value pair, you can use a simple array like a data structure where keys (integers) can be used directly as
an index to store data values. However, in cases where the keys are too large and cannot be used directly as
an index, a technique called hashing is used.

In hashing, the large keys are converted into small keys


by using hash functions. The values are then stored in a
data structure called a hash table. A hash table is a data
structure that implements a dictionary ADT, a structure
that can map unique keys to values.

In general, a hash table has two major components:


1. Bucket Array
2. Hash Function

IN: 9606058406
sales@edureka.co
US: 18338555775
16 WWW.EDUREKA.CO/JAVA

Chapter 7

ADVANCE JAVA CONCEPTS


This chapter will introduce you to some of the advanced concepts of Java which serves major
functionalities in making a program efficient.

7.1 Multithreading in Java


A multithreaded program contains two or more parts that can run concurrently. Each part of such a
program is called a thread and each thread defines a separate path of execution. Thus, multithreading
is a specialized form of multitasking.  Java’s multithreading system is built upon the Thread class, its
methods, and its companion interface i.e., Runnable.

Java lets you create a thread in the following two ways:-


HOW TO CREATE
1. By implementing the Runnable interface
A JAVA THREAD? 2. By extending the Thread

class MyThread implements Runnable {


String name; OUTPUT
Thread t;
CREATING MULTIPLE THREADS

New thread: Thread[One,5,main]


MyThread (String threadname){
name = threadname; New thread: Thread[Two,5,main]
t = new Thread(this, name); New thread: Thread[Three,5,main]
System.out.println("New thread: " + t); One: 5
t.start();
} Two: 5
public void run() { Three: 5
try { for(int i = 5; i > 0; i--) One: 4
{ System.out.println(name + ": " + i);
Thread.sleep(1000); Two: 4
} Three: 4
}catch (InterruptedException e) { One: 3
System.out.println(name + "Interrupted");
Three: 3
}
System.out.println(name + " exiting."); Two: 3
} } One: 2
Three: 2
class Main {
public static void main(String args[]) { Two: 2
new MyThread("One"); One: 1
new MyThread("Two"); Three: 1
new MyThread("Three");
try { Thread.sleep(10000); Two: 1
} catch (InterruptedException e) { One exiting.
System.out.println("Main thread Two exiting.
Interrupted");
Three exiting.
}
System.out.println("Main thread exiting."); Main thread exiting.
} }

IN: 9606058406
sales@edureka.co
US: 18338555775
17 WWW.EDUREKA.CO/JAVA

7.2 Exception Handling in Java


Errors arise unexpectedly and can result in disrupting the normal flow of execution. This is something
that every programmer faces at one point or the other while coding.
Java, being the most prominent object-
oriented language, provides a powerful
mechanism to handle these
errors/exceptions called Exception
Handling.  All exception and error types
are subclasses of class Throwable, which
is the base class of the hierarchy. One
branch is headed by Error which occurs
at run-time and the other by Exception
that can happen either at compile-time
or run-time.

EXCEPTION HANDLING METHODS

TRY FINALLY THROWS

2 4
1 3 5
CATCH THROW

7.3 Java DataBase Connectivity (JDBC)


JDBC is a standard Java API for database- The JDBC API supports both two-tier and three-
independent connectivity between the Java tier processing models for database access but
programming language and a wide range of in general, JDBC Architecture consists of two
databases. This application program interface layers:
lets you encode the access request statements, 1. JDBC API: This provides the application-to-
in SQL. They are then passed to the program JDBC Manager connection.
that manages the database. It mainly involves 2. JDBC Driver API: This supports the JDBC
opening a connection, creating a SQL Database, Manager-to-Driver Connection.
executing SQL queries, and then arriving at the
output.

IN: 9606058406
sales@edureka.co
US: 18338555775
18 WWW.EDUREKA.CO/JAVA

Chapter 8

JAVA PRACTICE PROGRAMS


8.1 Palindrome Program using For Loop 8.3 Recursive Binary Search

public class PalindromeProgram {


public static void main(String[] args) { public class BinarySearch {
int n=1234521, rev=0, rem, temp; // Java implementation of recursive Binary Search
temp = n; // Returns index of x if it is present in
for( ;n != 0; n /= 10 ) arr[l..h], else return -1
{ int binarySearch(int a[], int l, int h, int x)
rem = n % 10;
{
rev= rev* 10 + rem;
} if (h >= l) {
if (temp== rev) int mid = l + (h - l) / 2;
System.out.println(temp + " is a // If the element is present at the middle itself
palindrome."); if (a[mid] == x)
else
return mid;
System.out.println(temp + " is not a
palindrome."); // If element is smaller than mid, then it can
} only be present in left subarray
} if (a[mid] >x)
8.2 Calculate Permutation & Combination return binarySearch(arr, l, mid - 1, x);
// Else the element can only be present in right
package Edureka; subarray
import java.util.Scanner; return binarySearch(arr, mid + 1, h, x);
public class nprandncr { }
//calculating a factorial of a number
public static int fact(int num)
// We reach here when element is not present in
{ array
int fact=1, i; return -1;
for(i=1; i<=num; i++) }
{
fact = fact*i;
public static void main(String args[])
} {
return fact; BinarySearch ob = new BinarySearch();
} int a[] = { 20, 30, 40, 10, 50 };
public static void main(String args[])
{
int n = a.length;
int n, r; int x = 40;
Scanner scan = new Scanner(System.in); int res = ob.binarySearch(a, 0, n - 1, x);
System.out.print("Enter Value of n : "); if (res == -1)
n = scan.nextInt();
System.out.print("Enter Value of r : ");
System.out.println("Element not present");
r = scan.nextInt();
// NCR and NPR of a number else
System.out.print("NCR = " +(fact(n)/(fact(n- System.out.println("Element found at index " +
r)*fact(r)))); res);
System.out.print("nNPR = " +(fact(n)/(fact(n-
}
r))));
} }
}
JAVA PRACTICE PROGRAM EXAMPLES
IN: 9606058406
sales@edureka.co
US: 18338555775
19 WWW.EDUREKA.CO/JAVA

Chapter 9

FREQUENTLY
ASKED
INTERVIEW
QUESTIONS
Java has dominated the programming world since the
early 2000s and has managed to keep its magic intact
with its platform independence till date. This chapter
covers the questions that will help you in your Java
Interviews and open up various career opportunities as a
Java aspirant.

1. Explain JDK, JRE and JVM. 21. Explain what is MVC?


2. Explain public static void main(String args[]) in Java. 22. Describe the Collection hierarchy in Java.
3. Why Java is platform-independent? 23. What is Arraylist in Java?
4. Why Java is not 100% Object-oriented? 24. How will you reverse a List?
5. What are Wrapper classes in Java? 25. What is a Priority Queue in Java?
6. What are constructors in Java? 26. What is the HashSet class in Java and how does it store
7. What is a singleton class in Java? elements?
8. Differentiate between Arraylist and Vector in Java. 27. What is the difference between Error and Exception?
9. What is the difference between equals() and == in Java? 28. Differentiate between final, finally, and finalize fulfill.
10. Differentiate between Heap and Stack Memory in Java. 29. What is Synchronization?
11. What is Java String Pool? 30. What is OutOfMemoryError in Java?
12. What is Constructor Chaining in Java? 31. What are the different types of Garbage Collectors in Java?
13. What is a classloader in Java? 32. Can we write multiple catch blocks under single try block?
14. What is a Map in Java? 33. What is JDBC Driver?
15. What is runtime Polymorphism? 34. What is JDBC Connection interface?
16. Differentiate between Abstract classes and Interfaces. 35. Differentiate between execute & executeQuery.
17. What is an Association? 36. What do you understand by JDBC Statements?
18. What is a Marker interface? 37. What is Composition in Java?
19. What is a Servlet? 38. What is the difference between break and continue
20. What is the life-cycle of a Servlet? statements?

100+ JAVA INTERVIEW QUESTIONS & ANSWERS


IN: 9606058406
sales@edureka.co
US: 18338555775
20 WWW.EDUREKA.CO/JAVA

CAREER WHO IS A JAVA PROFESSIONAL?


A Java Professional works mostly with Java to design, develop and

GUIDANCE
build applications and websites that have dynamic elements.

Java Developer Android / Mobile App


A Java Developer is a specialized type of Developer
programmer who may collaborate with
web developers and software engineers An Android Developer is responsible for
to integrate Java into business developing applications for devices
applications, software and websites.    A powered by the Android operating
Java Developer is responsible for the system. Due to the fragmentation of this
design, development, and management ecosystem, an Android developer must
of Java-based applications. Because Java pay special attention to the application's
is used so widely, particularly by large compatibility with multiple versions of
organizations, the daily roles vary widely. Android and device types.

Java Web Developer


Java Web Programmer
Java Web Developers write, test, and
debug back-end code that supports
Java Web Programmers are
websites and web applications. This role
responsible for designing, coding and
requires a high level of technical expertise
modifying websites, from layout to
and familiarity with both the Java
function and according to a client's
programming language and related
specifications. Strive to create visually
technologies, such as relational databases
appealing sites that feature user-
and servers. Java developers work closely
friendly design and clear navigation.
with front-end developers to determine a
project’s specifications and scope and
translate this information into functional,
reliable, and scalable code.

Java Application Developer EJB Programmer


Java Application Developer is
The EJB Developer is a Java applications
responsible for developing software
programmer, and is familiar with both
solutions to meet customer needs.
SQL and with database access using
Creating and implementing the source
SQLJ or JDBC. The EJB deployer installs
code of new applications. Testing
and publishes the EJBs. This involves
source code and debugging code.
interaction with the EJB developer, so
Evaluating existing applications and
that the transactional nature of the EJBs
performing updates and
are understood.
modifications.

NEED EXPERT Talk to our experts and explore 08035068109


GUIDANCE? the right career opportunities! +1415 915 9044
EDUREKA JAVA TRAINING PROGRAMS

JAVA CERTIFICATION TRAINING


Weekend Live Class 24 x 7 Technical Assistance

https://www.edureka.co/java-j2ee-training-course

SPRING FRAMEWORK TRAINING


Weekend Live Class 24 x 7 Technical Assistance

https://www.edureka.co/spring-certification-course

MICROSERVICES CERTIFICATION TRAINING


Weekend Live Class/SP 24 x 7 Technical Assistance

https://www.edureka.co/microservices-architecture-training

SELENIUM CERTIFICATION TRAINING


Weekend/Weekday Live Class 24 x 7 Technical Assistance

https://www.edureka.co/selenium-certification-training

LEARNER'S REVIEWS

Elena AF Avinash Kulkarni Ankit Sharma


EA AK AS

Clear and detailed instructions, My journey started with Edureka Its very simple in learning
great examples of problem solving last year, when i was in search of and interesting too. The way
mostly based on real-world cases, "Micro-service Architecture our instructor is teaching us
and Java programming codes Training" course. My search ended is simply awesome. The thing
at Edureka. It was the best learning which I like the most about
were made available quickly for
experience. Edureka provides very Edureka is its Support
review right after class. Instructor well trained professionals. I would service,as I have got all my
takes time to listen and answer like to thank Edureka team for all queries answered by them on
students' questions. the support. time. Thank you Edureka :)

IN: 9606058406
sales@edureka.co
US: 18338555775
Free
Resources

2500+ Technical
Blogs
3000+
Video Tutorials on
YouTube

30+
Active
Free Monthly
Community Webinars
WWW.EDUREKA.CO/JAVA

About Us
There are countless online education marketplaces on the internet. And there’s us. We
are not the biggest. We are not the cheapest. But we are the fastest growing. We have
the highest course completion rate in the industry. We aim to become the largest
online learning ecosystem for continuing education, in partnership with corporates
and academia. To achieve that we remain ridiculously committed to our students. Be it
constant reminders, relentless masters or 24 x 7 online technical support - we will
absolutely make sure that you run out of excuses to not complete the course.

Contact Us IN: 08035068109 | US: +1415 915 9044


www.instagram.com/edureka.co/
IndiQube ETA, 3rd Floor, www.facebook.com/edurekaIN
No.38/4, www.linkedin.com/company/edureka/
Adjacent to Dell EMC2, www.youtube.com/user/edurekaIN
Dodanekundi, t.me/s/edurekaupdates
Outer Ring Road, Bengaluru, twitter.com/edurekaIN
Karnataka - 560048 in.pinterest.com/edurekaco/

News & Media


Edureka partners with
Edureka (Brain4ce Education
NIT Warangal to upskill
Solutions) tops Deloitte Tech
IT professionals in AI and
Fast 50 2014 rankings
Machine Learning

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy