Edureka Java Ebook
Edureka Java Ebook
Edureka Java Ebook
TABLE OF CONTENTS
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
IN: 9606058406
sales@edureka.co
US: 18338555775
MASTERING JAVA WITH EDUREKA
5. OOPS IN JAVA 11
TABLE OF CONTENTS
IN: 9606058406
sales@edureka.co
US: 18338555775
3 WWW.EDUREKA.CO/JAVA
Chapter 1
INTRODUCTION TO
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.
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
JAVA APPLICATIONS
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
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.
IN: 9606058406
sales@edureka.co
US: 18338555775
7 WWW.EDUREKA.CO/JAVA
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[]
IN: 9606058406
sales@edureka.co
US: 18338555775
9 WWW.EDUREKA.CO/JAVA
Chapter 4
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*/
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
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:
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
IN: 9606058406
sales@edureka.co
US: 18338555775
13 WWW.EDUREKA.CO/JAVA
IN: 9606058406
sales@edureka.co
US: 18338555775
14 WWW.EDUREKA.CO/JAVA
Chapter 6
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
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: 9606058406
sales@edureka.co
US: 18338555775
16 WWW.EDUREKA.CO/JAVA
Chapter 7
IN: 9606058406
sales@edureka.co
US: 18338555775
17 WWW.EDUREKA.CO/JAVA
2 4
1 3 5
CATCH THROW
IN: 9606058406
sales@edureka.co
US: 18338555775
18 WWW.EDUREKA.CO/JAVA
Chapter 8
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.
GUIDANCE
build applications and websites that have dynamic elements.
https://www.edureka.co/java-j2ee-training-course
https://www.edureka.co/spring-certification-course
https://www.edureka.co/microservices-architecture-training
https://www.edureka.co/selenium-certification-training
LEARNER'S REVIEWS
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.