Tuesday, February 19, 2019

Spring REST Web Services Exception Handling

 Solution 1 – The Controller level @ExceptionHandler

The first solution works at the @Controller level – we will define a method to handle exceptions, and annotate that with @ExceptionHandler:
1
2
3
4
5
6
7
8
public class FooController{
     
    //...
    @ExceptionHandler({ CustomException1.class, CustomException2.class })
    public void handleException() {
        //
    }
}
This approach has a major drawback – the @ExceptionHandler annotated method is only active for that particular Controller, not globally for the entire application. Of course, adding this to every controller makes it not well suited for a general exception handling mechanism.
We can work around this limitation by having all Controllers extend a Base Controller class – however, this can be a problem for applications where, for whatever reason, this isn’t possible. For example, the Controllers may already extend from another base class which may be in another jar or not directly modifiable, or may themselves not be directly modifiable.
Next, we’ll look at another way to solve the exception handling problem – one that is global and doesn’t include any changes to existing artifacts such as Controllers.

3. Solution 2 – The HandlerExceptionResolver

The second solution is to define an HandlerExceptionResolver – this will resolve any exception thrown by the application. It will also allow us to implement a uniform exception handling mechanism in our REST API.
Before going for a custom resolver, let’s go over the existing implementations.

3.1. ExceptionHandlerExceptionResolver

This resolver was introduced in Spring 3.1 and is enabled by default in the DispatcherServlet. This is actually the core component of how the @ExceptionHandler mechanism presented earlier works.

3.2. DefaultHandlerExceptionResolver

This resolver was introduced in Spring 3.0, and it’s enabled by default in the DispatcherServlet. It’s used to resolve standard Spring exceptions to their corresponding HTTP Status Codes, namely Client error – 4xx and Server error – 5xx status codes. Here’s the full list of the Spring Exceptions it handles, and how they map to status codes.
While it does set the Status Code of the Response properly, one limitation is that it doesn’t set anything to the body of the Response. And for a REST API – the Status Code is really not enough information to present to the Client – the response has to have a body as well, to allow the application to give additional information about the failure.
This can be solved by configuring view resolution and rendering error content through ModelAndView, but the solution is clearly not optimal. That’s why Spring 3.2 introduced a better option that we’ll discuss in a later section.

3.3. ResponseStatusExceptionResolver

This resolver was also introduced in Spring 3.0 and is enabled by default in the DispatcherServlet. Its main responsibility is to use the @ResponseStatus annotation available on custom exceptions and to map these exceptions to HTTP status codes.
Such a custom exception may look like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
    public ResourceNotFoundException() {
        super();
    }
    public ResourceNotFoundException(String message, Throwable cause) {
        super(message, cause);
    }
    public ResourceNotFoundException(String message) {
        super(message);
    }
    public ResourceNotFoundException(Throwable cause) {
        super(cause);
    }
}
Same as the DefaultHandlerExceptionResolver, this resolver is limited in the way it deals with the body of the response – it does map the Status Code on the response, but the body is still null.

3.4. SimpleMappingExceptionResolver and AnnotationMethodHandlerExceptionResolver

The SimpleMappingExceptionResolver has been around for quite some time – it comes out of the older Spring MVC model and is not very relevant for a REST Service. We basically use it to map exception class names to view names.
The AnnotationMethodHandlerExceptionResolver was introduced in Spring 3.0 to handle exceptions through the @ExceptionHandler annotation but has been deprecated by ExceptionHandlerExceptionResolver as of Spring 3.2.

3.5. Custom HandlerExceptionResolver

The combination of DefaultHandlerExceptionResolver and ResponseStatusExceptionResolver goes a long way towards providing a good error handling mechanism for a Spring RESTful Service. The downside is – as mentioned before – no control over the body of the response.
Ideally, we’d like to be able to output either JSON or XML, depending on what format the client has asked for (via the Accept header).
This alone justifies creating a new, custom exception resolver:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@Component
public class RestResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver {
 
    @Override
    protected ModelAndView doResolveException
      (HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        try {
            if (ex instanceof IllegalArgumentException) {
                return handleIllegalArgument((IllegalArgumentException) ex, response, handler);
            }
            ...
        } catch (Exception handlerException) {
            logger.warn("Handling of [" + ex.getClass().getName() + "]
              resulted in Exception", handlerException);
        }
        return null;
    }
 
    private ModelAndView handleIllegalArgument
      (IllegalArgumentException ex, HttpServletResponse response) throws IOException {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        String accept = request.getHeader(HttpHeaders.ACCEPT);
        ...
        return new ModelAndView();
    }
}
One detail to notice here is that we have access to the request itself, so we can consider the value of the Accept header sent by the client.
For example, if the client asks for application/json then, in the case of an error condition, we’d want to make sure we return a response body encoded with application/json.
The other important implementation detail is that we return a ModelAndView – this is the body of the response and it will allow us to set whatever is necessary on it.
This approach is a consistent and easily configurable mechanism for the error handling of a Spring REST Service. It does, however, have limitations: it’s interacting with the low-level HtttpServletResponseand it fits into the old MVC model which uses ModelAndView – so there’s still room for improvement.

4. Solution 3 – @ControllerAdvice

Spring 3.2 brings support for a global @ExceptionHandler with the @ControllerAdvice annotation. This enables a mechanism that breaks away from the older MVC model and makes use of ResponseEntity along with the type safety and flexibility of @ExceptionHandler:
1
2
3
4
5
6
7
8
9
10
11
12
13
@ControllerAdvice
public class RestResponseEntityExceptionHandler
  extends ResponseEntityExceptionHandler {
 
    @ExceptionHandler(value
      = { IllegalArgumentException.class, IllegalStateException.class })
    protected ResponseEntity<Object> handleConflict(
      RuntimeException ex, WebRequest request) {
        String bodyOfResponse = "This should be application specific";
        return handleExceptionInternal(ex, bodyOfResponse,
          new HttpHeaders(), HttpStatus.CONFLICT, request);
    }
}
The@ControllerAdvice annotation allows us to consolidate our multiple, scattered @ExceptionHandlers from before into a single, global error handling component.
The actual mechanism is extremely simple but also very flexible. It gives us:
  • Full control over the body of the response as well as the status code
  • Mapping of several exceptions to the same method, to be handled together, and
  • It makes good use of the newer RESTful ResposeEntity response
One thing to keep in mind here is to match the exceptions declared with @ExceptionHandler with the exception used as the argument of the method. If these don’t match, the compiler will not complain – no reason it should, and Spring will not complain either.
However, when the exception is actually thrown at runtime, the exception resolving mechanism will fail with:
1
2
java.lang.IllegalStateException: No suitable resolver for argument [0] [type=...]
HandlerMethod details: ...

5. Solution 4 – ResponseStatusException (Spring 5 and Above)

Spring 5 introduced the ResponseStatusException class. We can create an instance of it providing an HttpStatus and optionally a reason  and a cause:
1
2
3
4
5
6
7
8
9
@GetMapping("/actor/{id}")
public String getActorName(@PathVariable("id") int id) {
    try {
        return actorService.getActor(id);
    } catch (ActorNotFoundException ex) {
        throw new ResponseStatusException(
          HttpStatus.NOT_FOUND, "Actor Not Found", ex);
    }
}
What are the benefits of using ResponseStatusException?
  • Excellent for prototyping: We can implement a basic solution quite fast
  • One type, multiple status codes: One exception type can lead to multiple different responses. This reduces tight coupling compared to the @ExceptionHandler
  • We won’t have to create as many custom exception classes
  • More control over exception handling since the exceptions can be created programmatically
And what about the tradeoffs?
  • There’s no unified way of exception handling: It’s more difficult to enforce some application-wide conventions, as opposed to @ControllerAdvice which provides a global approach
  • Code duplication: We may find ourselves replicating code in multiple controllers
We should also note that it’s possible to combine different approaches within one application.
For example, we can implement a @ControllerAdvice globally, but also ResponseStatusExceptions locally. However, we need to be careful: If the same exception can be handled in multiple ways, we may notice some surprising behavior. A possible convention is to handle one specific kind of exception always in one way.
For more details and further examples, see our tutorial on ResponseStatusException.

6. Handle the Access Denied in Spring Security

The Access Denied occurs when an authenticated user tries to access resources that he doesn’t have enough authorities to access.

6.1. MVC – Custom Error Page

First, let’s look at the MVC style of the solution and see how to customize an error page for Access Denied:
The XML configuration:
1
2
3
4
5
<http>
    <intercept-url pattern="/admin/*" access="hasAnyRole('ROLE_ADMIN')"/>  
    ...
    <access-denied-handler error-page="/my-error-page" />
</http>
And the Java configuration:
1
2
3
4
5
6
7
8
@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .antMatchers("/admin/*").hasAnyRole("ROLE_ADMIN")
        ...
        .and()
        .exceptionHandling().accessDeniedPage("/my-error-page");
}
When users try to access a resource without having enough authorities, they will be redirected to “/my-error-page“.

6.2. Custom AccessDeniedHandler

Next, let’s see how to write our custom AccessDeniedHandler:
1
2
3
4
5
6
7
8
9
10
@Component
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
 
    @Override
    public void handle
      (HttpServletRequest request, HttpServletResponse response, AccessDeniedException ex)
      throws IOException, ServletException {
        response.sendRedirect("/my-error-page");
    }
}
And now let’s configure it using XML Configuration:
1
2
3
4
5
<http>
    <intercept-url pattern="/admin/*" access="hasAnyRole('ROLE_ADMIN')"/>
    ...
    <access-denied-handler ref="customAccessDeniedHandler" />
</http>
Or using Java Configuration:
1
2
3
4
5
6
7
8
9
10
11
@Autowired
private CustomAccessDeniedHandler accessDeniedHandler;
 
@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .antMatchers("/admin/*").hasAnyRole("ROLE_ADMIN")
        ...
        .and()
        .exceptionHandling().accessDeniedHandler(accessDeniedHandler)
}
Note how – in our CustomAccessDeniedHandler, we can customize the response as we wish by redirecting or display a custom error message.

6.3. REST and Method Level Security

Finally, let’s see how to handle method level security @PreAuthorize, @PostAuthorize, and @SecureAccess Denied.
We’ll, of course, use the global exception handling mechanism that we discussed earlier to handle the AccessDeniedException as well:
1
2
3
4
5
6
7
8
9
10
11
12
13
@ControllerAdvice
public class RestResponseEntityExceptionHandler
  extends ResponseEntityExceptionHandler {
 
    @ExceptionHandler({ AccessDeniedException.class })
    public ResponseEntity<Object> handleAccessDeniedException(
      Exception ex, WebRequest request) {
        return new ResponseEntity<Object>(
          "Access denied message here", new HttpHeaders(), HttpStatus.FORBIDDEN);
    }
     
    ...
}

7. Spring Boot Support

Spring Boot provides an ErrorController implementation to handle errors in a sensible way.
In a nutshell, it serves a fallback error page for browsers (aka the Whitelabel Error Page), and a JSON response for RESTful, non HTML requests:
1
2
3
4
5
6
7
{
    "timestamp": "2019-01-17T16:12:45.977+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Error processing the request!",
    "path": "/my-endpoint-with-exceptions"
}
As usual, Spring Boot allows configuring these features with properties:
  • server.error.whitelabel.enabled: can be used to disable the Whitelabel Error Page and rely on the servlet container to provide an HTML error message
  • server.error.include-stacktrace: with an always value, it includes the stacktrace in both the HTML and the JSON default response
Apart from these properties, we can provide our own view-resolver mapping for /error, overriding the Whitelabel Page.
We can also customize the attributes that we want to show in the response by including an ErrorAttributes bean in the context. We can extend the DefaultErrorAttributes class provided by Spring Boot to make things easier:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Component
public class MyCustomErrorAttributes extends DefaultErrorAttributes {
 
    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
        Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, includeStackTrace);
        errorAttributes.put("locale", webRequest.getLocale()
            .toString());
        errorAttributes.remove("error");
 
        //...
 
        return errorAttributes;
    }
}
If we want to go further and define (or override) how the application will handle errors for a particular content type, we can register an ErrorController bean.
Again, we can make use of the default BasicErrorController provided by Spring Boot to help us out.
For example, imagine we want to customize how our application handles errors triggered in XML endpoints. All we have to do is define a public method using the @RequestMapping and stating it produces application/xml media type:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Component
public class MyErrorController extends BasicErrorController {
 
    public MyErrorController(ErrorAttributes errorAttributes) {
        super(errorAttributes, new ErrorProperties());
    }
 
    @RequestMapping(produces = MediaType.APPLICATION_XML_VALUE)
    public ResponseEntity<Map<String, Object>> xmlError(HttpServletRequest request) {
         
    // ...
 
    }
}

Saturday, February 2, 2019

Devops interview Quetions

1. How to build artifacts in jenkins?
2. How to install plugins without internet?
3. Have you configure slaves?
4. Are you configures Maven,Tfs,Git,java..etc in jenkins?how we can do?
5. What are the issues you are facing in jenkins?
6. How to get outside files inside my container?
7. What is pipeline? are you involve to develop pipeline script?
8. Are you develop shell script? for what purpose you are with shell script?
9. why pipeline we are using?
10.Are you invovle in a maven script?
conduent
==================
1) what is git ignore.can you explain internal process?
2) what is git pull request?
3) what is git pull ,push and fetch and clone?
4) what is branching?c
5)what is git merge how it will works?
6)what is git rebase.can you explain diff b\w rebase and merge?
7)what is Ami.how to create ami?
8)what is ant and maven.diff b\w them?
9)what are the components in build.xml.can you expalin?
10)what are the components in pom.xml.can you expalin?
11)what is sonarqube.how to integrate jenkins with sonarqube?
12)can you explain sonarqube dashboard?
13)what are the components you have worked in aws?
14)have you worked on tfs and clearecase?



. which tool have you used for implement CI/CD ? 2. Any alternate tool do you know for CI/CD ? 3. what is Continuous Integration? 4. what type of jobs have you configured in jenkins? 5. what are the types of jobs are available in jenkins? 6. what is difference b/w freestyle and pipeline? 7. what is pipeline? 8. what is declarative pipeline? 9. what is difference between declarative pipeline and script based pipeline? 10. write the pipeline syntax? 11. what is master/slave architecture? what is the use of master/slave? 12. How many we can connect the slaves? 13. How many ways we can provide security for your jenkins server? 14. what is sonarqube ? have you configure ? How you configure ? 15. what type of artifactory repository tool have you used? 16. what is the use of artifactory tools? 17. How you declare a variables in pipeline? 18. what is DSL language? domain spcific language? 19. what is upstream/downstream projects? what is the use of it? which scenario you configure? 20. If a have 10 repositories i github how many jobs you can configure? 21. Dou you have experience to install jenkins? 22. How you configure jdk,maven,gradle...etc? 23. In my environment i have different version for java implementation projects is there ? How you configure multiple jdk's? 24. what are the plugins have you used in your project? 25. How to take backup my jenkins? thin backup plugin 26. what is jenkins Home directory? 27. How to deleted old builds automatically? 28. How to configure multiple environment deployment?

Monday, January 28, 2019

Spring Bean Life Cycle

  1. Spring instantiates the bean.
  2. Spring injects values and bean references into the bean’s properties.
  3. If the bean implements BeanNameAware, Spring passes the bean’s ID to the set- BeanName() method.
  4. If the bean implements BeanFactoryAware, Spring calls the setBeanFactory() method, passing in the bean factory itself.
  5. If the bean implements ApplicationContextAware, Spring calls the set- ApplicationContext() method, passing in a reference to the enclosing application context.
  6. If the bean implements the BeanPostProcessor interface, Spring calls its post- ProcessBeforeInitialization() method.
  7. If the bean implements the InitializingBean interface, Spring calls its after- PropertiesSet() method. Similarly, if the bean was declared with an initmethod, then the specified initialization method is called.
  8. If the bean implements BeanPostProcessor, Spring calls its postProcess- AfterInitialization() method.
  9. At this point, the bean is ready to be used by the application and remains in the application context until the application context is destroyed.
  10. If the bean implements the DisposableBean interface, Spring calls its destroy() method. Likewise, if the bean was declared with a destroy-method, the specified method is called.
enter image description here

Thursday, December 27, 2018

The Path to Becoming a Software Architect

Have you ever wondered what career opportunities a developer has? What directions are open, beyond what horizons to grow. And most importantly, where are developers beyond the age of 45? Is there a developer among your friends who is over 45? I personally know several developers beyond this age and many of them are hardcore programmers who even saw punch cards back in the day.
There are several career paths a developer might take:
● The first and obvious one is to grow in the area in which you are working. If you are a junior developer, then just grow to middle, then senior and lead roles.
● Transition to another technology stack. Actually, a big number of developers moved into the mobile area when iOS and Android OS gained ground.
● Grow into a manager role. As a developer, the greatest staffing issue I saw was the shortage of competent managers. Clever managers are expensive, hence they are scarce. If the manager has a technical background, that will allow him to be on the same wavelength with the developers.
● Become a software architect. This direction will be considered in this series of articles.
● Get out of IT. Sometimes this happens. It is never too late to do what you like to do.

Article series

  1. The Path to Becoming a Software Architect
  2. Stakeholders in Software Architecture
  3. Types of Software Architects
  4. Quality attributes in Software Architecture. Part I
  5. TBD Quality attributes in Software Architecture. Part II
  6. TBD Software Architect. Diagrams and documentation
  7. Certificates in Software Architecture
  8. Books in Software Architecture
  9. TBD Software Architect. Design vs Architecture

Yes, This Was My Path

In the past 8 years, I have worked with Java EE, then moved to iOS, and became a team lead. I managed various developer teams, including Android, and Web stacks. Created the architecture of the network layer for several services developed by the company, with sockets and REST API. I became acquainted with the managerial role and the prospect of growing in this direction while in the position of team lead for over two years. In my next role, my goal is to grow as a software architect.
For most developers, the function of the architect on the project is often unclear, so in this series of articles, I will try to find the answers to these related questions. Who is an architect, what is the scope of responsibilities, and how to grow in this direction and outline and action plan for myself and beginners wanting to move along this path.

Who Can Benefit from This?

This series of articles will help you if you belong to one of the following categories:
● IT developer or engineer. You are still growing as a developer, but you are looking ahead and planning your career. Even if the goals are initially vague, a person who consciously sets strategic goals will reach them much quicker than a person who does not plan where she is heading.
● Team leader, lead software engineer. You are at the highest stage of the software development discipline. To grow further, you have a choice to either learn one more stack of technologies, pursue a career outside software engineering, or to become a software architect.
● Software architect. You recently took this position, or have been working in this field for a long time. Perhaps one of the main qualities of such a specialist is the understanding that there are always areas that a person does not know and that the learning process is continuous.
● IT manager. Although you are a manager, you understand perfectly well that you should at least approximately understand what your subordinates or colleagues are doing. The acute problem of management is the technical incompetence of the manager in the field in which he or she is managing.

Who is an Architect?

Before moving on to more specific questions, it is necessary to define the software architect role and it responsibilities.
A software architect is a software expert who makes high-level design choices and dictates technical standards, including software coding standards, tools, and platforms. The leading expert is referred to as the chief architect. (Wikipedia, The Free Encyclopedia, s.v. “Software architect”, https://en.wikipedia.org/wiki/Software_architect
Like most high-level positions, there are no clear criteria that define this role. However, it is possible to define a number of responsibilities and qualities that contribute to the career of the architect.
First, let’s consider the characteristics of the architect:
● Communicability. Having talked with many software architects, I heard that it is one of the most important characteristic of this specialist. During the working day, they have to talk with customers in the language of business, managers of all levels, business analysts and developers. If you have a natural charisma and you know how to convince people, then this will be a huge plus, as it is very important to explain your actions correctly. Architects are laconic, eloquent and competent speakers. The software architects with whom I spoke have highly developed skills in communication and persuasion. Another reason why this characteristic is most important is that the architect in this role participates in most discussion making processes, and often compromises must be reach that are acceptable and beneficial for all involved parties.
● Broad and deep technical knowledge. This should be obvious since one cannot become a software architect with a medical background. In addition, the architect usually has knowledge in several technological stacks at a decent level, and should have a good understanding of a few other ones. The software architect should also be prepared to compose a large number of technical documentation, reports and diagrams.
● Responsibility. You should understand that architect decisions are usually the most expensive. Therefore, a person in this position should take the most responsible approach to his work and to the decisions made. If the developer’s error costs a couple days of work of one person, then the architect’s mistake can cost person-years on complex projects!
● Stress resistance. You will have to make decisions because in this role, you will be asked to do so and you will need response. You will be working with different people from different areas, and you will have to deal with rapidly changing demands or even with changing business environments. Therefore, it is necessary to be ready for stress and to look for some ways to escape negative emotions. Work is always more pleasant when it brings pleasure. So if you choose this role only for the money, then think again.
● Management skills. This includes both organizational and leadership skills. The ability to lead a team, which may be distributed and composed of very different specialists, is essential.
● Analytic skills. Even if a specialist has a wide erudition in technology, he has tried many things on his own or participated in projects of various types, this does not guarantee that he can easily change the style of thinking to architect. One of the most important tasks is the ability to represent an abstract problem in the form of some finite real object of the system, which developers are already evaluating, designing and developing. Great communications skills are essential to clearly represent the abstraction in the form of the final system to the members of the team and the customer. It will be necessary to clearly communicate to both business and development, what is still to be done.
If we talk about the responsibilities of the architect, then here is the perfect example from 19th century about bridge construction. At that time, the tests of the newly constructed bridge were the following: the key group of engineers, architects and workers stood under the bridge while the first vehicles were on it. Thus, they staked their lives upon the construction and the strength of the structure. So if there is a question — what is the responsibility of the software architect on the project? The answer is, he is responsible for everything.
If you give up loud and beautiful phrases, then the architect’s work includes:
● Identifying the stakeholders on the project.
● Identifying business requirements and requirements of the stakeholders on the project.
● Designing the entire system based on the received requirements.
● Choosing the system architecture and each individual component of this system at a high level.
● Choosing the technologies for the implementation of each component and connections between the components.
● Architectural review. Yes, yes, it exists.
● Code-review.
● Writing project documentation and its support.
● Creating unified development standards in the company.
● Controlling the architecture during the next iteration of the system release.
This is only a subset of the software architect’s responsibilities. The most important responsibility is complete technical support of the project from the moment of inception, through product release, to development of enhancements. And supporting the next releases. It will be necessary to switch a lot between different tasks during the working day.

How to Become a Software Architect?

To begin with, it is important to define milestone goals that lead to achieving your strategic goal of becoming a software architect. For me, such goals for the next six months are:
● Understand and try several technological stacks. My current knowledge is concentrated in the field of iOS. It is necessary to try Android, several server languages, to start python, and refresh Java EE skills. The architect is a full-stack developer, so it is important to have a broad technical knowledge.
● Reading literature. It is important to determine the most valuable books and articles that will help to grow in this direction. Usually the most effective way to find such literature is ask other professionals in this field for their recommendation. In one of the future articles, I plan to give you such a list of literature.
● Find a mentor. It is desirable to find a software architect at your current place of employment. It is always easier to get experience from a trained specialist than to start considering a certain area from scratch. It is important to be prepared to ask good questions from your mentor.
● Study courses/obtain certificates. There are many courses and certificates available, but only a few are worth their money, and the higher level courses cost a lot of money. Personally, I have attended the architectural courses of Luxoft (http://www.luxoft-training.com/it-course/ARC-001/), which have proven to be a worthy investment. It is extremely important that the lecturer of the course be a professional in this field and be able to answer questions. As for certificates, before starting, it is best to understand whether there are authoritative certification systems for architects and whether it is worthwhile obtaining the certification. This point I will discuss in a future article of this series.
One of the most important parts is a clear and stable plan review. What has been done, what should be reviewed, and where to accelerate or which goal to remove as useless.

Check Your Readiness Level

If you are interested in this introductory article from the series on how to become a software architect, or if you suddenly have thoughts to try this path, it is worth making sure that you really want it.
Firstly, people are afraid of everything new. A new position, new kind of stress, as opposed to the comfortable status quo. Of course, the choice is not always unambiguous and depends on how much you are willing to change something in your life. At the same time, it can depend not only on you, but also on the family, your financial commitments, parents and other factors.
Secondly, this path takes several years. The process of becoming a software architect does not happen overnight. As a team lead, I realized what to do and how to deal with stress only a year after I was appointed to an official position. At the same time six months before that, I performed it unofficially. One software architect I know said that he understood what his responsibilities are 18 months after he was promoted to this role. Such intervals of time are normal and you need to understand whether you are ready to move in this direction. Even if you do not have a stable plan ready, it is better to start taking small steps that move you ahead, rather than remaining in the same place.
Standing in the same place in IT is a synonym for stagnation and personal fetters in life.

Monday, December 24, 2018

Java Streams

In Java-8, Streams can be obtained in a number of ways. Some examples are:

From a Collection via the stream() and parallelStream() methods.
From an array via Arrays.stream(Object[]).
From static factory methods on the stream classes, such as Stream.of(Object[]), IntStream.range(int, int) or Stream.iterate(Object, UnaryOperator).
The lines of a file can be obtained from BufferedReader.lines().
Streams of file paths can be obtained from methods in Files.
Streams of random numbers can be obtained from Random.ints().
Numerous other stream-bearing methods in the JDK, including BitSet.stream(), Pattern.splitAsStream(java.lang.CharSequence), and JarFile.stream().


Here is the list of all Stream intermediate operations:

filter()
map()
flatMap()
distinct()
sorted()
peek()
limit()
skip()

Here is the list of all Stream terminal operations:

toArray()
collect()
count()
reduce()
forEach()
forEachOrdered()
min()
max()
anyMatch()
allMatch()
noneMatch()
findAny()
findFirst()

How to Grow Your Career as Java Developer?

First things first. If you’re someone looking to adopt a new programming language to learn and earn then Java is certainly a great option to begin with. For those still struggling to make it out alive from being a Java intern, keep hanging. Much better is to come for the true ones!
The popularity enjoyed by Java programming language can be attributed to a number of reasons. First of all, it flaunts a basic to learn approach. Secondly, the high-level programming language supports a number of platforms. In fact, Java is one of the desirable programming languages to learn in 2019.
Many of the big names, ranging from IBM to Infosys, rely on Java for surviving in the world of IT. Though a lifespan of 22 years isn’t something that can be considered much for the lifespan of a programming language. However, surviving and leading the frontier makes Java one of the most-demanded programming languages across the globe.
In addition, to be able to develop applications that can work across a wide variety of operating systems, Java is regarded as one of the, if not the, most reliable programming language.

The X-Factor of Java

Every programming language that is still breathing has some X-factor that keeps them relevant. Java’s X-Factor is its ease of use and does that flexibly. Not only easy to learn, but the high-programming language is also easy to use, compile, and debug. The simplicity of Java is its biggest advantage over other programming languages.
As Android is based on Java, the concerning market automatically comes under the umbrella of Java. Although Kotlin is giving a fair run for money to Java for Android application development, Java still leads the Android application market as well as the enterprise back-end market. Hence, Java offers a very diverse range of career opportunities among the variety of industries and markets.
Java is an evergreen programming language (at least, for now). Those opting Java as their career option will find it fruitful to bear with the very humble beginnings. However, being a developer is not easy. You need to keep working to stay relevant in the industry. Not sure how to do that? Well, here are some great ways to improve your career as a Java Developer:

1. Attend Developer Conferences and Join Developer Communities

Attending conferences about the latest happenings in Java will give you a boost in your career. It is a great way of staying ahead and knowing what is going on and what can be expected in the near future. As a Java Developer, you can also join various online developer communities. These are great places to share your knowledge and expertise and in return learn from others in your community.

2. Stay up to Date

While you need to stick to several technologies while working as a Java Developer, you need to stay abreast of the latest ongoings too. You must be well aware of the latest programming languages and frameworks that the developer community is using and also keep an eye on the ongoing and upcoming trends.
Stay aware of the latest developments in the programming community here.

3. Develop Soft Skills

Some would argue that technical knowledge is ample for the role of a developer. This is true but for the early phase in the career of a developer. The more you advance in your career, the more is the requirement of soft skills. Three of the most important soft skills that any developer must have are:
  1. Communication – As organizations grow, there is a need for an inter-department collaboration. By means of improving written and verbal communication, you can be the person behind the initiatives rather than one following them in an effectual way.
  2. Problem Solving – Any Java developer needs to be a problem solver. By coming up with opportune and practical solutions to problems, you can be a valuable part to your team and your employer.
  3. Customer Service – Customer service is an important part of any product or service offering. The progress and success of a product depend on the satisfaction level of the consumer. Hence, it is a great approach to work and grows as well by prioritizing customer satisfaction as one of your end-goals.

4. Dive into Open Source

Open source software and applications are great to work with. They let you do some amazing stuff without sparing even a single penny. Many of the open source projects enjoy active community support. Such projects not only makes your skill better but also allow you to implement your ideas in a creative way.
Check out the latest trending Java repositories at GitHub.

5. Go Freelance

There are just so many online marketplaces where you can endorse your services as a freelancer. In addition to making some additional few bucks every month, it offers you an opportunity to learn better. Different projects will introduce to a whole different level of requirements and tasks.
It’s pretty easy to get started as a freelancer. You need to set up your profile at one of the freelance websites, such as Fiverr and Upwork, and then bid for projects.
Sign up for UpWork here.
Sign up for Fiverr here.

6. Keep a Blog

Keeping a blog is very important for any professional these days, especially those concerned with IT. Start learning to write and share your professional views or personal findings via your blog. Making a blog is super easy with WordPress. You can purchase the web space and web address for a nominal fee. However, if you don’t wish to spend money then you can also get a free one!
While writing on your blog, especially when giving out data or numbers, be sure to back it up. You can’t risk having misleading or wrong information on your blog. That’s the ethical thing to do. Remember, neither the Internet nor the good editors tolerate nuisance.
Here’s a WikiHow Tutorial illustrating how to be a good blogger.

7. Know Your Extras

To stand out from the herd, you need to learn some tools that are lesser known to others. This will give you a significant opportunity. You need to learn about these tools and add them to your development routine. Results will be there sooner or later, but rest assured they will be good.

8. Learn Other Programming Languages

Clinging to a single programming language isn’t sufficient in the present scenario. In addition to your primary programing language of expertise, you need to be adequate in other contemporary programming languages. Therefore, keep learning new programming languages. Even if you aren’t able to code exceptionally well in your secondary languages, you should be able to understand code written in them without a doubt.
Python is a major competitor to Java. Know about the clash of the two leading programming languages and their possible consequences in 2019 here.

9. Stay for Not too Less, Not too Much

There are jobs that don’t offer much to carry for the next role. Hence, it doesn’t matter what work you do in such jobs they are just chores, no learning, no fun. Thankfully, being a Java Developer is not. Changing jobs every 6 months or so is not a good sign, however. Invest some more time and be patient in your present Java developer role.
On the other hand, sticking to the same job for more than 5 years is also not recommended. Therefore, keep looking for better opportunities with higher payouts and more effectual ways to hone your skill set as a Java developer.