Brush-up java for Interview
5/5
()
About this ebook
This book is useful for developers who has prior java development experience and wants to scale up or brush up their knowledge. It will be helpful for interview preparations. One can use it as a tool to crack the java interview. It is specially designed to brush-up the java concepts quickly.
Ashutosh Shashi
Ashutosh Shashi is a visionary and innovative technologist, currently living in Atlanta, Georgia, USA. He has completed master's degree in Computer Applications. He has more than 15 years of experience in IT industry. He is TOGAF 9.1 Certified, Google Cloud Certified Professional Cloud Architect, Microsoft Certified AZURE Solutions Architect Expert, AWS Certified Solutions Architect - Associate, Project Management Professional (PMP), DataStax Certified Professional on Apache Cassandra, and Oracle Certified Java SE 8 programmer. One can define him as a deep reader, dedicated writer and technology passionate person. He loves to keep himself updated with the latest stack of technologies and industry standards.
Related to Brush-up java for Interview
Related ebooks
Java Core Interview Questions and Answers. Tech interviewer’s notes Rating: 1 out of 5 stars1/5Grokking the Java Interview Rating: 0 out of 5 stars0 ratingsJava Core Interview in Australia. Questions and Answers. Tech interviewer’s notes Rating: 0 out of 5 stars0 ratingsAdvanced JAVA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJava: Best Practices to Programming Code with Java Rating: 0 out of 5 stars0 ratingsJava Coding Problems: Improve your Java Programming skills by solving real-world coding challenges Rating: 0 out of 5 stars0 ratingsJava: Advanced Guide to Programming Code with Java: Java Computer Programming, #4 Rating: 0 out of 5 stars0 ratingsJava: Tips and Tricks to Programming Code with Java Rating: 0 out of 5 stars0 ratings100 Recipes for Programming Java Rating: 5 out of 5 stars5/5Practical Java 8: Lambdas, Streams and new resources Rating: 5 out of 5 stars5/5Java and Java EE Interview Preparations Rating: 0 out of 5 stars0 ratingsLearn Java 12 Programming: A step-by-step guide to learning essential concepts in Java SE 10, 11, and 12 Rating: 0 out of 5 stars0 ratingsJava 8 Programmer II Study Guide: Exam 1Z0-809 Rating: 4 out of 5 stars4/5100+ Solutions in Java: A Hands-On Introduction to Programming in Java (English Edition) Rating: 0 out of 5 stars0 ratingsCore Java Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5Java: Beginner's Guide to Programming Code with Java Rating: 0 out of 5 stars0 ratingsJava/J2EE Design Patterns Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsJava: Best Practices to Programming Code with Java: Java Computer Programming, #3 Rating: 0 out of 5 stars0 ratingsLearn Java: A Crash Course Guide to Learn Java in 1 Week Rating: 3 out of 5 stars3/5(Part 1) Absolute Beginner: Java 4 Selenium WebDriver: Come Learn How To Program For Automation Testing Rating: 0 out of 5 stars0 ratingsJAVA for Beginner's Crash Course: Java for Beginners Guide to Program Java, jQuery, & Java Programming Rating: 4 out of 5 stars4/5JavaScript Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJAVA Programming for Beginners: The Simple Guide to Learning JAVA Programming fast! Rating: 0 out of 5 stars0 ratingsJava: Beginner's Guide to Programming Code with Java: Java Computer Programming Rating: 0 out of 5 stars0 ratingsJava: Tips and Tricks to Programming Code with Java: Java Computer Programming, #2 Rating: 0 out of 5 stars0 ratingsJava 8 to 21: Explore and work with the cutting-edge features of Java 21 (English Edition) Rating: 0 out of 5 stars0 ratings
Programming For You
HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsLearn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Mastering Windows PowerShell Scripting Rating: 4 out of 5 stars4/5Programming Arduino: Getting Started with Sketches Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Gray Hat Hacking the Ethical Hacker's Rating: 5 out of 5 stars5/5SwiftUI For Dummies Rating: 0 out of 5 stars0 ratingsPokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5C# Programming from Zero to Proficiency (Beginner): C# from Zero to Proficiency, #2 Rating: 0 out of 5 stars0 ratingsPython: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5The CSS Guide: The Complete Guide to Modern CSS Rating: 5 out of 5 stars5/5Spies, Lies, and Algorithms: The History and Future of American Intelligence Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5
Reviews for Brush-up java for Interview
1 rating0 reviews
Book preview
Brush-up java for Interview - Ashutosh Shashi
Brush-up java
for
Interview
Java concepts refresher.
(Covers up to java 11)
Ashutosh Shashi
Brush-up java for interview: Java concepts refresher
Copyright © 2020 by Ashutosh Shashi
All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means without written permission from the author.
ISBN 9781735222226
DEDICATION
To my parents,
Mr. Ram Binod Sharma and Mrs. Ramsukumari Devi, for their blessings.
To my wife Neha for her unconditional support.
And
Thanks to my dear daughter Anvita for ‘cover and more drawings’ of this book.
This page is intentionally left blank
Table of Contents
Introduction
Basic Java Concepts
Class, interface & package
Array
pass-by-value
JVM
Working of JVM
Garbage Collection
OOP Concepts
Abstraction
Encapsulation
Inheritance
Polymorphism
SOLID principle
Class, method and Objects
Abstract Class
Final class
Class access specifier
Nested class
Anonymous class
Immutable class
Object class
Object Comparisons
enumerations
Generics
Exception handling
Annotations
Java Collection
Enumeration
Iterator
ListIterator
List Interface
Set Interface
Queue Interface
Deque Interface
Map Interface
Multithreading
Thread Class
Runnable Interface
Thread Properties
Thread Synchronization
Liveness problems
Executors
Concurrent Collections
Java 8 features
Lambda Expression
Stream API
Method References
Default and static method for interfaces.
New Date and Time API
Optional
CompletableFuture
Unit Testing
Junit Tests
Mockito
Code Coverage
TDD
Miscellaneous concepts
Reflection
Java 9 Features
Java 11 Features
CI/CD
About the Author
Ashutosh Shashi is a visionary and innovative technologist, currently living in Atlanta, Georgia, USA. He has completed master’s degree in Computer Applications. He has more than 15 years of experience in IT industry. He is an architect, trainer, and author.
He is TOGAF 9.1 Certified, Google Cloud Certified Professional Cloud Architect, Microsoft Certified AZURE Solutions Architect Expert, AWS Certified Solutions Architect – Associate, Project Management Professional (PMP), DataStax Certified Professional on Apache Cassandra, and Oracle Certified Java SE 8 programmer.
One can define him as a deep reader, dedicated writer and technology passionate person. He loves to keep himself updated with the latest stack of technologies and industry standards.
Introduction
This book is useful for developers who has prior java development experience and wants to scale up or brush up their knowledge. It will be helpful for interview preparations. One can use it as a tool to crack the java interview.
This book is not in the form of interview questions and answers. It is specially designed to brush-up the java concepts quickly so that you will be capable to answer java interview questions.
This book contains small code snippet as example code. All code is tested, and you will be able to compile and run in single java file.
This book covers almost all the concepts of Java, up to java 11, that you need to know for interview.
Please send your suggestion and feedback in email at: bjava@ashutoshshashi.com
Basic Java Concepts
A close up of a dog Description automatically generatedJava is a general purpose, concurrent, object-oriented programming language. Java programming language is a statically typed language, meaning, in Java every variable and every expression has a type known at compile time. Types in Java is divided in two category, Primitive Type and Reference Type.
Primitive types are reserved keyword (pre-defined in Java) that is used to define a type of a variable. Primitive types are boolean, int, long, short, float, double, byte, and char.
Reference types are referenced to the objects. Reference types are class type, interface type, array type, and type variables.
Java is platform independent, object-oriented, and multithreaded programming language. Here platform-impendent means you can write the code once and run in any platform. In other words, Java is not operating system dependent, you just need to have JVM installed in your machine and you can run same code in any operating system. We will discuss more about JVM in a separate chapter.
Object oriented programming is a programming technique that use objects and their interfaces to build building blocks. We will discuss more about it in a separate chapter.
Multithreaded meaning Java have capability that can be used to write concurrent program and java will run it concurrently. We will discuss multithreading in a separate chapter.
Class, interface & package
Package
Package is a directory in which programs or sub packages are organized. Package is a group of classes or interfaces or both. A package can have sub package and sub package can have programs (.java files). Programs are the class and interface files. Naming structure of a package is hierarchical, and member of a package are class and interface. In java.io, java is a package and io is a sub package. You can also say java.io is a package. Package helps to prevent name conflict. Two packages in java cannot be exactly same in same hierarchy. For example, you cannot have two java.io package. Because package prevent name conflict you can have class or interface with the same name in two different packages but not in the same package. However, having class or interface with the same name is not a good practice, if you have it then you may have to use class or interface name with full package hierarchy.
package ashu.tech;
import ashu.tech.basic.SameNameClass;
publicclassMyMainClass{
publicstaticvoid main(String[] args){
SameNameClass obj1 =newSameNameClass();
ashu.tech.jvm.SameNameClass obj2 =new
ashu.tech.jvm.SameNameClass();
}
}
In above code snippet, I have class SameNameClass in two package, one package it is importing and another package it is providing with full qualifier path. This happens only if you have class with same name in more than one package and you are using those in one class like above.
Class
Class is a template or logical construct, on which the whole Java programming language is based upon. In java specification class is defined as a reference type and it describes how that reference type is implemented. An Object class is the parent of all the classes in Java. Every class you create in Java, or any class that exists in Java is derived from Object class.
A class can be derived from a class or interface. Once you derive the class from a class or interface, it extends the functionality of base class. Members of base class will be visible in derive class is based on the access specified you have used to define members of base class. As Object class in the base class of all the classes in Java, methods of Object class are available in every class by default. You can have your own implementation (override) of object class method to manage the behavior of your class. Object class methods are: clone(), equals(), finalize(), getclass(), hashcode(), notify(), notifyAll(), toString(), and wait(). We will talk about Object class and its methods in detail in separately.
Members of the class can be defined with public, protected, default, and private access specifiers. Below is the explanation of access specifiers.
public - Members defined with public access specifier can be accessed from anywhere, inside or outside of the class.
protected – Members defined with protected access specifier can be accessed from inside the class, or it can be accessed within the same package, or it can be accessed in first level derived class.
Default – Members defined without any access specifier is considered as default or package-private access specifier. Exception is in interface where if you do not specify access specifier and by default it will be public. In class it will be default or package private. Default access specifier can be accessed from inside of the class and also can be accessed within the same package. Default cannot be accessed in derived class, if member of base class is default and base and derived classes are in different package. If base class and derived class are in same package, then member of base class with default access specifiers will be accessed in derived class.
private – Members defined with private access specifier can be accessed only from inside the class. Then what is the use of private access specifier? You can have public member that can be called outside of class and through public member you can call or manipulate the private member of class. For example, you have private variable in a class that you do not want anyone can modify freely. You want to control the modification process of that private variable that is why you declared it as private. Now you can have public method inside the same class (for example getter and setter methods) that can be used outside of the class to access or modify the variable. You will have more control on private variable.
Member fields of class can be declared as private, unless you have any special circumstances. Class methods should have minimum accessibility, if you are calling method only inside your class, you can make it private. Always try to make each class members as less accessible as possible.
Below table will be helpful to understand the visibility of access specifiers. Below table is applicable for both instance variable and instance methods.
In above table you can see if access specifier is protected, members will not be visible outside of package that is similar to default access specifier. But if base class is having protected member, subclass can see that protected member even though base class and subclass is from different package.
Interface
Interface is a reference type whose members are classes, interfaces, constants, and methods. While creating interface, the file