Tuesday, August 31, 2021
Java 8 Stream filter() + findFirst Example Tutorial
How to add and remove Elements from an Dynamic Array in Java? Example Tutorial
Saturday, August 28, 2021
Top 20 Java EE Web Developer Interview Questions
Ever since J2EE become obsolete the enterprise Java has got confusing names e..g JEE or Java EE. I am still not sure what is called officially and popularly so I have included all of them i.e. J2EE, Java EE and JEE. In this article you will find questions about Java EE platform, architecture and technolgoies e.g. JSP, Servlet, EJB, JMS, JSF, JMX, JNDI and JDBC. It will also include questions from application servers like GlassFish, WebLogic and WebSphere and messaging technologies like MQ Series, TIBCO and others.
Difference between Servlet and JSP?
Difference between Web and application Server?
What is EJB?
Difference between EJB 2.0 and EJB 3.0?
What is JMS?
What is difference between JMS and WebSphere MQ Series?
Some basic platform stuff:
List three Collections interfaces and the basic contract of each. List concrete implementations of each, how they differ, and performance characteristics in space and time.
Describe the contract of equals and hashCode. Why is it important that if you implement one, that you implement both?
What are generics? What is type erasure and what are the consequences? What are variance, covariance and contravariance? If blank stare: why can't you assign a collection with a generic type binding of a sub type to a reference to the same collection type binding of the super type? How do you specify the type binding of the super type to allow this? How do you specify the type binding to allow type-safe insertion?
Concurrency
Explain how notify and notifyAll work, and the difference between the two. Why prefer notifyAll to notify?
What is a deadlock and how do you avoid it?
What is a race condition and how do you avoid it?
What are some of the high-level concurrency classes provided by java.util.concurrent and how do they work?
Database
What are the different statement types and why would you use each?
How do you prevent SQL injection attacks?
What are transactions? What is ACID?
Hibernate
Give an overview of Hibernate and ORM. How do you load objects into the session? What does the session do with the objects while in the session? What is the difference between getting a persistent object from the session and querying for persistent objects?
When is it better to use plain SQL instead of ORM?
Java EE
How do you configure a DataSource in Weblogic to make it available using JNDI?
What are some ways for the client to obtain a reference to the DataSource from the app server? (Spring is not the answer I am looking for)
Spring
Give an overview of how Spring Dependency Injection container works. What is the purpose of DI? How to specify bean definitions? What are the different scopes? When do beans of each scope type get instantiated?
Web Services
What is the difference between SOAP-based web services and REST-based web services?
Describe SOAP and WSDL.
What exactly is REST? What is HATEOAS? What is the purpose of each of the HTTP verbs? What is idempotence? What is content-negotiation?
OOP
What is decoupling? Why are loose-coupling coupled classes desirable? What are some drawbacks?
What is cohesion? Why are highly cohesive classes desirable? What are some drawbacks?
Describe polymorphism. What is the importance of contracts between interfaces and concrete types? Why is polymorphic code desirable? What are some drawbacks?
REf : https://www.reddit.com/r/java/comments/2lo7it/conducted_an_interview_for_a_senior_java/
Friday, August 27, 2021
How to Remove Objects From ArrayList while Iterating in Java - Example Tutorial
Thursday, August 26, 2021
9 JSP Implicit Objects and When to Use Them
If you are new to JSP then your first question would be what are implicit objects in JSP? Well, implicit objects in JSP are Java object which is created by Servlet containers like the tomcat or Jetty during translation phase of JSP, when JSP is converted to Servlet. These objects are created as local variables inside the service() method generated by the container. The most important thing about the implicit objects is to remember that these objects are available to any JSP developer inside the JSP page and they can do a lot of things with implicit objects and expression language which was only possible with scriptlet earlier. That's why they are known as implicit objects.
How to implement PreOrder traversal of Binary Tree in Java - Example Tutorial
How to Enable GC Logging in Java HotSpot JVM
When we are diagnosing problems in a Java (EE or otherwise) application, is often a good idea to check how garbage collection is performing. One of the basic and most unobtrusive actions is to enable garbage collection logging.
As you may know, if we add the following arguments to the java start command…
-Xloggc:<file_name> –XX:+PrintGCDetails -XX:+PrintGCDateStamps
… the JVM will start writing garbage collection messages to the file we set with the parameter -Xlogcc. The messages should be something like:
2010-04-22T18:12:27.796+0200: 22.317: [GC 59030K->52906K(97244K), 0.0019061 secs]
2010-04-22T18:12:27.828+0200: 22.348: [GC 59114K->52749K(97244K), 0.0021595 secs]
2010-04-22T18:12:27.859+0200: 22.380: [GC 58957K->53335K(97244K), 0.0022615 secs]
2010-04-22T18:12:27.890+0200: 22.409: [GC 59543K->53385K(97244K), 0.0024157 secs]
The bold part is simply the date and time when reported garbage collection event starts.
Unfortunately -XX:+PrintGCDateStamps is available only for Java 6 Update 4 and later JVMs. So, if we are unlucky and our application is running on older JVMs we are forced to use…
-Xloggc:<file> –XX:+PrintGCDetails
… and the messages will be like:
22.317: [GC 59030K->52906K(97244K), 0.0019061 secs]
22.348: [GC 59114K->52749K(97244K), 0.0021595 secs]
22.380: [GC 58957K->53335K(97244K), 0.0022615 secs]
22.409: [GC 59543K->53385K(97244K), 0.0024157 secs]
Now, the bold numbers (also present in previous format) are the seconds elapsed from JVM start time
-XX:+PrintGCDateStamps -verbose:gc -XX:+PrintGCDetails -Xloggc:"<path to log>"
These options make Java to log garbage collector activities into specified file. All records will be prepended with human readable date and time. Meanwhile you should avoid using -XX:+PrintGCTimeStamps as it will prepend record with useless timestamp since Java application start.
Generate log can be later analysed with GCViewer.
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M
GC log files rotation makes analysis of garbage collection problems easier, also it guaranties that disk is protected from space overconsumption
Reference
https://blog.sokolenko.me/2014/11/javavm-options-production.html
https://176.34.122.30/blog/2010/05/26/human-readable-jvm-gc-timestamps/
java gc log file
java gc log format
how to read java gc log
How to reverse a singly linked list in Java without recursion? Iterative Solution Example
Wednesday, August 25, 2021
Some JavaScript Tips
Javascript requires discipline. You can easily create a giant mess. The language allows it. That doesn't mean you should. I've seen and worked on modular, object-oriented driver software written in assembly language. If a clean project and codebase can be done in assembly language, it can be done in javascript.
Use a lint
read other people's code, especially popular things like jquery, node, etc
Follow Crockford's advice about which features to use and which to avoid, e.g. always use === over ==. You almost never want what == does. Just don't use it at all. He has a lot of tips like that.
One good way to learn is to take somewhat complex functions/libraries and write them from scratch, and then compare your source code to the official source code. I did this with jQuery.Deferred, and it was really interesting to see how different my code was from the actual code.
4 Ways to Write String to File in Java
There are many ways to write String to File in Java and we will see four ways in this article. Simplest way to write text data into a File is by using FileWriter, it takes care of character encoding and provides simple methods to write String directly into file. Another way to write String is by using PrintWriter object. It provides convinient and much used to print() and println() method to write String to file in Java. Ofcourse you can alawys use FileOutputStream if you are getting String as bytes but its not as efficent as FileWriter. For those, who hates to deal with Java IO mainly to avoid closing files, stream and freeing up resource can use third party library like Apache Commons IO which provides very convinient methods to write String to file without worring about resource cleanup part.
using FileWriter
using PrintWriter
using FileOutputStream
Apache Commons FileUtils
How to write string to text file in Java using FileOutputStream
how to write string to a file in Java using FileWriter
How to write String to File using PrintWriter in Java
Java 7 one liner to write String to file
Writing text into File using Apache Commons IO
FileUtils class from Apache Commons IO contains some convinient utility methods to write String to text file.
main advantage of using a PrintWriter for writing String to file is that you can use its convinient print() and println() method to write lines. If you use println() then a line fee will always be inserted on contnet, effecitly writing content in new line. Don't forget to close stream, reader or file once you are done writing on it. This is one area where many developers make mistake, also you must know how to close stream in right way to avoid any issue. If you feel this is too much then you better stick with Apache Commons IO FileUtils class which will take care of closign file properly after writing.
How to use Expression language in JSP - Example
In order to use Expression language in JSP you need to include JSTL 1.1 Jar. It was introduced in JSP 2.0 version. Alogn with JSTL and custom tag library, JSP expression langauge are very important to minimize Java codes from JSP pages and by using thsi we can create more maintainable JSP pages. JSP Expression language or EL allows you to access attribute and properties of any object seemlessly without using scriptlet. You can use expression language as ${expr} and its processed at runtime by JSP engine. You can disable use of expression language in any JSP page by using taglib directive.
Syntax of Expression language
Implicit objects for Expressionlangauge
Benefits of using expression language
Expression language example in JSP
That's all about how to use expression language in JSP.
important points about expression langauge (EL)
1) Expression language provides a mechanism for enabling the presentation layer (JSP pages) to communicate with application logic (managed beans) without using Java code or scriptlet.
https://docs.oracle.com/javaee/6/tutorial/doc/bnahu.html
2) EL is used by both Java server pages (JSP) and JavaServer Faces (JSF).
3) EL allows JSP developers or page authors to use simple expressions to dynamically access data from any collection or object. EL greatly improves readability of JSP pages.
4) EL can also be used with Java Enum
jQuery pseudo selector Example
Apart from Class and ID selector, jQuery also provides CSS like pseudo selectors to select elements like first, last, even or odd in list of elements. For example, if you have an unordered list, which contains 5 list items and you want to select the first list item, you can use pseudo selector like $("#course li:first"). Similarly you can also choose the last list item in the unordered list by using $("#course li:last). Ifyou want to select alternate elements, you have options of choosing even or odd elements by using $("course li:odd) and $("#course li:even"). Odd selector will select all elements whose index is odd number, remember indes starts at 0. So odd selector will choose 2st and 4rd element and even selector will choose first, 3rd and 5th element.
here is an example :
jQuery DOM Traversal example
Apart from using descendant, child and pseudo selector to select descendant, childrens, first, and last elements, you can also use DOM traversing to find elements in jQuery. DOM traversing is a powerful technique which you can use in place of selector and it give better performance. jQuery provides methods to go up and down in DOM tree and also to select first, last, next, prev, parent and child like methods to move around efficiently. Here are examples of using different DOM traversal method in jQuery :
1) first
2) last
3) next
4) previous
5) parent
6) children
How to select and change multiple lines in SSMS (SQL Server Management Studio Tips)
Many times we copy Id, names and other attributes form Excle file, email or from other query result which doesn't have single quotes on it. In order ot add single quotes to make it Sring in SQL Server mangaement studio, you are left with no opiton but to manually add single quotes before and after stirng and comma between two values. This is ok if you have just couple of values but if you have 50 or 100 then you are screwed. Today I come to know about an excellent SSMS shortcut, which will let you change multiple lines at once, what this means is that you can add single quotes at front of those 50 values in one keystroke, provided they are in different lines. THis will save a lot of time while working wtih SQL Server,
I used to make a cab in excel, then open in notepad, and copy+paste. This will save so much more time.
here is this tip in action :
https://www.reddit.com/r/SQL/comments/39lfaf/i_just_learned_about_altshift_in_ssms/
I knew about ALT to select a column of text but I didn't know you could snap like that with shift. It also works in Visual Studio and Notepad++
It is indeed real, and other good text editors supports this action as well. I use it everyday in Visual Studio for example.
Neat trick, but it only works if all the items in your list are the same size like the GUIDs in your example, hat's a bummer. At least it'll always work on the left side.
You can also alt-mouse move for box selecttions.
It also works in conjunction with ctrl and the arrow keys and pageup/down and home/end.
Exception in thread thread_name: java.lang.OutOfMemoryError: Requested array size exceeds VM limit
Cause: The detail message "Requested array size exceeds VM limit" indicates that the application (or APIs used by that application) attempted to allocate an array that is larger than the heap size. For example, if an application attempts to allocate an array of 512 MB but the maximum heap size is 256 MB then OutOfMemoryError will be thrown with the reason Requested array size exceeds VM limit.
Action: Usually the problem is either a configuration issue (heap size too small), or a bug that results in an application attempting to create a huge array (for example, when the number of elements in the array is computed using an algorithm that computes an incorrect size).
Tuesday, August 24, 2021
How to use Randam vs ThreadLocalRandom vs SecureRandom in Java? Example Tutorial
How to Convert String to LocalDateTime in Java 8 - Example Tutorial
How to use Stream.filter method in Java 8? Example Tutorial
Monday, August 23, 2021
10 Examples of Stream API in Java 8 - count + filter + map + distinct + collect() Examples
Sunday, August 22, 2021
How to debug Java 8 Stream Pipeline - peek() method Example Tutorial
How to Calculate Next Date and Year in Java? LocalDate and MonthDay Example Tutorial
Saturday, August 21, 2021
How to Reverse an Array in place in Java? Example Solution
3 ways to ignore null fields while converting Java object to JSON using Jackson? Example
Friday, August 20, 2021
5 Differences between an array and linked list in Java
What is difference between final vs finally and finalize in Java?
Thursday, August 19, 2021
How to convert ArrayList to HashMap and LinkedHashMap in Java 8 - Example Tutorial
How to code Binary Search Algorithm using Recursion in Java? Example
Post Order Binary Tree Traversal in Java Without Recursion - Example Tutorial
Wednesday, August 18, 2021
7 Examples to Sort One and Two Dimensional String and Integer Array in Java | Ascending, Descending and Reverse Order
How to prepare Oracle Certified Master Java EE Enterprise Architect (1z0-807, 1Z0-865, 1Z0-866) - OCMJEA6 Exam
Phase 1: Compulsory Course
At this point, the candidate is required to take at least one official Oracle course from Java at any partner company. You can complete this course during certification - before, during, or after.If you already have experience in Java and architecture, leave to take the course at the end. If not, use the classes to gain knowledge for the test by doing them before. There is a complete grid of Java courses for the candidate to acquire the necessary know-how for this certification.