Learnprogramingbyluckysir

Thursday, September 24, 2020

Interview Questions for experienced java developer

 In this post you will know 22 most asked core java interview Questions and answers for java developers who are having 1 to 4 years of experienced.

When you are attending for Java interview core java interview questions plays important role no matter you are fresher  or mid level developer or senior java developer. This technical round decides outcome of your interview. 

1. Why you override hashcode along with equls() method?

2. How to prevent a class from being sub classed in java?

When a final modifier is used with a class then the class cannot be extended further. This is one way to protect your class from being sub classed and often sensitive classes are made final due to security reason. This is also one of the reasons why String and wrapper classes are final in Java.


Want see all answers then watch this video:



3. Can we override static method?

No, you cannot override static method in Java because method overriding is based upon dynamic binding at runtime and static methods are bonded using static binding at compile time. Though you can declare a method with same name and method signature in sub class which does look like you can override static method in Java but in reality that is method hiding.

4. Can we access private method in Java?

Yes, we can access private method in the same class but not outside the class.


5. Can you explain final keyword?

Final is a special keyword it can be used in different context such as:

When the final keyword is used with a variable then its value can’t be changed once assigned.

When a method is declared final then it can’t be overridden by the inheriting class.

When a class is declared as final in Java, it can’t be extended by any subclass class but it can extend other class.

6. Difference between checked Exception and unchecked Exception

Checked Exception:  The exceptions which are checked by the compiler for smooth excetuon of the program at runtime is called checked exception:


It means if a method is throwing a checked exception then it should handle the exception using try-catch block or it should declare the exception using throws keyword, otherwise the program will give a compilation error.


Ex: SQLException

IOException

ClassNotFoundException




Unchecked Exception: The exceptions which are not checked by the compiler are called unchecked Exception.


Ex: NullPointerException

ArrayIndexOutOfBound

IllegalArgumentException

IllegalStateException

7. How to fix concurrentModificationException?

8. Difference between abstract class and interface?

9. When to use abstract class and interface in java?

10. Difference Btw method overloading and overriding in java?

11. Difference between encapsulation and abstraction?

12. Have you applied object cloning in your project?

Object cloning in Java is the process of creating an exact copy of an object. It basically means the ability to create an object with a similar state as the original object. To achieve this, Java provides a method clone() to make use of this functionality. This method creates a new instance of the class of the current object and then initializes all its fields with the exact same contents of corresponding fields.

13. Difference between HashTable and HashMap

14. When to use Transient variable?

when you want to make a variable non-serializable in a class, which implements the Serializable interface. In other words, you can use it for a variable whose value you don't want to save.

15. Tell me one example when to use ArrayList and when to use LinkedList?

Arraylist is best choice is if our frequent operation is retrival that means get(int) or when search operation need to be performed.

Whereas Linkedlist is best choice if our frequent operation is insert and delete operations in the middle. Since it does not need several shift operation internally.


16. Diff b/w StringBuffer and StringBuilder


Every method present in StringBuffer is synchronized that means at a time only one thread is allowed to operate on StringBuffer object, hence StringBuffer obj is ThreadSafe whereas no method present in stringbuilder is synchronized that means multiple threads are allowed to operate simulountesly hence stringbuffer is not thread safe.


Stringbuffer increases waiting time of threads and hence performance is low whereas threads are not req to hold and hence performance is high.


17. How to create custom exception? Or user defined exception

To create user defined exception we need to write subclass simply extending the java Exception class and you can override toString()function to display your customize message on catch.

  

In the Exception class provides methods to show error message to the end users. They are

getLocalizedMessage()

getMessage()

toSting()


While you want to develop user defined exception in your programming project no need to override any of the above methods which are available in the Exception class in the sub class. Based on your project requirement you have to customize your message to show end users.


Simply says You can Override toString() method to display custom message.

           You must extend the Exception class to create custom exceptions 


18. When we should go for join() method?

If a thread wants to wait until completing some other thread then we should go for join() method. Join() method throws interruptedexception which is checked exception, hence we should handle either try-catch or throws keyword.


19. What type of exceptions faced in your project and how you resolve it?

I have faced different types of exceptions but some of the exceptions like nullpointerexceptions, concurrentmodification exception and illegalmonitorstateexception.

Wait(), notify() and notifyall() methods are available in Object class but not in Thread class becaz thread can call these methods on any common object.

To call wait(), notify() and notifyall() methods compulsory the current thread should be owner of that object that is current thread should has lock of that object that is current thread should be synchronized area. Hence we can call wait(), notify() and notifyall() methods only from synchronized are otherwise will get Runtime exception says Illegalstatemonitorexception.


Tell me some java8 features with example

Java 8 has been one of the biggest releases after Java 5 annotations and generics. Some of the important features of Java 8 are:

1. Interface changes with default and static methods

2. Functional interfaces and Lambda Expressions

3. Java Stream API for collection classes

4. Java Date Time API



20. Why we need generics? Have you used generics in Your Project?

21. Difference between Loose coupling and tight coupling?

22. Difference between BufferReader and Scanner in Java? which one prefer?

23. Explain collection conepts with realtime examples?

24. Exalain oops concepts with real time examples

25. What is singleton class in Java?

26. Difference between ClassNotFoundException and NoClassDefFoundError

27. Difference between constructor and method

28. Explain public static void main()

29. Difference between Heap Memory and Stack

30. How to explain Spring MVC Architecture

31. How to explain project architecture?




 

 

 

 




 


Friday, September 18, 2020

Top 5 Best Microservices Books

 In this post you will know the top 5 MicroServices Architecture Books for java developers as well as software architect position developers. 

Microservices architecture allows developers to build and maintain applications with ease, and enterprises are rapidly adopting it to build software using Spring Boot as their default framework. With this book, you’ll learn how to efficiently build and deploy microservices using Spring Boot.


1. Hands - on Microservices with springBoot and spring Cloud

This book covers the following exciting features:


    Build reactive microservices using Spring Boot

    Develop resilient and scalable microservices using Spring Cloud

    Use OAuth 2.0/OIDC and Spring Security to protect public APIs

    Implement Docker to bridge the gap between development, testing, and production

    Deploy and manage microservices using Kubernetes

    Apply Istio for improved security, observability, and traffic management




2: Building Microservices 


In this  book, sam newman covered the principles of Microservice Architecture as well as how to design, deploy, test and observe Microservice Architecture in length. He also pointed out the potential pitfalls about designing Microservices and how to migrate a Monolith application into Microservices in an evolutionary way. As a bonus, Sam Newman’s writing is elegant, clear and he has explained such a complex topic in a surprisingly simple way. This is a must-read book for anyone wants to be engaged in Microservices


3. Microservices Patterns


In this book: the topics covered  the advantages of Microservice Architecture as well as the disadvantages and challenges of Microservices. For every challenge, he has then offered one or more patterns to solve the problem and their merits/demerits. This book also summarizes all the patterns used in the Microservices world.


4. Spring Microservices in Action


This book teaches you how to build microservice-based applications using Java and the Spring platform. You'll learn to do microservice design as you build and deploy your first Spring Cloud application. Throughout the book, carefully selected real-life examples expose microservice-based patterns for configuring, routing, scaling, and deploying your services. You'll see how Spring's intuitive tooling can help augment and refactor existing applications with microservices.


5. Cloud native architecture


The book starts with a quick introduction to cloud native architectures, helping you get up to speed with what cloud native architecture is. You will learn what a cloud adoption framework looks like and even go on to develop cloud native architectures using microservices and serverless computing as design principles. You'll then explore the major pillars of cloud native design including scalability and availability, cost optimization, security, and operational excellence to build on your knowledge of effectively running and managing cloud environments. In the concluding chapters, you will learn about a variety of public cloud architectures, right from Amazon Web Services (AWS) and Azure through to the Google Cloud Platform (GCP).


What you will learn

Understand the difference between cloud native and traditional architectures

Explore different aspects of migration, including when and why you should migrate

Identify the elements you need to consider when selecting a technology for your architecture

Automate security controls and configuration management

Use Infrastructure as Code(IaC) and CI/CD pipelines to run environments in a sustainable manner

Understand the cloud native application development capabilities of AWS


Who this book is for

This book is for software architects who want to design resilient, scalable, and highly available applications that are native to the cloud.


Friday, September 11, 2020

Top 15 Mostly Asked SpringBoot Interview Questions and answers

 In this post you will learn mostly asked springboot interview questions and answers. Nowadays interview expects more knowledge of Spring Boot from candidates. Spring Boot aims to simplify Java development with Spring by removing major pain points with respect to configuration, dependency management and ease of development.

In order to answer Spring Boot question with confidence, you not only know what problem Spring Boot solves but also in-depth knowledge of some of its core features like auto-configuration and starter dependencies. These two features eliminate a lot of configuration and setup work from Spring-based Java application.

Here is the List Top SpringBoot Interview Questions and answers




1. What is springboot?

It is a framework for rapid application development built on top of the Spring Framework. We can say in simple words springboot is the combination of spring framework and embedded servers. It is used to create a stand-alone Spring-based application that you can just run because it needs minimal Spring configuration. In Spring Boot, there is no requirement for XML configuration (deployment descriptor) that means it decreases the effort of the developer.

2. Why Springboot is used?
To design any spring based application, a developer needs to be taken care on manual set up on Hibernate data source, Entity Manager, Session Factory, Transaction Management everything.

To Design all those common set up, a developer doesn’t need to define everything individually, SpringBootConfiguration annotation enough to manage everything at the time of deployment.
Spring MVC application some of the XML configuration mandatory to manage. Whereas Configuring Spring Boot Application nothing needs to be managed, the only annotation managed everything.
As configuration can be easily handled by manually, so Spring or Spring MVC can manage to not loading some of the unwanted default features for that specific application. In case of Spring Boot, it automatically handled on default loading part, so the developer doesn’t have as such concept of not loading some of the specific unusable spring default features.

3. what is use of @SpringBootApplication annotation and how it works internally?

The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes. Spring Boot enables the developer to use a single annotation instead of using multiple. But, as we know, Spring provided loosely coupled features that we can use for each individual annotation as per our project needs.

4. What are starter dependencies?
Spring Boot starters are maven templates that contain a collection of all the relevant transitive dependencies that are needed to start a particular functionality.
For example, If we want to create a Spring WebMVC application then in a traditional setup, we would have included all required dependencies ourselves. It leaves the chances of version conflict which ultimately result in more runtime exceptions.
With Spring boot, to create web MVC application, all we need to import is spring-boot-starter-web dependency. Transitively, it brings in all other required dependencies to build a web application e.g. spring-webmvc, spring-web, hibernate-validator, tomcat-embed-core, tomcat-embed-el, tomcat-embed-websocket, jackson-databind, jackson-datatype-jdk8, jackson-datatype-jsr310 and jackson-module-parameter-names.
pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

5. What is Spring Initializer? why should you use it?
One of the difficult things to start with a framework is initial setup, particularly if you are starting from scratch and you don't have a reference setup or project. Spring Initializer addresses this problem in Spring Boot.

It's nothing but a web application which helps you to create initial Spring boot project structure and provides Maven or Gradle build file to build your code.

6. What is Spring Actuator? What are its advantages?
This is an interesting Spring Boot question and mostly asked on Java roles which also has some support responsibility. Spring Actuator is another cool Spring Boot feature which allows seeing inside a running application.

 It allows you to see inside an application. Since Spring Boot is all about auto-configuration it makes debugging difficult and at some point in time, you want to know which beans are created in Spring's Application Context and how Controllers are mapped. Spring Actuator provides all that information.

It provides several endpoints e.g. a REST endpoint to retrieve this kind of information over the web. It also provides a lot of insight and metrics about application health e.g. CPU and memory usage, number of threads etc.

It also comes with a remote shell which you can use to securely go inside Spring Boot application and run some command to expose the same set of data. You can even use JMX to control this behavior at runtime.

Btw, it's important to secure your Spring Actuator endpoints because it exposes a lot of confidential information and a potentially dangerous one-two. For example, by using /showdown endpoint you can kill a Spring Boot application.


7. What is Spring Boot CLI? What are its benefits?
Spring Boot CLI is a command line interface which allows you to create Spring-based Java application using Groovy. Since it's used Groovy, it allows you to create Spring Boot application from the command line without ceremony e.g. you don't need to define getter and setter method, or access modifiers, return statements etc.

8. What are some common Spring Boot annotations?
Some of the most common Spring Boot annotations are @EnableAutoConfiguration, @SpringBootApplication, @SpringBootConfiguration, and @SpringBootTest.

The @EnableAutoConfiguration is used to enable auto-configuration on Spring Boot application, while @SpringBootApplication is used on the Main class to allow it to run a JAR file. @SpringBootTest is used to run unit test on Spring Boot environment.

9. What is the difference between @SpringBootApplication and @EnableAutoConfiguration annotation?
Even though both are essential Spring Boot application and used in the Main class or Bootstrap class there is a subtle difference between them. The @EnableAutoConfiguration is used to enable auto-configuration but @SpringBootApplication does a lot more than that.

It also combines @Configuration and @ComponentScan annotations to enable Java-based configuration and component scanning in your project.

The @SpringBootApplication is in fact combination of @Configuration, @ComponentScan and @EnableAutoConfiguration annotations

It's also very powerful and can auto-include a lot of library in Groovy's default package if you happen to use it.
For example, if you use JdbcTempalte, it can automatically load that for you

10. Can we disable the default web server in the Spring Boot application?
The major strong point in Spring is to provide flexibility to build your application loosely coupled. Spring provides features to disable the web server in a quick configuration. Yes, we can use the application.properties to configure the web application type, i.e.  spring.main.web-application-type=none

11.Can we override or replace the Embedded Tomcat server in Spring Boot?
Yes, we can replace the Embedded Tomcat with any other servers by using the Starter dependencies. You can use spring-boot-starter-jetty  or spring-boot-starter-undertow as a dependency for each project as you need.

12. How to do unit testing and integration testing in a spring boot application?
Typically any software application is divided into different modules and components. When one such component is tested in isolation, it is called unit testing.
Unit tests do not verify whether the application code works with external dependencies correctly. It focuses on single component and mocks all dependencies this component interacts with.

To perform unit testing, we can take help of specialized annotations such as :
@JdbcTest – can be used for a typical jdbc test when a test focuses only on jdbc-based components.
@JsonTest – It is used when a test focuses only on JSON serialization.
@RestClientTest – is used to test REST clients.
@WebMvcTest – used for Spring MVC tests with configuration relevant to only MVC tests.
In integration testing, we shall focus on testing complete request processing from controller to persistence layer.
The @SpringBootTest annotation helps in writing integration tests. It starts the embedded server and fully initializes the application context. We can inject the dependencies in test class using @Autowired annotation.
We can also provide test specific beans configuration using nested @Configuration class or explicit @TestConfiguration classes.

13. How to enable debug logging?
To enable debug logging,
1. we can start the application with the --debug switch.
2. we can set the logging.level.root=debug property in application.properties file.
3. We can set the logging level of root logger in supplied logging configuration file.


14. How to enable HTTPS/SSL support in Spring boot?
The SSL support in spring boot project can be added via application.properties and by adding the below entries.
application.properties
server.port=8443
server.ssl.key-alias=selfsigned_localhost_sslserver
server.ssl.key-password=changeit
server.ssl.key-store=classpath:ssl-server.jks
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=JKS

15.Is this possible to change the port of Embedded Tomcat server in Spring boot?
Yes, it's possible to change the port. You can use the application.properties file to change the port. But you need to mention "server.port" (i.e. server.port=8081). Make sure you have application.properties in your project classpath; REST Spring framework will take care of the rest. If you mention server.port=0 , then it will automatically assign any available port.

16. Where do you define properties in Spring Boot application?
You can define both application and Spring boot related properties into a file called application.properties. You can create this file manually or you can use Spring Initializer to create this file, albeit empty.

You don't need to do any special configuration to instruct Spring Boot load this file. If it exists in classpath then Spring Boot automatically loads it and configure itself and application code according.

Wednesday, September 9, 2020

When to use SQL and NoSQL

 In this post you will know when to use SQL and NoSQL . This is question may rise from many of software developers what exactly difference between SQL and NoSQL and when to use SQL and NoSQL.

First let us understand why nosql came into IT Market though sql already exist.  The main reason is, with rise of social media,E commerce, search, and the explosion of data, SQL was struggling to manage all the requests, transactions, and activity occurring online. NoSQL is designed to manage lots of traffic and data.

SQL is used to communicate with Relational Databases. It is used to store ,update,delete the data.

 RDBMS stores the data in a very organized way in tabular format.




Examples for RDBMS are:

oracle, mysql, sql server

whereas nosql(not only sql) can store the data in different types of data together. Data is stored in many ways which means it can be document-oriented, column-oriented, graph-based or organized as a Key-value store. It is used for flexibility and therefore speed and scalability in managing large volumes of data.


There are four types of NoSQL databases.

Key value: data is stored as attribute names or keys with values

Document: contains many different key value pairs

Graph: used to store data related to connections or networks

Column: data is stored as columns instead of rows


Examples for nosql database are:

MongoDB, Cassandra, Redis, Couchbase, DynamoDB and Hbase


Now lets talk about when to use SQL and nosql


Use SQL instead of Nosql

You’re working with complex queries and reports. With SQL you can build one script that retrieves and presents your data. 

NoSQL doesn’t support relations between data types.

 SQL databases are a better fit for heavy duty or complex transactions because it’s more stable and ensure data integrity.

if you’re not working with a large volume of data and not expecting constant changing in your project then sql is best choice.


use nosql instead of sql


if You are not concerned about data consistency and 100% data integrity then no sql is best choice. 

For example, with social media platforms, it isn’t important if everyone sees your new post at the exact same time, which means data consistency is not a priority.

You have a lot of data, many different data types, and your data needs will only grow over time. NoSQL makes it easy to store all different types of data together and without having to invest time into defining what type of data you’re storing in advance.

It can’t guarantee ACID properties. In such cases like financial transactions, etc., you may go with SQL databases.

If you have local data transactions that need not be very durable.

if You are constantly adding new features, functions, data types then nosql is better choice.

The choice of the database will depend upon your preferences, business requirements, volume, and variety of data.

NoSQL databases are gaining large popularity these days due to their capacity to integrate big data, low cost, easy scalability, 


and open source features. However, it is still a relatively young technology and lacks standardization, unlike SQL which in 


turn creates some issues during migration. Lack of ACID compliance is also a concern with NoSQL.




Thursday, September 3, 2020

Will you Leave this company if you get better opportunity?

 In this post i am going to sharing frequently asked HR Tricky Interview Question and also who attend for government jobs also may face this type of tricky interview questions. In this session you will find Best answer for the HR interview " will you leave this organization if you get better opportunities? 


Okay, these kinds of questions are quiet tricky. Either of a straight YES and NO can create a negative image of yours. You need to be sincere enough to deal with such a situation.

Sometimes it's good to be diplomatic to get an offer with a handsome paycheck. Let's find out the consequences of saying yes or no:

If you directly say YES then it leaves a negative impression about you which is not acceptable in the corporate environment and it would be significant enough to disqualify you for the further rounds. So not a direct yes on this question.

 


If you directly say NO then the interviewer might think that you are lying to land into a job.

What should be your ideal take on this???

This question must be answered in a somewhat diplomatic manner. I would answer this question like — “For me, better opportunities does not mean a raise in salary. If I would get better opportunities in terms of learning, opportunities to showcase my skills, better career growth options, good working culture, opportunities to work in my areas of interest only then would I consider leaving the organization. Working for this organization has always been my dream and I would not leave the organization just for a mere hike in my salary.”

 

Second answer should be like “First of all, I will explore the information about the opportunity to figure out the outcomes of joining. Everybody loves the comfort zone and once I start feeling comfortable here, it would be hard for me to switch my loyalty and compromise my comfort level. Comfort in terms of cordial relationship with my peers, not finding comfort in my tasks.

I love challenging tasks only. To be honest, I will try to seek advice from my college seniors and the elders in my family. If the opportunity fits all the aspects then I will definitely reveal the same to my reporting manager and I hope your employee retainment policies must be reasonable enough to retain my employment with this organization.”




Monday, May 4, 2020

How to become full stack .Net Developer

In this post you will know how to become a full stack .net Developer and also known who is full stack developer and what are the skills required to become a full stack .net developer.

A full stack developer is capable of working both front and Back end Technologies and also should have worked on servers, database, software design, cloud technologies etc..



The following are the skills required to become a full stack .net developer:


Front End:
·  HTML
·  CSS
·  Bootstrap
·  JavaScript
·  jQuery/ Angular JS
·  AJAX

Back End:
·       C#
·       ASP.NET
·       .NET Core(Newly released)

Frameworks:
·       Web API
·       MVC

Database:
·      Sql Server

Cloud Technology:
·       Microsoft Azure

Added Skills:
·       Devops
·       Testing skills
·       Software Design skills
·       Version Control : GIT (or) SVN
·       Communication and Presentation

Friday, February 14, 2020

When to use SQL and when to use NoSQL

In this post you will know what is SQL and NoSQL and the main differences between them and also covered when to use SQL and Which scenario recommended to use NoSQL,

SQL stands for Structured Query language, pronounced as "S-Q-L" or sometimes as "See-Quel". SQL is the standard language for dealing with Relational Databases. SQL can be used to insert, search, update and delete database records. SQL can do lots of other operations including optimizing and maintenance of databases. Relational databases like MySQL Database, Oracle, Ms SQL server, Sybase, etc uses SQL.

 NoSQL is not a relational database. The reality is that a relational database model may not be the best solution for all situations. The easiest way to think of NoSQL, is that of a database which does not adhering to the traditional relational database management system (RDMS) structure. Sometimes you will also see it revered to as 'not only SQL'.





Now we will see the key differences between SQL and NoSQL

                SQL
 NoSQL
1.                      SQL is Relational data base(RDBMS)
2.                      It is a query based language
3.                      These databases are table based databases.
4.                      SQL databases are vertically scalable.
5.                      SQL databases are suitable for complex query intensive work environments.
6.                      SQL follow ACID model such as:
·      Atomicity
·      Consistency
·      Isolation
·      Durability
Examples: oracle,mysql,sql server etc..

1.          These databases are called non relational databases or distributed data bases.
2.          This database is no declarative query language.
3.          This database can be document based, graphs, key-value paired data bases.
4.          NoSQL databases are horizontally scalable.
5.          It is not suitable for complex query.
6.          NoSQL follows BASE model such as
·       Basically available
·       Soft State
·       Eventually Consistent

Examples:  MangoDB, DaynoDB, Cassandra etc..


when to use SQL:


SQL Preferred when building customer reports
When the requirement is to store and get data from a database.
If communication is required from different related tables then should use SQL
If you want write complex queries using joins, views , stored procedures.

When to use NoSQL:
Need to handle large volumes of structured, semi-structured, and unstructured data
Follow modern development practices such as agile sprints, quick iterations, and frequent code pushes
Prefer object-oriented programming that is easy to use and flexible
Used when logging data from variety of sources.