Solutions of Core Java Interview Questions
Long back I posted few core java interview questions. But for one or the other reason, I always got a bit preoccupied and never managed to post the answers for those questions. So here I am today, with my view points on those questions. However, my explanations would be very brief and I would still recommend you to search and read as much as you can about these topics.
Q. Why do you think, Java is such a popular programming language? Or it may be reiterated like,“What makes Java different from C, C++?”
A. In my viewpoint Portability and Automatic Memory management are the two properties that made Java such a popular language. It is important that you understand how java is made portable and how automatic memory management is done by JVM.
Q. What exactly is “Code once and run anywhere” property of Java? How does Java achieve this behavior? Or it may be reiterated like, “What makes java a platform independent language?”
A. There you go, the interviewer wants to know the life cycle of a java program and what role the JVM plays in that. So you should remember, that Java Code is first compiled by the java compiler into class files and it is these class files which are portable and can be executed on any JVM platform. The core java concept implied here is that, it is the JVM that adds portability to Java Code.
Q. Can you explain how garbage collection happens in java? Or it may be reiterated like what is so special about Garbage collection in Java?
A. Garbage Collection is automatic in Java. While writing your code, you never have to worry about memory management. The JVM has a garbage collector thread which automatically takes care of Garbage collection. However still, there are certain good programming practices which as Java programmer is expected from you and those programming practices will make your code perform better.
Q. What will happen if I call ‘System.gc()’ from my code?
A. Many people reply to this interview question, stating that the garbage collector thread would start running. However that is not correct. Calling System.gc() is like making a request to the VM to perform garbage collection, it does not mean that the VM would start Garbage collection immediately after the call. However when you call System.gc(), the next time the garbage collector thread is run, it will perform a full garbage collection, which means, all the new and old generations would be collected. Although this means longer time and more CPU cycles. So calling System.gc() makes sense only when you know your application is sitting idle.
Q. Can you explain some algorithms that are used by JVM for garbage collection?
A. The garbage collection algorithm has evolved over the period and precisely there is no single algorithm that is followed by all the JVM’s. Since you can write your own JVM’s you can also implement garbage collection the way you like it. However all the algorithms follow a basic principle, which you can say as the core java concept of Garbage collection. The JVM essentially tracks every piece of heap memory. Periodically it runs a check and scans all the objects and variables part of the program. It tries to determine if it could reach the memory for the allocated object. Any memory that cannot be reached is reclaimed and freed. This is what is called as Garbage Collection and this how essentially it works in Java.
I hope the solutions for these few Core Java Interview Questions would give you a head start in preparing for your Java Interviews. However, I will also try to frequently update this website with more Java Interview Questions and their solutions. Till then keep posting your comments and reviews.
http://javaconcepts.in/java/solutions-of-core-java-interview-questions/
相关推荐
Java Software Solutions Foundations of Program Design,第8版,英文文字版 Java程序设计教程 第八版 作者:John Lewis, William Loftus 经典畅销教材 Java 程序设计教材 高校必备
This is a Questions & Answers book with 250+ questions and answers relating to core Java with lots of code snippets (100+), examples, and diagrams. Most Java interviews and technical challenges you ...
反问题中经典的书箱,由Tikhonov编写
《The Exact Feasibility of Randomized Solutions of Uncertain Convex Programs》这篇论文由M. C. Campi和S. Garatti共同撰写,发表在2008年的SIAM Journal on Optimization上,其主要探讨了在不确定环境下处理凸...
Modern Java Recipes Simple Solutions to Difficult Problems in Java 8 and 9 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
For the widest degree of readability, the solutions are almost entirely written with Java (with the exception of C / C++ questions). A link is provided with the book so that you can download, compile,...
Core Java Volume I–Fundamentals, 1 (11th Edition) By 作者: Cay S. Horstmann ISBN-10 书号: 0135166306 ISBN-13 书号: 9780135166307 Edition 版本: 11 出版日期: 2018-09-06 pages 页数: 928 The #1 Java ...
《Java Software Solutions 4th》是一本专注于Java软件开发的教材,主要针对快速掌握Java编程技术的读者。这本书第四版的出现,意味着它在不断更新和优化中,以适应不断发展的Java技术和教育需求。该书深入浅出地...
For the widest degree of readability, the solutions are almost entirely written with Java (with the exception of C / C++ questions). A link is provided with the book so that you can download, compile,...
Solutions include code snippets which are primarily in C++. Programs concerned with concurrency are in Java. Complete programs are available at epibook.github.io. Java versions of the C++ programs in ...
Java是一种广泛使用的高级编程语言,它具有面向对象、跨平台和多线程等特性。Java软件解决方案的第七版,提供了深入探讨Java编程语言及其应用的方法。该书籍覆盖了从基础概念到复杂主题的各个方面,包括IDE选择、...
150 programming interview questions and solutions Plus: Five proven approaches to solving tough algorithm questions Ten mistakes candidates make -- and how to avoid them Steps to prepare for ...
Fully updated to reflect Java SE 7 language changes, Core Java®, Volume II—Advanced Features, Ninth Edition, is the definitive guide to Java’s most powerful features for enterprise and desktop ...