Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Brush-up java for Interview
Brush-up java for Interview
Brush-up java for Interview
Ebook251 pages3 hours

Brush-up java for Interview

Rating: 5 out of 5 stars

5/5

()

Read preview

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.

LanguageEnglish
Release dateAug 22, 2020
ISBN9781735222226
Brush-up java for Interview
Author

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

Programming For You

View More

Related articles

Reviews for Brush-up java for Interview

Rating: 5 out of 5 stars
5/5

1 rating0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    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 generated

    Java 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

    Enjoying the preview?
    Page 1 of 1