Dalvir Singh Bains

Ranch Foreman
+ Follow
since Aug 10, 2022
Merit badge: grant badges
Biography
Learner
For More
Surrey, Canada
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Dalvir Singh Bains

Hi Everyone

I'm sharing with all of you that I passed both OCP8 and OCP17 exams. I passed OCP8 on November 14, 2024 and passed OCP17 exam on November19,2024.

I'll honestly share my experience regarding preparation and exam in this post. I'll try my best to keep it to the point and as relevant as possible
for the users of this forum. It can be a bit lengthy post but trust me new test takers will find some relevant info.

My Background: I've a computer science background but due to my negligent career related decisions, I didn't look up for jobs in IT field.
I didn't take career related decisions with consciousness and planning. So, as a result I ended up working in unrelated field to my education (as a pharmacy technician).

I had java OCA certification in 2019 and after that I sidelined my technical studies and job search efforts in IT industry. So, I had been working in pharmacy since mid of 2019.

Some personal life events happened in December 2023 last year and I made up my mind and took a conscious decision to look for an employment in my field of study and clear the long pending OCP8 certification alongside.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
A lot of time had been passed since 2019 and java had evolved a lot since I left the books. I initially studied half-mindedly for around 2 months along with full time job and aiming for OCP8 in February 2024 but failed that exam.

Reasons of my first OCP8 exam failure:
  • Inadequate/shallow level preparation for OCP8 objectives
  • Rookie level test taking skills
  • Unable to manage test anxiety and lost track of time

  • So, in March 2024, I decided to give all in to java learning and exam preparation. I made it my utmost important goal and started preparing towards it. I prepared with job till July 2024 but left pharmacy job in July 2024 and committed fully towrards job searching in IT and learning java.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Initial challenges I faced in language learning:

  • I had lots and lots of questions in my head about why something works/behave in a particular way or you can say how language concepts work internally?


  • Since, I was dedicately learning a coding language for the first time, everything felt daunting and overwhelming initially. I was even struggling with very basic concepts of java like type casting in interfaces, basic OOPS concepts etc. Collectors API was a whole different universe. Nested and local types felt intimidating


  • So, there're two paths now-either fight or flight. I had already taken second option as I explained above while choosing career field. I persisted this time and consistently studied daily without a day off. My goal was to thoroughly understand the language concepts to build a considerable foundation for coding and development skills and improve it incrementally.

  • --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Topics that took my most effort and time:

  • Generics in java: This topic gave me the hardest time. It had a steep learning curve especially when one is weak in language basics. From being near zero in this topic , I reached to a point to comfortably code and read java API and Stackoverflow posts involving nested generic code. I read online articles about generics, bounded types and after spending some frustrated hours over months things finally started making sense to me in generics. Point is - keep trying , never quit, try alternative resources, take notes, revise , repeat.  

  • https://angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html
    ( very good resource to understand overriding/overloading related concepts in java generics)

  • Understanding method references (both bounded and unbounded): Took me some effort to get my head around it. I wasn't able to understand how method argument and target type is being passed behind the scenes. Read a lot of Stackoverflow posts and online articles about it ,but when we learn the concept and hit that Eureka moment we can apply it confidently in coding.


  • Modules/ Modular JDK concepts: They were intimidating in the beginning but then I loved them. Services, modular jars, ServiceLoader API. I wrote and read code examples to try various services related modular concepts.

  • https://www.oracle.com/corporate/features/understanding-java-9-modules.html
    (very good resource for understanding module concepts with web links to all the JEPs)
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    My exam preparation strategy:
    First OCP8 failure taught me 2 important things which I'll follow for any time based technical exam in my life:
  • I need to do justice with all questions in terms of time
  • Second, I need to develop coding MCQ solving skills with accuracy for that I need to work on java basics
  • Knowing how to program in java is one thing and performing under pressure with blazing speed code reading is another skill


  • So, I started working on it by solving java MCQs daily. I used to put up a timer and start solving MCQs daily.
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Resources I followed:
  • I relied more on internet resources like JLS, javadoc, JEPs, online coding forums reason- I had lots of questions and my basics were weak in language. So, following any standard exam preparation book like most users on this forum didn't help me much.


  • I had lack of industrial coding experience but put many hours day and night to up my level in java with determination. I believed I may not have the "natural" learning instincts towards coding but I had the will and determination to improve my situation. That determination motivated me daily to overcome all the challenges in learning java. I believe with self-discipline and determination we can learn any skill in this world if we put in enough efforts and hours towards it. Human mind is very powerful and has lots of untapped potential.


  • Below is the list that I followed, it's neither absolute nor exhaustive. Everyone can add/remove based upon their preferences. All a person needs to start learning java is a good working PC/laptop, any one good reference book and a focussed and determined mind.That's it.

  • OCP book by Jeanne Boyarsky and Scott Selikoff  (I followed for File I/O, NIO and modules chapters, I liked the casual teaching style of authors)


  • OCP 17/21 book by Hanumant Deshmukh ( This book is jam packed with basic concepts of java; very useful for beginners; must read)


  • Enthuware OCP8 and OCP17 mock exams ( Do they need intro best and to the point)


  • OCP 17 Mock exams by Udayan Khattry on Udemy (Java Certification (1Z0-829) Topic-wise Tests Part-1 and Part-2) ( Quality content and questions for preparation)


  • I solved any possible java MCQ I can find/download from internet in test/timed environment to train myself in performing under time pressure


  • coderanch.com ( The site admins are super friendly to java beginners in terms of responding to queries. I posted some queries and everyone helped me graciously. I'll give back to coderanch community by contributing whatever I've learned so far. I really appreciate your help )


  • JavaDoc and JLS ( This is the holy book, best friend, soulmate, buddy for a java coder/learner)


  • I want to specifically give a shout out to this youtube channel:
    my name is GYAN (Youtube handle:@mynameisGYAN). It has awesome java content for beginner to intermediate learners. Very thorough, teaching the language core concepts and quality content. No timepass, no bluff---just pure knowledge sharing. Especially videos on Generics and Multithreading programming are of very good quality and to the point.


  • OCP17 practice book of 1000 questions by Scott and Jeanne ( some questions are really good and thoughtful but some are unnecessarily tricky)

  • -------------------------------------------------------------
    Mistakes I made/ Things that didn't help me: : You can save time by avoiding some or possibly all of these:
  • Breaking consistency in studies
  • Procrastination in preparation / Putting off important things for future
  • Wishful thinking without a strategy and appropriate plan
  • Not taking notes of my mistakes
  • Not revising my notes
  • Not practicing solving MCQs in time constrained environment
  • Not coding in java right from the beginning of preparation ( merely reading language syntax is counterproductive and defeats the purpose of learning; aim should be to use the language daily in delivering meaningful use cases)

  • ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Things that indirectly helped me:

  • Not sticking to the exam objectives


  • I believe exam objectives are broad; my learning style is to build basic concepts; so it triggered a chain reaction of concept learning for me;  to learn about the "effect" I had to learn the "cause" first and it lead to increase of my preparation time.


  • For example: exam objectives say "Use Generics/ Wildcards": It indirectly requires the understanding of "type erasure in java" which entails " use of bridge methods by compiler" which further entails "Type parameters and their scopes" which further entails " Intersection types"---it's a chain of concepts and everything is interlinked. If any one piece of puzzle is missing then concepts will be shaky and one can't confidently answer the question on method overloading and overriding without knowing type erasure. Without knowing the right tool/language construct for the required job how can one even code a solution?


  • Furthermore, generics are scattered all over in javadoc and I believe without knowing why exactly they're required one can't get full value out of javadoc.


  • Another example, in exam objectives it says "using textblocks" which indirectly entails knowledge of escape sequences, escape characters, character lierals, whitespace characters, difference in line terminator characters in windows and Linux platform. I mean everything is interlinked.


  • Another example, in objective "performing reduction of parallel streams" which entails knowing about spliterators and stream characteristics and how encounter order of different collections affect parallel processing in streams.point is --everything is interlinked.


  • One last example, exam objective of " declaring nested class objects" can go quite heavyweight very quickly due to the addition of Sealed types, Record classes, Local enum classes and flexibilities allowed in Java 16 in terms of declaration of static members in nested types.


  • Furthermore, topic of "nested types" entails knowledge of concepts like Canonical names of types, Fully qualified and simple names of java types, Qualified this and Qualified super concepts. I mean everything is interlinked. For me, personally, like Maths problems, it's like all or none
    approach; either you know the complete concept or you know half-concept (which is a recipe of hidden bug and failure at some time in future)
    Nested types and method overloading is embedded all over in javadoc.


  • Things that helped me in building java basics and clearing OCP exams: Everyone has their individual learning styles. Please introspect and assess accordingly.
  • Writing numerous coding examples/use cases by myself to understand the API and language behavior
  • Reading JEPs on Modules, Modular architecture, instanceof pattern matching, sealed types, Record classes
  • Reading JLS sections selectively for language syntax and rules
  • Reading/understanding java code in problem context/meaningful use-case context on online forums (Stackoverflow/coderanch/Reddit)
  • Taking coding notes and revising them regularly to familiarize with language
  • Coding daily in java (This is absolutely must to build muscle memory in language syntax and API usage)
  • Reading countless javadoc pages and method API descriptions


  • My strategy in exam preparation and during attempting exam questions: I'm sharing these tips as a java beginner not as a professional java developer, since this exam has variety of test takers of all sort of professional backgrounds.

  • If you've coded enough java examples while preparing, read java code on Stackoverflow posts and solved enough MCQs in a timed environment; you develop a skill to quickly read java code in exam.


  • If you've thoroughly understood java core concepts like type casting, Generics, OOPS concepts, runtime method dispatching, compiler's algorithm to select appropriate methods AKA static bindng,JVM runtime class and insatance initialization mechanism---then you will easily smell wrong java syntax by merely seeing it in exam options and thus eliminating wrong answers.


  • Don't trust the mind. Test the mind. Give it code to solve, MCQs to figure out and see its response under time constraint. Benchmark the score and see where the trajectory of preparation is leading. Consistent good scores in random tests on random days say themselves a lot about one's preparation. Numbers never lie.


  • When I solved MCQs during preparation, I divided 90 minutes to 3 chunks of 30 minutes each. I had set a mental goal of solving
    at least 19-20 questions in first 30 minutes with as much accuracy as possible. It used to help me in getting a head start and slow down gradually in next remaining 1 hour so that I still have 8-9 minutes in the end to review questions I marked. It helped me keep track of time. There will always be an inherent tendency to answer a question incorrectly  in exam despite knowing the concept due to exam stress, time , inability to recall API at right moment, but that's OK. That's why mock exams are for -to minimize that tendency but it will always be there. Exams are exams. We adapt, we train accordingly.


  • ***Both OCP8 and OCP17 are code heavy. Code is jam packed in snippets especially in OCP17. There were long coding snippets at the start of my OCP17 exam. One need to be fast and accurate at the same time. Quick API recall and mental code execution is a skill that comes with practice. So, especially for beginners like me ,read and write enough java code at home to train your eyes not to get bogged down when clock is ticking on your head unless you're a professional software developer with some experience.***


  • Practice writing code a lot. It has no match. Literally, no match. I initially used notepad and cmd to code and understand modules. I wanted to train my brain to learn command line switches related to modules, JDEPS, JLink and jar files. It was fun. I also learned about jar creation, jar decompression and jar manifest files indirectly while learning modular jars. Gradually, I shifted to IntelliJ reason- it was more efficient and provided option to hover and read javadoc right way thus saving time.  One hour of mindful coding with focus is better than reading online articles on java or watching youtube videos (without quality content) on java.


  • I believe reading java certification prepartion books and knowing java syntax/rules is necessary but not sufficient to clear the exam and build the concepts. Only when we start typing code, we come to realize our false positives in learning. It's important to test ourselves frequently to know what we think we know but actually we either don't know or half-know. Only when weird Runtime exceptions and compiler
    errors are slapped on our face; we tend to know the gaps in our knowledge and do efforts look for missing pieces of puzzle/answers online. It helps in solidifying learning and retaining concepts longer.


  • Then there comes a point in learning when that blinking little cursor on Intellij console, every whitespace character, comma, dot, semi-colon start to talk to you (kidding but you got the feeling) you feel like crossing that threshold point or plateau in learning, after which things/concepts tend to become very very niche/specific, you feel like  having some control and command over the language use and you've enough test data from mock exams to backup your thought ( atleast 80-85% score in mock exams). Now you're ready to put your hard earned money and book the official exam.


  • Be honest to oneself, we know honestly where we need to work upon whether in studies or in life in general. I tried to fix one thing a day or atleast one can take an honest small little step towards fixing something. then inch by inch , day by day things start to fall into their place. Persist, resist and never give up. Scores may be bad in one mock exam on any random day. But ultimately we learned something out of it. Things change, stick to the path of honesty and truth. Only truth prevails. Enjoy learning while preparing. Not everyone gets a chance to learn
    and study on mother earth. Happy learning and coding
  • Thanks @Carey and @Jhonson for your inputs. I appreciate.

    and to @Mike thanks for pointing out what I believe completes this answer.
    2 months ago

    Hi everyone

    As far as I've understood class initialization process during class loading phase, at runtime as per JLS "Initialization of a class consists of executing its static initializers and the initializers for static fields (class variables) declared in the class."

    As per JLS section  12.4.1. When Initialization Occurs
    A class or interface T will be initialized immediately before the first occurrence of any one of the following:

    T is a class and an instance of T is created.

    A static method declared by T is invoked.

    A static field declared by T is assigned.

    A static field declared by T is used and the field is not a constant variable



    My question is regarding the last point mentioned above and Enums in java.

    Suppose I've the following code:





    I believe for compiler above enum definition is like below representing each enum constant as public static final field referring to a singleton object



    since all the enum values internally are public , static and final constants, so as per the fourth point mentioned above  using the enum field NOKIA for the first time shouldn't trigger the execution of static block in enum Phone during the class loading of Demo2 by JVM.

    In other words, I'm not able to understand why explicitily declared static block is being exceuted here?
    Are enum classes treated special by classloaders as compared to "regular" java classes in this aspect ?
    Is fourth point of JLS section  12.4.1 of class initialization isn't applicable to enum classes?

    I believe it would've made sense in the following case:





    Please provide your guidance on this and where I'm having a gap in the understanding of enum concepts.

    Thanks
    2 months ago
    Thanks @Carey and @Mike for your insights on this. I really appreciate.

    @Mike I agree with your points.

    The only similar guarantee in the API is that if the elements were equal (meaning, if the compare() method returned 0) then the elements would not be reordered.



    For your above remark, I tried to play with the Comparator further and changed it as below:


    The output was as per specification as you pointed out and order of elements was unchanged. Moreover,signum(compare(x, y)) == -signum(compare(y, x)) condition also holds for Comparator<String> cmp = (j,k)-> 0;
    since compare(x, y) and compare(y, x) are both 0 in this case. Hence, 0 == - 0  evaluates to true in java as per specification. We can say that Comparator<String> cmp = (j,k)-> 0; is a valid comparator giving consistent results.

    Mike,I appreciate your detailed explanation.
    4 months ago
    Hi everyone

    I understand that the comparators returning just plain int values without any meaningful sorting criteria aren't very practical in industrial scenarios, but just consider this simple usecase I encountered today while studying for OCP exam.


    As per javadoc that sort method sorts the specified list according to the order induced by the specified comparator.

    In above example what can be the order induced by comparator returning just int value of 1? I believe it should be reverse alphabetical order since ideally this custom comparator returning just 1 should induce the order as per below


    I don't understand why the output is still showing the alphabetical order but not the reverse one.

    If I modify the comparator as below:



    Now, in this case the order should have stayed the same as insertion order since -1 means first argument must come before second as specified by int compare(T o1,T o2)  

    Please provide your guidance on above interpretations.

    Thanks
    4 months ago
    Thanks @Piet for the solution. It's very interesting. It helped me revise the Collectors API related concepts.
    4 months ago
    Thanks @Campbell and @Piet for your feedback on my post. I earned some more cows yayyyyyyyyy!!!

    @Piet as per your following remark:

    As an extra exercise: from the frequencyMap, can you create a datastructure that gives, when printed,

    {3=[apple], 2=[pear], 1=[papaya, orange, banana]}



    I've tried to come up with the following solution. I know you intend to solve this exercise only using Collectors API. The following example is giving the desired result but it's using another map to sort the map in reverse order of keys at line 12. I'm thinking of some way to do it using Collectors itself without using another map. For now, I've this code as solution:



    Please review and provide your feedback.

    Thanks


    4 months ago
    I've understood this concept. Thanks @Carey and @Campbell.

    Today I feel like sharing my heart with you all while prepairing for the OCP.

    So, far in order to understand the working of API I write code examples and try my best to cover edge cases. This is so far my approach towards learning the java API. I know over time using API at job or in projects help to recall API faster and it kinda builds muscle memory.But I've to reach that stage yet. I also try to go over the problems posted by other users on this forum and on SO to build my code comprehension skills. Examples on Coderanch and SO helps me to see code in problem context and its possible solutions(submitted my first edit on SO recently and it got accepted-felt good . I strongly believe in quality over quantity in life in general; this belief I try my best to use in learning java.

    I try to understand the concept concretely to the best of my abilities. Whatever I don't understand or when in doubt I try to read javadoc, see code examples, ask on coderanch and practice writing by myself. Taking analogy of swimming, like it can only be learned by jumping in the pool. Coding can be learned by coding...self-introspecting---coding....repeat, measuring and benchmarking the learning alongwith adjusting the learning path. I feel kinda low today so just feel like sharing with you all this. I respect you all as my seniors in this field. I know I've to put in more hours and it's just the beginning but I'll persist and persevere.

    This is so far my method to understand java API. As you are seniors to me in this industry, I would appreciate your valuable feedback on my learning style and suggestions in areas of improvement.

    I'm trying to give hands on practice to java dedicately first time in life.

    Thanks
    4 months ago
    I'l try to summarize our discussion and concepts that are validated:

    1. Maps generated from streams in general have unspecified iteration order unless a specific sorted map implementation is requested ( Obviously every sorted collection is ordered ). Javadoc validates this as well about unspecified order of map entries.

    2. Due to unspecified iteration order, map generated at line 4 in my refactored example has unspecified order. It just happens to be in a consistent order after multiple runs in this example( by chance) at line 5 but that is just co-incidence. Nothing can be said definitely. As it's behavior may change when generated using a large data set. Here, initial data set of 7 items is not enough to deduce anything conclusively.

    3. In this specific coding example, In order to make sure that orange is ordered before papaya, we have some of possible solutions like the ones mentioned on that SO link or using a chaining comparator.

    and @Campbell by "value" in your following remark:

    The concept problem I saw earlier is that a linked map is intended to give iteration order the same as insertion order, but a tree map gives iteration order according to a value (as specified by the Comparator used to populate it)



    do you mean to say the numerical int "value" which is the result of method: int compare( Object, Object) of Comparator interface i.e {-1,0,1} for custom sorting of TreeMap? It's not the Map's "Value" from key-value pair because TreeMaps decide sorting criteria based on Map keys not values.

    Thanks for your insights on this post @Campbell.

    4 months ago
    Thanks Piet and Campbell for your replies.

    @Piet :following on the improvised example you've posted, I've refactored my orginal post as below:



    @Campbell and @Piet: I understand the alternate ways to get the entries order as metioned in that SO post as well as using chaining comparators (thenComparing) but it wasn't I intended to ask originally. I was not very clear in explaining earlier.

    I believe after refactoring the original post, I can myself understand it better and try to explain again what I intended to mean actually originally.

    I think it all boils down to line 4 of this coding example. Maps generated from streams don't maintain any order unless a specific map implementation is requested( TreeMap, LinkedHashMap etc.).

    So, considering this point the output map entries at line 5 of this code, should be in random order. but somehow due to an internal map (possibly HashMap implementation chosen by groupingBy collector here, order is always consistent resulting in a order dependecy on map variable by result variable.

    At 19:00 minute of this youtube(https://www.youtube.com/watch?v=lwp2RZ__0ko) video, @Stuart Marks explains about iteration order of Map data structures. As per this video, new unmodifiable collections of Collections API do have randomized iteration order but older Maps like HashMap despite having unspecified iteration order still  give consistent iteration order sometimes due to behavior of hashing algos.

    I believe this is happening here , map generated at line 5 is always consistent in terms of order of its entries i.e.( papaya always showing before orange even after multiple runs of code).

    Due to this consistency in the  order of map entries at line 5, even after sorting is done at line 9 and sorted stream of map entries is generated, the order of enteries for papaya and orange is preserved despite both mapping to same value 1 ( as it was in the entryset).

    Please provide your guidance on it.

    Thanks
    4 months ago
    Hi

    First of all, Thank you all for your valuable guidance and support so far. I appreciate.

    I was coding some examples for the Collectors API and came across the following example on Stackoverflow  [ https://stackoverflow.com/questions/47019946/java-8-group-by-a-list-sort-and-display-the-total-count-of-it ]

    My question is regarding the Comparator used by the Map.Entry here.

    I understand how this example works. My only question is the order of printing of map entries.

    I mean when I run this example the output is always {apple=3, banana=2, papaya=1, orange=1} even after multiple executions of code.

    I want to understand how comparingByValue works internally when it decides the tie case in sorting; I mean the case when both map values  are equal?(value is the sorting criteria in this example in reversed order)

    Like in this case,  I understand that entries of this map are sorted based on the reverse natural order of values (3,2,1....) but value 1 corresponds to 2 keys papaya and orange.

    Why is it always papaya entry before orange entry despite the fact that value corresponding to both keys is 1 ?

    I mean why the output can't be {apple=3, banana=2, orange=1, papaya=1} in this case ?



    My logic:
    As per javadoc, there is no guarantee of a specific Map implementation type used by the groupingBy collector. Hence, it can be unordered. Further , on calling entryset method on it will give a set which is distinct at the most ( no ordering guarantee by set as well here ). Hence, encounter order of stream generated by entryset.stream() should be random.

    Somehow, strangely,the intermediate sorted stream is always {apple=3, banana=2, papaya=1, orange=1} by always sorting papaya before orange. this is the point where I,m not understanding it properly.

    But since the stream is sorted by comparingByValue and there is a constraint on forEachOrdered to adhere to encounter order. Somehow, forEachOrdered is adding values into the LinkedHashMap in the same insertion order in my code executions.I mean for value 1 since there are 2 keys; so there should be some chance that finalmap can contain orange before papaya.

    Please provide your guidance on it.

    Thanks



    4 months ago