Such is every other job in the world... Even doctors have to constantly learn about new things and advancements in medical science to keep up with their craft.Guy who works in IT company here and completely agree to this. Read all the news about massive layoffs happening in IT companies. A bulk of those being let go are in middle management which is your typical 40 ish people. The issue with IT is that after a certain point there is nothing you can acquire in terms of knowledge because IT as such grows at the bottom (new technologies, extensions and parameters) and not from the top like medicine or law (which build on on existing knowledge).
For example after working 20 years in Java you are demanded to learn Python. Suddenly all the knowledge you have acquired over the past 20 years is useless. In addition to that, most of what you did has been automated and now you are a liability to the company who can get a 5 years experienced guy to do the same thing you did at a fraction of the cost. This is why unless you invest what you earn while you are young it is difficult to achieve FIRE from IT. On the other hand, the knowledge a surgeon acquired from doing 20 years of surgeries becomes invaluable as time goes on. It is almost guaranteed that your income will continue growing if you keep building on your existing skills. In IT on the other hand you need to keep starting from scratch.
What people forget about IT is that fundamentally it exists to automate things. Including itself. So everything in IT has an expiration date.
And no job is safe, even whole government jobs... Example, the US Government shutdown.
The Java example you took, while yes I agree the trends are shifting, there are also massive companies who have build Legacy systems and constantly require people who have those skills and experiences. So, it is upto oneself to either upskill or find a job in a particular niche... Software Development, isn't just about Programming languages, it's also about the concepts because after a certain point in your career, you are not just writing code, you are managing infrastructure, you are doing system design, a lot more things than what you used to do...
Also, I am an educator in this field and I teach working professionals as my passion, the jobs are there, my perspective on this is that the IT job market is more of an issue of unemployability rather than unemployment. The skill gap between job demand and what people have is the reason why everyone thinks of IT in bad light.