Saturday, December 30, 2023

5 Free Data Structure and Algorithms Books in Java Programming

In the last article, I have shared some of the best data structure and algorithms books for programmers, but those were not free. After that article, I received some feedback about how about sharing free data structure and algorithm books? Fair enough, everybody loves free eBooks, courses, and PDFs, don't you? In the past, I have shared a list of free Java programming books, so I had some ideas. I did some more research on the internet and checked my collection as well. Fortunately, there are a couple of good Data Structure and Algorithm books which are available for free as a PDF download or for online reading, which is what I am going to share with you all today.

Top 5 Books to Learn DevOps in 2024 - Best of Lot

DevOps is one of the in-demand skills for experienced developers. It also offers a career path for senior developers who don't want to go to project management and want to remain technical and close to the code, but what is DevOps? and how can you learn DevOps? In the past, I have shared some of the best DevOps courses and a complete DevOps Developer RoadMap, and in this article, I'll share the best books to learn DevOps for developers, but before that let's understand what is DevOps?  It is nothing but is an integration of the word development (Dev) and Operations (Ops). Development here refers to software development, I mean the process of writing code, unit testing, debugging and running source codes to create software. While Operations are Information Technology Operations like deployment, support, and creating new environments.

Top 5 Books to Learn Python in 2024 - Best of Lot

Hello guys, if you want to learn Python and looking for the best Python books then you have come to the right place. In the past, I have shared the best Python 3 courses, best websites to learn Python, Python Developer RoadMapPython questions for interviews, and today, I am going to share the best books to learn Python programming in 2024. Whether you are an AI expert or a Computer Science student, you will come across Python Programming language sooner or later in your career. Starting its journey in 1991, Python has now captured the Programming world. Started as just a scripting solution for trivial stuff, Python is now everywhere.

Friday, December 29, 2023

Top 5 Hibernate Books for Java Developers - Best, Must read

Hibernate is one of the most popular, open-source ORM (Object Relational Mapping) framework, which has now become a standard for developing persistence layer on Java enterprise application, along with JPA (Java Persistence API). I often receive requests to suggest which book is best to learn to hibernate or recommendation about some good books and training courses on Spring and Hibernate. This motivates me to write this article about some of the best books on Hibernate currently available on the market.

Thursday, December 28, 2023

How to sort ArrayList in Natural and Custom Order in Java - Example Tutorial

Sorting ArrayList in Java is a common task for Java developers and we have touched it while discussing in my last article 10 Examples of  ArrayList in Java and again when we discussed comparator and comparable in Java. There are multiple ways to sort ArrayList in Java for example, you an use Collections.sort() method or List.sort(), or Stream.sort() method to sort an ArrayList in Java depending upon which Java version are you using. If you want a solution irrespective of Java version then Collections.sort() is the best way because this method is available since JDK 1.1. In order to sort an ArrayList, we need to use the Collections utility class which contains an overloaded sort() method for sorting different collections and supports different comparators in Java. In this article, we will see how to sort ArrayList in the natural order of elements and then sorting ArrayList in Java with a comparator.

Top 5 Data Structure and Algorithm Books - Must Read, Best of Lot

Data Structure and Algorithms books are often taught as textbooks in various universities, colleges, and Computer Science degree courses, yet, when you put programmers in a situation, where they need to find and decide, which data structures and algorithms to use to solve a problem, they struggles. I have seen this, and I think one reason for this is perspective. When you read something like a textbook and your perspective is just to do well in the exam, you might not be thinking about learning and applying that knowledge to real-world problems. Since data structures and algorithms are the core of any programming problem, it becomes extremely important for programmers to master them even if you have learned well during academics.

Wednesday, December 27, 2023

10 Things Java Programmers Should Learn in 2024 [UPDATED]

It's 27th December now, and only a few days have left in the year 2023, one of the years which brings joy and freedom after a couple of years of lockdown. Now, it's time to look back and retrospect on what you have achieved in 2023 and what you could have done better, despite all the challenges 2023 has thrown to all of us. This will also help you to create your goals for 2024. As a programmer, our biggest challenge is to keep ourselves up-to-date. Technology changes very fast, and you will see a new version of programming language and framework coming to every couple of years. This year has plentiful changes with keeping up-to-date with a new Java version every 6 months, Spring 6.0, Spring Security 6.0, and Spring Boot 3; it's probably the busiest year in terms of changes for Java developers.

Monday, December 25, 2023

Top 10 Java Programming Books - Best of lot, Must Read

Hello guys, if you want to learn Java and looking for the best books to learn Java then you have come to the right place. In the past, I have shared best Java courses, websites, and even a complete Java Developer RoadMap and in this article, I am going to share best books you can read to learn Java programming in depth. These top Java programming books are some of the good books to learn Java and I would say some of them are simply the best Java books ever published. Whenever a programmer starts learning Java programming language, the first question he asks is "Which book should I refer to learn Java?", or "What is the best book to learn Java for beginners?" or "Can you tell me some good books to learn Java?" .That itself says how important Java books are for programmers especially beginners.  

Sunday, December 24, 2023

Top 10 Gift Ideas for Programmers, Software Engineers, and Tech Geeks in 2024

Hello guys, it's that time of the year again when we buy gifts for our loved ones, friends, and colleagues. If you are looking for gift ideas for your programmer friends and colleagues then you have come to the right place. My friend circle has a lot of programmers and non-programmers. When it comes to buying gifts for birthdays, anniversaries, or holidays, I receive a lot of queries from my non-programmer family and friends about what to buy for a programmer? Well, buying a gift is easy but choosing or finding the right gift for someone is really really tough. I have had this experience when it comes to buying gifts for kids. 

10 Spring Framework Books Experienced Java Developers Should Read in 2024 - Best of Lot

The Spring framework has changed a lot in the last couple of years. We have seen significant releases for Spring, Spring Boot, and Spring Security. These new releases introduced several exciting features to meet the latest software development trends, like Reactive programming, support for Kotlin for developing Spring applications, Spring WebFlux - a new framework to build non-blocking and reactive web applications,  and many more. Since the software world is changing and most of the development is happening on Cloud with Microservice architecture leading the way, it's high time that experienced Java developers should upgrade themselves.

Saturday, December 23, 2023

5 Must Read Books to become Software Architect or Solution Architect

I receive a lot of queries from senior Java developers, who aspire to become software architect or solution architect, like what can they do to become a software architect? Which books, resources, or certifications can help? And general queries like how much experience you need to become a software architect etc. In the past, I have been suggesting them individually about some books to read to expand their knowledge base and look at the software from architecture and design perspective, and this article is a compilation of many of such suggestions. Since a lot of books can confuse, I have only select 5 best and must-read books from the software architect's perspective.

Tuesday, December 19, 2023

Top 5 Big Data and Apache Spark Courses for Java Developers to Learn Online - Best of Lot [2024]

A slowing economy and the recent trend of job cuts in India and elsewhere have made many programmers anxious about their job security. I receive a lot of emails and Facebook chats about suggestions to improve IT skills to remain competitive and marketable. So, if you are in the same boat, you can learn Big Data and IT Automation to remain marketable. These two skills are in great demand and will generate a lot of jobs in the future. I have suggested many Java developers around the world learn Big Data Technologies like Apache Spark to give their CV a new boost. Since it's not easy to learn new technology and at a certain age, you feel a lot of restriction and resistance from both your body and mind. In order to overcome that I found a combination of books and online courses works great.

Sunday, December 17, 2023

How to enable Spring MVC in Java Web Application? Example Tutorial

In last article, I have shared thoughts on how to enable Spring Security on Java Web application, where my reader also shown interest to know how to configure/enable Spring MVC in Java web application. Though, this is very basic information, it helps a lot to anyone who is new to String framework and want to understand then essential steps required to enable Spring MVC framework for a Java based web application. It's easy to configure Spring MVC if you have developed a simple hello word kind of program using Servlet or JSP and familiar with web application fundamentals in Java world e.g. Servlet container like Tomcat, deployment descriptor file or web.xml, Servlet or JSP itself and some essential tags on web.xml e.g. <servlet> and <servlet-mapping>, <url-pattern> etc. 

Monday, December 11, 2023

How to conditionally render view in JSP using Spring Security tag library? Example tutorial

One of the common requirement of secure Java application is to show and hide content based upon role of current user. For example, a logged in user can see his name e.g. Welcome User1 but that link is not visible to an unauthenticated user. Similarly, a user with admin role can see a lot of admin related functionality which should not be visible to a normal user e.g. add/remove users, disable users, create roles, edit roles etc. How can you achieve such condition based rendering in view? Does spring security support that? Well, the answer is Yes. Spring security provide a tag library which you can use in JSP pages to perform a lot of authentication and authorization related stuff e.g. you can access current user's name, you can access access current user's role and you can also conditionally show/hide certain section of views based upon user's role. 

Wednesday, December 6, 2023

How to Crack Microsoft Azure Administrator Associate AZ-104 Certification Exam in 2024

Hello guys, if you are looking for cloud certifications in 2024 then Microsoft Azure Cloud certifications can be a great addition to your profile. Azure certifications are one of the top cloud certifications you can take in 2024 along with AWS certifications. Earlier, I have shared a few tips, courses, and practice tests to pass the AZ-900 or Microsoft Azure Fundamentals exam and today, I'll talk about AZ-104 or Microsoft Azure Administrator certification.  A couple of years ago, Microsoft launched two new certifications AZ-100 and AZ-101. These are the replacement of 70-535 for the new role-based Microsoft Azure Administrator Certification. On May 1, 2019, both AZ-100 and AZ-101 exams as well as AZ-103 exam have been replaced by the AZ-104 exam and till date it is the only exam you need to pass to become a certified Azure administrator associate in 2024.

Tuesday, December 5, 2023

Top 8 Online Courses to Learn Cyber Security and Information Security in 2024 - Best of Lot

If you want to learn Cyber Security and Information Security and looking for the best Cyber Security online courses, then you have come to the right place. In this post, I have shared the free Cyber Security and Web Security Courses for beginners.  There is no doubt that Cyber Security and Information Security are essential for business in today's environment, where companies face high risk from malware and other kinds of software viruses and online threats. It's also one of the most overlooked areas from programmers, especially from India and South East Asia, where most computer engineers want to go into application development. 

Top 7 Node.js and Express JS online courses for Web Developers in 2024 - Best of Lot

There is no doubt that JavaScript is the #1 Programming language in the world and Node.js is one of the biggest reasons for that. Initially, JavaScript was considered just a client-side scripting language but Node.js has changed all that by allowing developers to create dynamic web pages on the server-side using JavaScript. It is also rated as the most popular framework on the StackOverflow Developers survey. The most important benefit of Node.js is that it allows you to build a full-stack application based on just one language, JavaScript. This is especially useful for start-ups that put a lot of emphasis on being able to iterate early and often.

Monday, December 4, 2023

How to Crack AWS Certified Solution Architect Associate Exam SAA-C03 in 2024

There is no doubt that AWS certification is precious and opens the door for a lot of opportunities, not just for system admins but also for developers and DevOps. Even though there is no substitute for knowledge and experience there are a lot of tangible and intangible benefits of AWS certifications, mainly AWS Certified Solution Architect Associate. Your certification is useless if you don't know how to work in AWS console, but if know that and still struggling to find a job then AWS certification can help you. First thing, it gives you recognition. It allows you to put AWS in your resume and LinkedIn and also get you a lot of chances as recruiters and companies prefer certified professionals over a non-certified if skill set matches.

Spring Professional Develop 2024 Certification Guide - [VMware 2V0 -72.22 FAQ]

If you are a Java developer, working in the Spring framework, and thinking to become a certified Spring professional but couldn't do it in the past due to expensive mandatory training provided by Vmware and its partners then there is good news for you. Now you can take online Spring training courses from Vmware for appearing to the Spring Professional Develop certification exam, which means, now, it's not mandatory to take expensive Spring training for Spring certifications (see here). Similar to Oracle's Java certifications, you can become a Vmware Certified Spring Professional by just buying the exam vouchers and scheduling your exam online using examlocal.com from anywhere in the world.

5 Best Java 8 and Functional Programming Books for Beginners and Experienced [UPDATED]

If you follow Java updates, you may know that Java 13 was released, and Java 14 is on the way, but I often receive emails and queries asking about some good books to learn Java 8. Since Java 8 is very different from any other JDK release, in terms of language and API enhancement, you really need an excellent book to learn fundamentals. In short, based upon my 2 years of learning and reading Java 8 books, I can say that Java SE 8 for Really Impatient is hands down the best book to learn Java 8. It covers all the essential things released in JDK 8, not just lambda expression and streams but also new Date and Time API and several other minor enhancement yet crucial features, which often go unnoticed.

Top 7 Courses to Learn Shell scripting in Linux (bash, ksh, csh) Online in 20243 - Best of Lot

Hello guys, you might know that a massive chunk of a developer's time is wasted in trying to repeat tasks and commands, especially when it comes to working with a bunch of UNIX or Linux machines, and a good knowledge of shell scripting can free you from such mundane task and give time to do some interesting stuff. If you don't know what shell scripting is then let me tell you is nothing but a program written using shell built-ins, and Linux commands to automate things, like checking if a host is reachable or finding and deleting large files that are older than certain days or archiving them into another machine.

Top 6 Advanced SQL Books for Experienced Programmers - Best of lot, Must read

If you an experienced programmer and know how to write SQL queries and database fundamentals but want to take your SQL and database skills to the next level then you have a come to the right place. In this blog, I have shared a lot of free SQL books and courses you can use to start your SQL journey. This is also the second article about SQL books, In the first part, I have shared some of the best SQL books which are essential to learning SQL queries and fundamentals of database like normalization, indexing, and other design stuff, if you haven't read it yet, I suggest to do it now. You will find some amazing books to start learning SQL.

How to get current logged in user in JSP and Controller using Spring Security? Example Tutorial

One of the common task while using Spring Security in a Java web application is getting the username of currently logged in user. Sometime, you need that in your controller class and sometime in JSP for view purpose, but the big question mark is how do you get the current user in Spring Security? Well, there are many ways to do it and depending upon whether you need it inside a JSP page or Controller class, you can choose them. The current user, also known as Principal in Spring Security can be obtained from the UserDetails class, which holds all details for currently logged in user. You can get this class from the SecurityContext, which in turn can be retrieved from SecurityContextHolder as shown below:

Sunday, December 3, 2023

Top 7 Books for Programming/Coding Interviews in 2024 - Best of lot

If you are preparing for Programming Job interviews and looking for some of the best books for programming questions, then you have come to the right place. In this article, I am going to share a couple of good books to prepare coding, software design, and data structure algorithm questions, which are essential for any coding interviews. Though a programming interview also explores other areas of software development, like the programming language, you would be mainly used in your project, like, C++ or Java. The database and SQL-based questions, the operating systems, and UNIX-related questions, some of the software design and object-oriented design pattern questions, and much more, but coding-based questions form the core of programming interviews.

Udemy vs CodeCademy vs Zero to Mastery Review? Which is the best place to learn Programming in 2024?

Online learning, particularly online courses, has completely changed the way people learn things as whoever I speak from beginner to professionals; everyone seems to prefer learning online. The current global situation has also accelerated the need for online learning. This is a nice change, but, with so many choices available, there is also a lot of confusion which often pops up when I discuss with my readers. One question which has been kept coming in the past is which platform to choose for learning online? CodeCademy, Udemy, or ZTM Academy? This is the most common question among all beginners mind who have just started to learn coding and programming online.

Friday, December 1, 2023

Top 8 Courses to Learn Angular Framework in 2024 - Best of Lot

If you are a Web developer or someone who wants to learn Angular for web development and looking for some excellent resources, like books, online courses, and tutorials, then you have come to the right place. In the past, I have shared some of the best Angular tutorials, and best Angular books, and today, In this article, I am going to share some of the best Angular courses to learn modern-day web development. If you don't know what Angular is and how it helps you to develop modern-day web development, let me give you a brief overview. It's a JavaScript front-end framework that allows you to build a modern big e-commerce web application as well as a single-page web application that runs on a browser.

Tuesday, November 28, 2023

Top 6 Courses to Crack AWS Solutions Architect - Associate Exam (SAA-C03) in 2024 - Best of Lot

Hello guys, are you preparing for AWS Solutions Architect - Associate Exam?  or Do you want to become Amazon Web Services (AWS) Certified Developer in 2024 to give your Cloud Computing career a push? and looking for some useful resources to prepare well for your exam then you have come to the right place. In the past, I have shared some free courses to learn AWS for beginner and in this article, I will share some of the best online courses to pass the AWS Solutions Architect - Associate Exam and become Amazon Web Services Certified Associate - a certification which will not only add value into your resume but also help you to get the high-paying job you always wanted.

Sunday, November 26, 2023

Top 6 Online Courses to Learn Kubernetes in 2024 - Best of Lot

Hello guys, Kubernetes has become a very popular tool and skill today in the container management community, and it's one of the most in-demand skills and a must-learn tool for both DevOps engineers and Developers. It is a tool written in Golang and it is created by Google. There are many things you need to take care of when working in production environments with microservice patterns and containers. These include version control, health check, rollback mechanism, and scaling. Kubernetes provides the management and orchestration capabilities to deploy containers in accordance with all the necessary mentioned things.

How Request mapping or HandlerMapping works in Spring MVC? @RequestMapping Example

Hello guys, In last a couple of articles, we have learned how Spring MVC framework works and what is the role of DispatcherServlet in Spring MVC. We have briefly touched another frequently asked Spring MVC interview question, how does requests are mapped to controllers in Spring MVC? In this article, we'll expand our knowledge on that. You have learned that DispatcherServlet is the front controller in Spring MVC framework, it is the single point entry and all incoming request goes through it, but instead of processing those request it just dispatches the request to the appropriate handler methods based on the request mapping, but how does it do that?

15 Best Udemy Courses to Learn Python Programming in 2024 [UPDATED]

Hello guys, If you want to learn Python programming and looking for the best Udemy courses to learn Python online, then you have come to the right place. Earlier, I have shared the best Python courses and free Python courses for both beginners and experienced Python developers but In this article, I am going to share the top 10 Udemy courses to learn Python in 2024. This includes both hands-on and project-based courses where you will learn by doing, I mean you will actually build the projects using Python. This is the best approach to learning any new technology or skill, including Python. By the way, when it comes to learning online, Udemy is my go-to place because of affordable pricing and some high-quality courses.

Monday, November 20, 2023

How to secure an URL using hasRole() in Spring Security? Is it enough to hide sections of JSP to protect URL? Example?

One of the Spring security question asked to me on a recent interview was about is it enough to hide portions of JSP to protect a URL from unauthorized access in Spring security? First of all I didn't understand the question, so I ask him to clarify a bit more. He explained to me that there are different roles in his application e.g. DEVELOPER, ADMIN, TRADER, OPERATION and each role can only see the functionalities based upon their role. For example, an ADMIN has a right to add or remove new users into the system, while DEVELOPER can only see test order, but OPERATION can see all orders. 

Monday, November 13, 2023

How to show current logged in username in JSP using Spring Security? Example Tutorial

One of the common feature of secure Java web application to show the username as link on the top right corner of web application once user successfully logged in. Some application also show the logout or sign-out link like that but how do you display the current user or principal name in a JSP page secured using Spring security library? Well, Spring Security provides a small but userful JSP tag library which contains custom tags similar to JSTL, which can show a lot of useful authentication and authorization details of current user. For example, you can use <s:authetication> tag to display the current principal details including the username of currently logged in user. The tag name is authentication here and s is the prefix you specify while importing tag using taglib directive in JSP. 

Sunday, November 5, 2023

5 Ways to Update Values in ConcurrentHashMap in Java 8 - Example Tutorial

In last article, I have showed you how to update value in HashMap and today we'll learn about how to update value in a ConcurrentHashMap. Some of you may question, can we use the same technique we used to update a value in HashMap here? well, you can but you need to keep in mind the difference between an HashMap and a ConcurrentHashMap. The HashMap is only meant to be updated by one thread at a time, hence you don't need to pay any attention to thread-safety or concurrency, but ConcurrentHashMap can be updated by multiple threads at the same time, hence you need to pay special attention. 

Monday, October 30, 2023

Why Java and Spring Developers Should Learn RESTful Web Services and Microservices

More and More companies are adopting  Microservices architecture e.g. Uber and Netflix already uses it and many startups I know is choosing REST and MicroService as the standard way to build and provide their services. This is fueling the demand for programmers who can develop robust and scalable Microservices and RESTful Web Services. Since Java is one of the most popular language for developing backend, it is also benefiting from this trend. The demand for Java developers who knows Spring framework and understand how to build RESTful web services is huge and that's why it has become a key skill in Java application development job market. 

Monday, October 23, 2023

15 Example of print() and println() methods in Java

Hello guys, if you have learned Java in early 2000 then there is  good chance that you must have written your first Java code using System.out.println(). For a long time, I have no idea what that mean but I alway use it to print messages on console. When I started working in Java and preparing for Java certification then I come to know that System is a class and out is an object of PrintStream which has println() method. That was a revelation for me. I also found that Java provides a powerful set of I/O classes for handling various input and output operations. Among these, the PrintStream class stands out as a versatile tool for writing formatted text to output streams. The print()printf() and println() methods within the PrintStream class, as well as System.out.println(), are particularly useful for printing different types of data to the console or other output destinations.

Sunday, October 15, 2023

Top 6 Books to Learn and Master Programming and Coding - Must Read, Best of Lot

Coding is an integral part of Programming, and we all somehow learned to code by following examples here and there. Yes, I am talking about both self-taught programmer and Computer Science Graduates. You can learn Coding easily if you are dedicated, but what is more difficult is to write good code. You can easily find programmers in Java, C++, Ruby, or Python, but finding programmers, who are also a good coder is very difficult. Some universities have a good curriculum and practical classes to teach coding better than others, but most of these great coders are self-taught Programmers, who learned by reading books, joining online courses, and doing things on their own.

Wednesday, October 11, 2023

Top 7 Courses to learn Data Structure and Algorithms in 2024 - Best of Lot [UPDATED]

Hello guys, both Data Structures and Algorithms are one of the most essential topics for programmers and if you want to learn Data Structure and Algorithms in 2024 then you have come to the right place. The best thing about them is that they never get out-of-date, and any investment you made in terms of time and money will pay rich dividends for a long time. I have also found that people good at algorithms and data structures are often better programmers than others. They tend to improve your programming skill and coding sense, and that's the main reason I suggest all kinds of programmers, from junior to senior to spend some time revising, refreshing, and honing their data structure and algorithm skills.

Tuesday, October 10, 2023

How to fix Eclipse - Could not reserve enough space for object heap in Java? Solution

If you are running Java program in Eclipse and ever tried playing with -Xmx parameter you know about those virtual machine initialization error e.g. "“Error occurred during initialization of VM; Could not reserve enough space for object heap”. This error usually occur when you to try to give your program, running on 32-bit JVM more than 1.4G of memory in Eclipse in Windows. It doesn't matter how much memory your machine have e.g. I have seen this error in laptops running 4GB of memory. The important thing which matter is whether JRE or JVM you are using with Eclipse is 32-bit or 64-bit. If you use 64-bit JRE in Eclipse, you can potentially allocate more than 1.4G of memory in Windows itself.

Monday, October 9, 2023

How to fix java.net.SocketException: Connection reset by peer: socket write error? [Solved]

"Exception in thread "main" java.net.SocketException: Software caused connection abort: socket write error" comes when you are writing into a connection which is already closed by your peer i.e. the other party in the connection. For example, if you are server and sending response to client but client closed its connection before you complete writing response, the write() method of DataOutputStream will throw this error. It's not necessary that this error will only come when you are using DataOutputStream, it can come even if you are just using and OutputStream or SocketOutputStream point is you are writing in a socket which is closed by other end. Here is the actual error message with stacktrace:

Sunday, October 8, 2023

2 Ways to remove whitespaces from String in Java? Example Tutorial

You can remove blanks for whitespaces from a Java String by using the trim() method of java.lang.String class of JDK API. Unlike SQL Server which have LTRIM() and RTRIM() methods to remove whitespace from String, Java doesn't have ltrim() and rtrim() methods to trim white spaces from left and right, instead it just have a trim() method which removes all spaces from String including space at the beginning and at the end. Since String is Immutable in Java, it's worth noting that this method return a new String if original String contains space either at beginning or end, otherwise it will return the same String back. 

Friday, October 6, 2023

How does Remember Me functionality works in Spring Security?

In the last article, You have learned how to enable the remember-me functionality in Spring security and today you will learn how does Remember Me work under the hood. So far, you know that remember-me functionality uses cookie to remember users and allow auto-login (without entering password again), so you might have guessed that spring security provides hooks to generate that cookie as well as process those cookie when an already signed user open the application after the break e.g. after a day or two. As long as cookie is not expired and token is valid i.e. user hasn't changed the password, he should be able to login to your application. 

Wednesday, October 4, 2023

6 ways to sort ArrayList in Java 8? List.sort() + Collections.sort() Example Tutorial

There are many ways to sort an ArrayList in Java 8; for example. you can use the old but still rocking way to sort a List by using Collections.sort() method, or you can use the newly added sort() method in the List interface in Java, or you can use the new java.util.stream API to sort a list of objects. You now have multiple choices when it comes to sort a List or Array in Java. Though, my preferred way is Collections.sort() method because it is available to all the Java versions and its easy to use and it also allows you to sort in any custom order.  The method is overloaded which gives you ability to sort a list of objects into their natural order as well allow you to supply a Comparator of your choice to sort elements into customer order. 

Tuesday, October 3, 2023

How to enable RememberMe Functionality in Spring Security

Hello guys, most of the web application has login or authentication functionality where user need to enter their username and password to access functionalities provided by application. This is great from application's perspective because functionalities are protected from anonymous user but from user's perspective he would appreciated something which would not ask him/her to enter username and password every now and then. This is what remember me functionality of Spring security does. It allow you to build a web application which can remember their user and allow them to automatically login when the restart their browser or come back another day. 

Top 5 Online Courses to learn gRPC and Google Protobuf in Java, Python, Golang & C# in 2024 - Best of Lot

If you are a Java developer then you might have heard about the gPRC, the Google Remote Procedure Call solution. It's the latest buzz in the tech circle, and people are talking enthusiastically about it. The buzz is evident because it's coming from Google like Angular, Golang, Flutter, Dart, TensorFlow, and other latest technologies. For those who don't know, gRPC is a super-fast, super-efficient Remote Procedure Call (PRC) system that will help you to develop distributed systems like Microservices. This means you can use gPRC to communicate between your Microservices at super-fast speed.  Similar to other RPC solutions like SOAP, it allows a client application to call a method on the server as it is a local object. The server defines service and indicates that it can be called remotely with method parameter and return type and then provides implementation and an RPC server that can handle client calls.

Monday, October 2, 2023

Top 5 Online Courses to Learn MongoDB NoSQL Database in 2024 - Best of Lot

MongoDB is one of the leading NoSQL databases and it was on my radar for a long time but I never get a chance to learn or work on it, but Recently I got an opportunity to use MongoDB for one of our projects and I learned a lot on the way. In this article, I will introduce MongoDB and how to learn MongoDB so that you can use it in your project. In this article, I will share some of the online courses which I have taken to understand everything up to the basic CRUD (Create, Retrieve, Update, Delete) operations on MongoDB. I have also read a couple of books and followed some tutorials but these courses were my main source to learn Mongo DB.

Saturday, September 30, 2023

10 Exception handling Best Practices in Java Programming

Exception handling is an important part of writing robust Java applications. It’s a non-functional requirement for any application, to gracefully handle any erroneous condition like resource not available, invalid input, null input, and so on. Java provides several exception handling features, in built-in the language itself in form of try, catch, and finally keywordJava programming language also allows you to create new exceptions and throw them using  throw and throws keyword. In reality, Exception handling is more than knowing the syntax. Writing a robust code is an art more than science, and here we will discuss few Java best practices related to Exception handling.

How to Fix Exception in thread "main" java.lang.ExceptionInInitializerError in Java Program? Example

JVM throws java.lang.ExceptionInInitializerError, when there is an Exception inside static initializer block. If you know about static variables in Java, then you may know that they are initialized at the time of class loading. If there is an Exception during that initialization of static variables, you will see ExceptionInInitializerError in Java. This could be any exception e.g. java.lang.ArrayIndexOutOfBound or java.lang.NullPointerException. Java developers are often confused with this error because they think that they have not defined any static initializer block, then how come they are getting ExceptionInInitializerError; well, by default Java combines all static variable initialization inside a static initializer block and initialize them in the order they are declared in the source file.

How to fix java.io.FileNotFoundException: (Access is denied)? Example

Earlier my impression was that java.io.FileNotFoundException: (Access is denied) comes when you try to read a text or binary file for which you don't have permission from the Java program but this can also come while you are using the jar command. jar command internally uses java.util.zip.ZipFile class to open any jar or war file which can throw java.io.FileNotFoundException: (Access is denied). I was trying to see the contents of the war file which was created using a recent build when I stumble upon this error, see the exact command below:

test@dev454:war-store/target jar -tvf maven-eclipse-web-demo
java.io.FileNotFoundException: maven-eclipse-web-demo (Access is denied)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:127)
        at java.util.zip.ZipFile.<init>(ZipFile.java:88)
        at sun.tools.jar.Main.list(Main.java:979)
        at sun.tools.jar.Main.run(Main.java:224)
        at sun.tools.jar.Main.main(Main.java:1149)

How to resolve java.lang.UnsupportedClassVersionError:Unsupported major.minor version 49.0 to 65 with example

The java.lang.UnsupportedClassVersionError  is a quite common error after NoClassDefFoundError or ClassNotFoundException they all seems to related to class files but they all are different and there cause and resolution are different. In this java tutorial, we will see what is UnsupportedClassVersionError in Java? Why UnsupportedClassVersionError comes in Java? What are a class file format and version numbers associated with it and finally how to resolve UnsupportedClassVersionError in Java? 

Thursday, September 28, 2023

Fixing java.net.BindException: Cannot assign requested address: JVM_Bind in Tomcat, Jetty

One of the most dreaded errors in Java-based client server-based applications is a networking-related error, e.g. java.net.BindException: Cannot assign requested address: JVM_Bind. I have faced this issue while working with web servers like Tomcat, Jetty, and Weblogic before, but yesterday it came again when one of my colleagues faced this issue in Windows. As soon as Java programmers see java.net.BindException, they come to the conclusion that it's an issue with two processes listening on the same port and often mistook it for Java.net.BindException: Address already in use: JVM_Bind:8080, which is slightly different than this.

How to Fix java.net.ConnectException: Connection refused: connect in Java

java.net.ConnectException: Connection refused: connect is one of the most common networking exceptions in Java. This error comes when you are working with client-server architecture and trying to make a TCP connection from the client to the server. Though this is not as cryptic as java.lang.OutOfMemoryError: Java heap space or java.lang.UnsupportedClassVersionError, it’s still a frequent problem in distributed Java applications. java.net.ConnectException: Connection refused: connect also comes in the case of RMI (Remote Method Invocation) because RMI also uses TCP-IP protocol underneath. While writing client socket code in Java, You should always provide proper handling of this exception

How to solve java.util.NoSuchElementException in Java? Example

How to fix java.util.NoSuchElementException in Java

java.util.NoSuchElementException is a RuntimeException that can be thrown by different classes in Java like Iterator, Enumerator, Scanner, or StringTokenizer. All of those classes have a method to fetch the next element or next tokens if the underlying data structure doesn't have any element Java throws "java.util.NoSuchElementException". The most common example of this is iterating over hashmap without checking if there is an element or not and that's why it's advised to use hashNext() before calling next() on Iterator. In this Java tutorial we will what causes NoSuchElementException in Java and how to avoid it completely.

How to fix java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory or "Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory" exception comes when you don't apache commons-logging-1.1.1.jar in your Classpath. I have faced this exception many times while using open-source frameworks like Struts, Spring, and Displaytag which uses a commons-logging framework for logging. commons-logging is not an actual java logging framework but provides a wrapper so that you can use log4j, java logging, or any other Java logging framework.

Top 10 DevOps Certifications for Experienced IT Professionals in 2024

Hello guys, DevOps, a combination of software development and IT operations, has become a widely adopted approach in the modern software industry. It emphasizes collaboration, automation, and continuous integration and delivery to streamline software development and deployment processes. To excel in the field of DevOps, professionals can pursue certifications that validate their knowledge and skills in various DevOps practices and tools. In the past, I have shared best Cloud Computing Certifications and best Certification for Java developers and in this article, we will explore the top 10 DevOps certifications for 2024 that can help bridge the gap between development and operations.

Wednesday, September 27, 2023

[Solved] How to find and Print Armstrong number between 0 and 9999 in Java? Example

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153 is an Armstrong number, since 1**3 + 5**3 + 3**3 = 153, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. Along with usual beginner exercises like calculating factorial, reversing a string, or calculating prime numbers, this is a good exercise to build programming logic. It teaches you basic programming techniques of how to use the operator for something which is not obvious.

Java Program to Multiply Two Matrices - Matrix Multiplication Example

How to write a Java program to multiply two matrices in Java is a very good programming exercise to get familiar with the two-dimensional array in Java. this example teaches about how to multiply arrays, how to access elements from a multi-dimensional array, how to pass them to a function etc. Since the matrix is a natural representation of a multi-dimensional array in Java, they are often used to illustrate real word matrix exercises e.g. the calculating sum of two matrices or calculating the difference of two matrices, etc. It's also one of the popular Matrix based coding problems you can find on coding interviews. 

[Solved] How to Implement Binary Search in Java without Recursion? Iterative Algorithm Example Tutorial

Hey Java programmers, if you want to implement a binary search in Java, and looking for both iterative and recursive binary search algorithms then you have come to the right place. Earlier, I have shared the free courses to learn Data Structure and algorithms in Java, and today, I am going to teach you an important algorithm.  In computer science, a binary search or half-interval search is a divide and conquer algorithm which locates the position of an item in a sorted array. Binary search works by comparing an input value to the middle element of the array. The comparison determines whether the element equals the input, less than the input or greater. 

How to Implement Stack data structure in Java? Example Tutorial

The stack is one of the popular data structures which supports LIFO (Last In First OUT) operation. Due to the LIFO advantage, you can use a stack data structure to convert a recursive algorithm to an iterative one. The stack data structure is very easy to implement using an array or linked list, but you don't have to implement it on your own because Java already provides a Stack implementation in java.util.Stack class. This class is a subclass of the Vector class and you should use it whenever you need Stack for your production code, there is no point in inventing the wheel again when the focus is on developing your application.

How to check if a given Number is Binary in Java? [Solved] Example

Today we will take a look at another simple programming exercise, write a program to check if a number is binary in Java. A number is said to be binary if it only contains either 0 or 1, for example, 1010 is a binary number but 1234 is not. You can not any library method to solve this problem, you need to write a function to check if the given number is binary, you can use basic constructs of Java programming language e.g. operators, keywords, control statements, etc. If you are a regular reader of Javarevisited, then you know that I love to share simple programming problems here.

How to find Middle Element of Linked List in Java in Single Pass

ow do you find the middle element of LinkedList in one pass is a programming question often asked Java and non-Java programmers in telephonic Interview. This question is similar to checking palindrome or calculating the factorial, where the Interviewer sometimes also asks to write code. In order to answer this question candidate must be familiar with the LinkedList data structure i.e. In the case of the singly LinkedList, each node of Linked List contains data and pointer, which is the address of the next Linked List and the last element of Singly Linked List points towards the null. Since in order to find the middle element of the Linked List you need to find the length of the linked list, which is counting elements till the end i.e. until you find the last element of the Linked List.

How to find the 3rd (Kth) Node from end of linked list in Java? Fast and Slow Pointer Example [Solved]

Hello guys, the problem to find the 3rd element from the end in a singly linked list or Kth node from the tail is one of the tricky but frequently asked linked list problems in Programming job interviews. I know you can easily solve this problem by moving from tail to head or in the reverse direction but the main challenge here is to solve the problem in just one pass. That means, you can not traverse the linked list again and you cannot traverse backward because it's a singly linked list. So what do you think? Isn't this problem challenging? Well, I did struggle when I saw this problem very first time but once you understand the logic and some tricks to solve a linked list based problem like Recursion then it would be easy for you, and that's what you will learn in this article.

How to Remove a character from String in Java ? Recursion Example [Solved]

Hello guys, if you are wondering how to remove a given character from a String in Java then you have come to the right place. In the past, we have solved many common String coding problems like String anagram check, String Palindrome check, and String permutation and in this article, you will learn how to remove a given character from a String in Java. Basically, you need to write a program to remove a given character from String in Java. Your program must remove all occurrences of a given character. For example, if given String is "aaaaa" and String to remove is "a" then the output should be an empty String. Similarly, if input String is "abc" and character to remove is "b" then your program must return "ac" as output. 

How to Print Pyramid Pattern of Alphabet Characters in Java? Example Tutorial [Solved]

In earlier programming tutorials, I have taught you how to print a pyramid pattern of stars and numbers in Java, and in this tutorial, you will learn the printing pyramid patterns of alphabets. If you understand the logic of previous programs then this one won't be difficult for you because we will use the same logic of printing rows and columns using the nested loop in Java. Actually, a pyramid pattern is nothing but a matrix where you need to print rows and columns. Though, you need to learn where to print those values and when to move to the next row.

Tuesday, September 26, 2023

What is LongAdder, AtomicLong, and LongAccumulator in Java? How it works? Example Tutorial

Hello guys, Concurrency in Java can be a challenging aspect of software development. As applications become more multithreaded and concurrent, Java developers often face issues related to thread safety, contention, and performance bottlenecks. To address these concerns, Java provides various tools and classes, one of which is LongAdder. In this article, we will explore what LongAdder is, when to use it, how to use it, and some best practices. You will be surprised to see how useful this little unknown class can be when multiple threads need to atomically update a shared counter like running count. 

How to calculate large factorial using BigInteger in Java? Example Tutorial

Factorial of numbers greater than or equal to 13 cannot be found using primitive int data type as shown in our earlier factorial solution due to overflow. These factorials are too large to fit in an int variable, whose maximum value is just 2147483647 (2^31 -1). Even if we use the long data type, factorials greater than or equal to 21 will generate an overflow. To find the factorial of anything above 21, you need to use the BigInteger class from java.math package.  As the name suggests, BigInteger class is designed to hold a really large integer value, something which is even bigger than the maximum value of long primitive like 2^63 -1 or 9223372036854775807L.

[Solved] How to find Largest Prime Factor of a Number in Java? Example

Hello guys, one of the common programming kata to learn coding is to write a program to find the largest prime factor of a number. Earlier, we have solved how to check if number is prime or not and in this article, we will calculate prime factors of a given number in Java.  Like any other programming problem, you need to build the logic to solve this problem. Before solving the problem, let's revise the concept of number theory. Prime factors of a positive integer are the prime numbers that divide the number exactly i.e. without any remainder, and prime factorization is the process of finding all prime numbers when multiplied together to make the original number.

3 ways to swap two Numbers without using Temp or Third Variable in Java?

How to swap two numbers without using temp or third variable is a common interview question not just on Java interviews but also on C and C++ interviews. It is also a good programming question for freshers. This question was asked to me long back and didn't have any idea about how to approach this question without using temp or third variable, maybe lack of knowledge on bitwise operators in Java or maybe it didn't click at that time. Given some time and trial error, I eventually come out with a solution with just an arithmetic operator but the interviewer kept asking about other approaches of swapping two variables without using temp or third variable.

Java 8 Compute(), ComputeIfAbsent() and ComputeIfPresent() Example Tutorial

Hello guys, if you have been doing Java development then you know that Java 8 brings a lot of changes not just on programming language part by introducing Lambda expression, default methods on interface, static method on interface but also on API  and SDK part like Stream API and new Date and Time API. But while those bigger changes get lot of coverage many small changes but very useful in day to day programming task doesn't get enough mention and many Java programmers are unaware of those. One of such enhancement was addition of compute(), computeIfAbsent(), and computeIfPresent() method in java.util.Map interface. Adding  a new method on an existing interface was not possible before Java 8 but new feature like default and static method on interface made it possible and Java designers take full advantage of these two feature to enhance and improve existing interface like Collection and Map. 

Monday, September 25, 2023

How to Find Largest and Smallest of N numbers without using Array in Java? Example

One of the common programming questions is, how do you find the largest and smallest number in N numbers without using arrays in Java? Can you write a program to solve this problem? Well, it's very similar to the problem we have seen before, find the largest and smallest of 3 integers. You can use the same approach and generalize it for N numbers. All you need to do is start with largest as Integer.MIN_VALUE and smallest number as Integer.MAX_VALUE and loop through N numbers. At each iteration, compare the number with the largest and smallest number, if the current number is larger than the largest then it's a new largest, and if the current number is smaller than the smallest then it's a new smallest number.

How to Remove Duplicate Characters from String in Java? Example

This week's coding exercise is to remove duplicate characters from String in Java. For example, if the given String is "aaaaaa" then the output should be "a", because the rest of the "a" are duplicates. Similarly, if the input is "abcd" then the output should also be "abcd" because there is no duplicate character in this String.  By the way, you can not use any third-party library or Java API method to solve this problem, you need to develop your own logic or algorithm and then write code to implement that algorithm. This is one of the interesting problems from Java coding interviews and you can use this program to weed out Java programmers who cannot write code.

How to generate Prime numbers in Java? Sieve of Eratosthenes Algorithm Example

Hello guys, I have said many times that a good knowledge of Data Structure and Algorithms is the first step towards becoming a better programmer and that's why I share a lot of Data structure and Algorithm stuff in this blog. To continue the tradition, I am going to share an interesting algorithm today, The Sieve of Eratosthenes algorithm, which can be used to generate prime numbers up to a given number. There are many occasions when you need to generate all prime numbers up to a specified integer and one algorithm which is most often used to generate prime numbers is the Sieve of Eratosthenes Algorithm. Surprisingly, not many developers know about this algorithm, particularly Java programmers, which is mainly because of not doing enough competitive programming.

Fibonacci Series in Java using Recursion and Iteration - Example Tutorial

Printing Fibonacci Series In Java or writing a program to generate Fibonacci number is one of the interesting coding problems, used to teach college kids recursion, an important concept where function calls itself. It is also used a lot as coding problems while interviewing graduate programmers, as it presents lots of interesting follow-up questions as well. In the Fibonacci series, the next number is equal to the sum of the previous two numbers. First two numbers of series are always 1 and 1, third number becomes 1 + 1 = 2, subsequently fourth number becomes 2 + 1 = 3. So a Fibonacci series looks like 1, 1, 2, 3, 5, 8, 11, 19, and so on, as shown in the image as well.

Quicksort Sorting Algorithm in Java - In Place Example and Explanation

Quicksort algorithm is one of the most used sorting algorithms, especially to sort the large lists, and most of the programming languages, libraries have implemented it in one or another way. In Java, Arrays.sort() method sorts primitive data types using a double-pivot Quicksort algorithm, authored by Joshua Bloch and others. This implementation provides better performance for a lot of data sets, where traditional quicksort algorithms reduced into quadratic performance. This method also uses MergeSort, another good sorting algorithm, to sort objects. Quicksort implementations are also available in the C++ STL library.

How to Find Multiple Missing Integers in Given Array of Numbers with Duplicates in Java?

Hello guys, It's been a long time since I have discussed any coding or algorithm interview questions, so I thought to revisit one of the most popular array-based coding problems of finding missing numbers in a given array of integers. You might have heard or seen this problem before on your programming job interviews and you might already know how to solve this problem. But, there are a lot of different versions of this problem with increasing difficulty levels which interviewers normally use to confuse candidates and further test their ability to adapt to frequent changes, which is key to surviving in the ever-changing software development world.

Top 30 Linked List Algorithm Questions from Programming/Coding Interviews

The linked list is one of the most common and essential data structure and that's why you would frequently find linked list based coding questions on interviews. The range of questions can be from simple questions like finding the length of a linked list to very difficult like merging two sorted linked lists. Nevertheless, the point is that you should be familiar with linked list data structure and must know how to perform basics task in the linked list e.g. adding or removing nodes from a linked list, traversing order linked list and implementing linked list in your choice of programming language like Java, C++, C, or Python.

How to Print Fibonacci Series in Java without Recursion - Coding Problem for Beginners

Fibonacci series is a great example of Dynamic Programming, Recursion, and how the use of Recursion can result in a clear and concise solution. That's why whenever asked about writing a Java program to get Fibonacci numbers or print the Fibonacci series of certain numbers, it's quite natural for programmers to resort to recursion. The interviewer often challenged this practice by asking candidates to implement the Fibonacci series without using recursion. Yes, you read it right, you can't use recursion and this is what you will learn in this article. If you have attended your programming classes regularly then you may know that many recursive algorithms also have their iterative counterpart which uses loops instead of recursion or calling itself. We will take advantage of that concept to devise a solution to this problem.

Sunday, September 24, 2023

3 ways to sort an ArrayList in Java without using sort() method - Example Tutorial

Hello guys, you can sort an ArrayList in Java without using the sort() method from the Collections class or the List interfaces' sort() method by implementing your own sorting algorithm. You can use any sorting algorithm like bubble sort, insertion sort, selection sort, quicksort, or merge sort to sort your ArrayList without using sort() method from Collection API. In the past, I have even showed multiple examples of sorting List in Java in both increasing and decreasing order. We have even seen example of sorting List in custom order using Comparator and in this article I will show you multiple way to sort an ArrayList without using Java Collection API. 

How to fix class file has wrong version 61.0, should be 53.0 error in Spring Boot? [Solved]

Hello guys, The "class file has wrong version" error typically occurs when you're trying to run a Java application compiled with a higher Java version than the one supported by your current Java runtime environment. In this case, the error message suggests that the class file was compiled with Java version 17 (version 61.0) but is being executed on a Java runtime that only supports version 9 (version 53.0). This error commonly asked when you try to use Spring Framework 6 or Spring Boot 3 in your project which is not running on Java 16 or Java 17.  The error also manifest in different messages like "“Java class file has wrong version 61.0” or "“Java class file has wrong version 62.0”. 

2 Ways to check If String is Palindrome in Java? Recursion and Loop Example Tutorial

A String is said to be Palindrome if it is equal to itself in reverse order. You can use this logic to check if String is Palindrome or not. There are two common ways to find if a given String is Palindrome or not in Java, first by using for loop, also known as an iterative algorithm, and second by using recursion, also known as a recursive algorithm. The crux of this problem lies in how do you reverse String in Java? because once you have the String in reverse order, the problem is reduced to just comparing itself with the reversed String. If both are equal then the given String is Palindrome otherwise it's not. Also whether your solution is iterative or recursive will also determine by implementing this logic.

How to Convert Fahrenheit to Celsius in Java with Example

In this Java tutorial, you will learn how to write a program to convert Fahrenheit to Celsius in Java. Fahrenheit is a thermodynamic temperature scale, where the freezing point of water is 32 degrees Fahrenheit (°F) and the boiling point of water is 212°F (at standard atmospheric pressure). This puts the boiling and freezing points of water exactly 180 degrees apart. Therefore, a degree on the Fahrenheit scale is 1/180 of the interval between the freezing point and the boiling point of water. Absolute zero is defined as -459.67°F. If you know, in the Celsius scale, the freezing point of water is at 0ºC and the boiling point of water is at 100ºC. By using these facts, you can easily deduce a formula to convert Fahrenheit temperature into Celsius.

How to print 1 to 100 without using loop in Java? Example Solution

This is one of the interesting problems  I have seen in coding interviews for beginners. The program has a surprise element by saying that you need to print 1 to 100 without using a loop e.g. for, forEach, or enhanced for loop. This brings out some innovative solutions from candidates which tell a lot about their approach, knowledge, and attitude. I remember, asking this question during campus recruitment to at least 5 candidates. The first one took 5 minutes to think and then come up with the brute force way where he just copies pasted 100 System.out.println() and printed numbers 1 to 100 but when we asked to improve that, he couldn't do that. Unfortunately, he didn't think that recursion can replace an iterative algorithm without using a loop.

How to Convert Binary Number to Decimal in Java - Algorithm Example Tutorial

Problem: Write a Java program to convert a binary number into the decimal format, without using any library method which can directly solve the problem. You are free to use basic Java functions through e.g. those defined in java.lang and all kinds of Java operators e.g. arithmetic and logical operator, bitwise and bitshift operator, and relational operators.

Solution: Let's first revise some theory of the number system, which is required to convert a number from binary to decimal format. There are four kinds of number systems binary, octal, decimal, and hexadecimal. Binary is base 2 and that's why any number is represented using only two-digit, 0, and 1 also known as bits.

Double Checked Locking on Singleton Class in Java - Example

Singleton class is quite common among Java developers, but it poses many challenges to junior developers. One of the key challenges they face is how to keep Singleton class as Singleton? i.e. how to prevent multiple instances of a Singleton due to whatever reasons. Double-checked locking of Singleton is a way to ensure only one instance of Singleton class is created through an application life cycle. As the name suggests, in double-checked locking, code checks for an existing instance of Singleton class twice with and without locking to double ensure that no more than one instance of singleton gets created.

How to check if a number is a palindrome or not in Java - Example

How to check if a number is a palindrome or not is a variant of popular String interview question how to check if a String is a palindrome or not. A number is said to be a palindrome if the number itself is equal to the reverse of number e.g. 313 is a palindrome because the reverse of this number is also 313. On the other hand, 123 is not a palindrome because the reverse of 123 is 321 which is not equal to 123, i.e. original number. In order to check if a number is a palindrome or not we can reuse the logic of How to reverse a number in Java.

How to Count Occurrences of a Character in String - Java Programming Example

Write a program to count the number of occurrences of a character in String is one of the common programming interview questions not just in Java but also in other programming languages like C or C++.  As String is a very popular topic in programming interviews and there are a lot of good programming exercises on String like "count number of vowels or consonants in String", "count number of characters in String", How to reverse String in Java using recursion or without using StringBuffer, etc, it becomes extremely important to have a solid knowledge of String in Java or any other programming language. Though, this question is mostly used to test the candidate's coding ability i.e. whether he can convert logic to code or not.