Having covered a lot of topics in .NET, let’s shift our attention to some JAVA questions. In this post, we will cover a few basic JAVA interview questions to get started. We will advance in complexity in later posts.
SO, first, let’s start with constructors.
Question: What is the difference between constructors and other regular methods?
Constructors must have the same name as the class name and cannot return a value. The constructors are called only once per creation of an object while regular methods can be called many times.
Question: What happens if you do not provide a constructor?
Java does not actually require an explicit constructor in the class description. If you do not include a constructor, the Java compiler will create a default constructor in the byte code with an empty argument. If a class includes one or more explicit constructors, the java compiler does not create the default constructor.
Question: Can you call one constructor from another?
Yes, the key is to use the this() construct.
public Shape(int id) {
this.id = id; // "this" means this object
}
public Shape(int id, String type) {
this(id); // calls constructor public Shape(int id)
this.type = type; // "this" means this object
}
Question: How can you invoke the base class constructor in the derived class?
You can use the super() syntax. Note that this has to be the first statement in the function.
public Circle(int id) {
super(id); //must be the very first statement in the constructor.
}
Question: How can you invoke base class methods in the derived class?
To call a regular method in the base class use “super.myMethod( )”. This can be called at any line.
public class Circle extends Shape
{
public void setUp()
{
super.initialize();
// do circle stuff
}
}
public void reset() throws Throwable
{
try
{
// Do stuff here to rest your object
}
catch (Throwable t) {}
finally
{
super.reset(); //clean up your parent class. Unlike constructors super.regularMethod() can be called at any line.
}
}
Question: Explain static initializers with an example.
When a class is loaded, all blocks that are declared static and don’t have function name (i.e. static initializers) are executed even before the constructors are executed. As the name suggests they are typically used to initialize static fields.
public class StaticInitializer
{
public static final int x = 5;
public static final int y;
//note that since y is final, it can be initialized only once.
//Static initializer block, which is executed only once when the class is loaded.
static
{
if(x == 5)
y = 10;
else
y = 5;
}
//constructor is called only after static initializer block
public StaticInitializer(){}
}
The code above sets the value of x to 5 and y to 10.
Given stuff and logical thinking are very good!
ReplyDeleteWhen coming to the java point there will be definitely asking the Questions
ReplyDeleteon the constructors!So i hope this is the good introduction for the java questions!
ya this is very very important to the interview, because constructors are the base for the objects creation....
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteWrite a program where the user enters the number of asterisk for the first row printed. The user will then enter another number (that is less than the number entered first). This number will be the number that each row will be decreased by. For example: User will enter 8 first and 3 second (row 1 - 8 asterisks, row 2 - 5 asterisks, row 3 - 2 asterisks. What will be printed is:
ReplyDelete********
*****
**
You can't print less asterisks than the decrement value (in the example you can't go below 2 because 3 was the decrement number).
This is quite simple:
Deletestatic void PrintStars(int startCount, int decrementValue)
{
// error checks
if ((startCount > 0) && (startCount >= decrementValue))
{
while (startCount >= 0)
{
// print current star count
Console.WriteLine(new String('*', startCount));
// decrement for next round
startCount -= decrementValue;
}
}
else
{
Console.WriteLine("Please provide valid input values");
}
}
Sain Bainuu,
DeleteThank you! Thank you! Thank you! Your blog was a total game changer!
Hello people, So I am having trouble uploading a file to my bucket. I have the proper credentials all set. The problem is when I try doing a
putRequest('bucket', 'keyName', 'fileFullPath') it will only save the file name and not the bytes. So I try sending it as an input stream to a byte array. This way it says there is no such file at specified location? I am running linux so It says no specified file at /home/{user}/pictures/example.jpg This is the problem I believe because it is searching from /home and not /
It was cool to see your article pop up in my google search for the process yesterday. Great Guide.
Keep up the good work!
Thanks a heaps,
Copper Wire Co. sells spools of copper wiring for $100 each. Write a program that display the status of an order. The program should have a function that asks for the following information:
ReplyDeleteThe number of spools ordered.
The number of spools in stock.
If there are special shipping and handling charges.
(Shipping and handling is normally $10 per spool.) If there are special charges, it should ask for the special chargers per spool.
Output: number of spools shipped, number of spools back ordered, subtotal of portion ready to ship, total shipping and handling charges on portion ready to ship, total of order ready to ship.
Validate: do not accept numbers less than one for spools ordered. Do not accept a number less than 0 for spools in stock or shipping and handling charges.
Once an order is printed, ask the user for the next order. Use a sentinel value to stop (q for quit or -1)
I came across your guide and found exact Basic-java Interview Q/A’s which I was looking for. Thanks for such a useful information’s. But I had found one good website related to Java interview Q/A’s. More Info: java-interview-questions
ReplyDeleteThanks for sharing such agreat article, really very helpful information. Keep sharing.
ReplyDeleteBest Software company in New jersey, USA
ReplyDeletewow...nice blog, very help full information. Thanks for sharing.
ReplyDeleteGrate blog to read its very nice explanation about Internet Of Things
Internet Of Things
Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.
ReplyDeleteBest Cloud Solutions | Austere Technologies
Really great blog, it's very helpful and has great knowledgeable information. Thanks for sharing, keep updating such a good informative blog.
ReplyDeleteQuality Managment Services | Austere Technologies
VERY INFORMATIVE BLOG. KEEP SHARING SUCH A GOOD ARTICLES.
ReplyDeleteInternet Of Things(IOT) Services | Austere Technologies
Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles
ReplyDeleteAustere Technologies|Mobility
Great article, really very helpful content you made. Thank you, keep sharing.
ReplyDeleteBest Software Testing Services | Austere Technology
Nice blog with excellent information. Thank you, keep sharing.
ReplyDeleteBest chartered accountant course in Hyderabad | Avinash college of commerce
Thanks for sharing this informative article..!!
ReplyDeleteKeep posting waiting for next post.
iOS Training in Bangalore Java Training in Bangalore
Great informative blog, thanks for sharing.
ReplyDeleteBest Blockchain services | Massil Technologies
Very useful information Big Classes has been constantly pioneering and evolving in the Online Training Industry. With an experience of over a decade and half in the training industry, Big Classes is today a name to be reckoned with for any kind of IT trainings in online model. With an army of trainers and a wide array of courses, Big Classes guarantees high quality training at an extremely competitive price, ensuring 100% value for money.
ReplyDeleteOnline IT Training
Excellent informative blog, keep for sharing.
ReplyDeleteBest System Integration services | Massil Technologies
Excellent informative blog, keep for sharing.
ReplyDeleteBest System Integration services | Massil Technologies
Finally I have found something which helped me. Many thanks!
ReplyDeletejava/j2ee classes Bangalore | java Training Center Bangalore | Best Core Java Training in Bangalore | java Course in Bangalore | Best Java Training Institute Bangalore Marathahalli | Core and Advanced Java Institute Marathahalli | Java Training Institute in Bangalore Marathahalli | Java Training in Bangalore
I like your blog, I read this blog please update more content on hacking,
ReplyDeleteNice post,and good information Thanks for sharing further check it once at
.NET Online Course
This is an excellent post that is being shared. Kindly do share more post in this sorts.
ReplyDeleteEnglish Speaking Classes in Mumbai
Best English Speaking Institute in Mumbai
Spoken English Classes in Mumbai
Best English Speaking Classes in Mumbai
English Speaking Course in Mumbai
English Coaching Classes in Mumbai
Best English Classes in Mumbai
Wow...What an excellent informative blog, really helpful. Thank you. Best Oracle DBA Course Training| orskl
ReplyDeleteOrskl
It was thinking about whether I could utilize this review on my other site, I will connect it back to your site though.Great Thanks. basic English vocabulary
ReplyDeleteWow...What an excellent informative blog, really helpful. Thank you. Best Oracle DBA Course Training| orskl
ReplyDeleteThe information is meaningful and magnificent which is shared here about the article. I really thank you for such a innovative post. if you want to take training in java, then ratindia.com is best for you. Summer internship program in jaipur
ReplyDeleteNext time I read a blog, Hopefully it won't fail me as much as this one. I mean, I know it was my choice to read, but I truly thought you would have something interesting to say. All I hear is a bunch of complaining about something that you could possibly fix if you weren't too busy seeking attention.
ReplyDeletebest service center in marathahalli
Samsung Galaxy S9+ authorized service center near me
oppo A77 service center near me
oneplus 5T authorized service center in banglore
realme 2 Pro authorized service center in banglore
Thank you so much giving me the useful information :
ReplyDeleteSelenium Training In Chennai
Selenium CourseIn Chennai
Selenium Training Institute In Chennai
Best Selenium Training Institute In Chennai
Data Science Training In Chennai
Machine Learning Course In Chennai
Data Science Course In Chennai
Protractor Training in Chennai
jmeter training in chennai
Rpa Training Chennai
Everything is very open with a precise description of the issues. It was really informative. Your website is very useful. Many thanks for sharing!
ReplyDeleteHuawei mobile LCD screen replacement near me
Vivo mobile LCD screen replacement near me
Motorola mobile LCD screen replacement near me
Asus mobile LCD screen replacement near me
LG Stylus 2 mobile LCD screen replacement near me
This comment has been removed by the author.
ReplyDelete
ReplyDeleteExcellent Post. I really admire after reading this blog.
ccna Training in Velachery
ccna Training in Tambaram
ccna Training in T Nagar
ccna Training in OMR
ccna Training in Porur
ccna Training in Vadapalani
ccna Training in Adyar
ccna Training in Thiruvanmiyur
ccna Training in Anna nagar
It's a nice article, Which you have shared here about the java. Your article is very useful for those who are want to learn java programming course. I would like to thanks for sharing this post here. Best Core Java With Data Structures Course In Delhi
ReplyDeleteGood Article
ReplyDeletedevops training in bangalore
hadoop training in bangalore
iot training in bangalore
machine learning training in bangalore
uipath training in bangalore
VISIT HERE => BIG DATA AND HADOOP TRAINING IN BANGALORE
ReplyDelete
ReplyDeleteIt is very beneficial information for me, I really impressed. This is very nice article and continues sharing with us...
Unix Training in Chennai
Unix Shell Scripting Training in Chennai
Embedded System Course Chennai
Linux Training in Chennai
Corporate Training in Chennai
Oracle DBA Training in Chennai
Tableau Training in Chennai
Pega Training in Chennai
Oracle Training in Chennai
Unix Training in OMR
Unix Training in Velachery
Thanks for your valuable content, it is easy to understand and follow.
ReplyDeleteEthical Hacking Course in Chennai
Hacking Course in Chennai
Ethical hacking course in bangalore
Ethical hacking course in coimbatore
Hacking course in coimbatore
Ethical hacking training in coimbatore
Ethical hacking in coimbatore
Data Science Courses in Bangalore
For Devops training in Bangalore visit:Devops training in Bangalore
ReplyDeleteExcellent web site you have got here.. It’s difficult to find good quality writing like yours these days.
ReplyDeletebest service center bangalore
I really appreciate individuals like you! Take care!!
Vivo display replacement Marathahalli
This is a topic that's near to my heart... Cheers! Exactly where are your contact details though?
Motorola display replacement Marathahalli
I seriously love your site.. Great colors & theme. Did you develop this website yourself?
ReplyDeleteHuawei display replacement Marathahalli
Please reply back as I’m looking to create my own website and would like to learn where you got this from or what the theme is named. Kudos!
Asus display replacement Marathahalli
Everyone loves it whenever people get together and share ideas. Great website, stick with it!
LG display replacement Marathahalli
The article explains value of Java and it is role inside Information Technology sector. It highlights the key role that Java plays in creating Online Advanced JAVA Training
ReplyDeletevery useful article.thanks keep sharing
ReplyDeleteBest Commerce College in Hyderabad
This comment has been removed by the author.
ReplyDeleteGood Information. Thanks for sharing
ReplyDeleteBest Junior College in Hyderabad
Very useful blog. excellent Information . Thank you . keep sharing
ReplyDeleteBest BBA College in Hyderabad
This comment has been removed by the author.
ReplyDeleteGood Information.Thank you.
ReplyDeleteDegree College in Hyderabad
About Director
thanking for sharing useful information
ReplyDeleteBest CEC and MEC college in Hyderabad
thanks for sharing information
ReplyDeleteBest commerce college
very useful information.thank you.
ReplyDeleteBest Commerce college in hyderabad
The Blog content is very informative
ReplyDeleteBest Commerce college in hyderabad
good post
ReplyDeleteBest commerce college
good post. thank you
ReplyDeleteBest commerce college
Best BBA college
ReplyDeleteThe information is useful thank you. keep sharing
ReplyDeleteBest Degree college in hyderabad
ethical hacking is the upcoming, valuable and job oriented solution that IT companies and other industrial sectors are adapting today. machine learning courses in hyderabad
ReplyDeleteThe blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much. i appreciate your efforts taken for the same. I found this worth sharing and must share this with all.
ReplyDeletedigital marketing company in bhubaneswar
website design and development
I am so happy to found your blog post because it's really very informative. Please keep writing this kind of blogs and I regularly visit this blog. Have a look at my services.
ReplyDeleteCyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course | CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course
Thanks for sharing this wonderful content.its very useful to us.It was very interesting and meaningful.I gained many unknown information, the way you have clearly explained is really fantastic.keep posting such useful information.
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course
Full Stack Training in Bangalore | Certification | Online Training Course
Full Stack Training in Hyderabad | Certification | Online Training Course
Full Stack Developer Training in Chennai | Mean Stack Developer Training in Chennai
Full Stack Training
Full Stack Online Training
Thank you for sharing valuable information. Thanks for providing a great informatic blog, really nice required information & the things I never imagined.
ReplyDeleteCyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course | CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course
Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us.This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteDevOps Training in Chennai
DevOps Online Training in Chennai
DevOps Training in Bangalore
DevOps Training in Hyderabad
DevOps Training in Coimbatore
DevOps Training
DevOps Online Training
1. PHP VS Java: Performance & Speed. In a nutshell: While comparing the Java vs PHP performance, Java is clearly a winner as it is faster and efficient than PHP to write enterprise applications. Like developers have to build mobile enterprise applications to streamline complex business processes and operation
ReplyDeleteJava Training in Chennai
Java Training in Bangalore
Java Training in Hyderabad
Java Training in Coimbatore
Java Training
very interesting blog
ReplyDeleteSoftware Testing Training in Chennai | Certification | Online
Courses
Software Testing Training in Chennai
Software Testing Online Training in Chennai
Software Testing Courses in Chennai
Software Testing Training in Bangalore
Software Testing Training in Hyderabad
Software Testing Training in Coimbatore
Software Testing Training
Software Testing Online Training
Great article, really very helpful content you made. Thank you, keep sharing.
ReplyDeleteacte reviews
acte velachery reviews
acte tambaram reviews
acte anna nagar reviews
acte porur reviews
acte omr reviews
acte chennai reviews
acte student reviews
This is a fabulous post I seen because of offer it. It is really what I expected to see trust in future you will continue in sharing such a mind boggling post
ReplyDeleteDigital Marketing Training Institutes in Hyderabadad
Best commerce college.
ReplyDeleteBest commerce college
Thanking for sharing nice information
ReplyDeleteBest commerce college
This comment has been removed by the author.
ReplyDeleteThe Blog Content is very informative
ReplyDeleteBest Degree College
good@!!!!!
ReplyDeletebest degree college
I like this post,And I figure that they making some incredible memories to scrutinize this post,they may take a good site to make an information,thanks for sharing it to me
ReplyDeletecertification of data science
You totally coordinate our desire and the assortment of our data.
ReplyDeletedata science course delhi
Thanks for sharing this post.
ReplyDeleteThis article really useful for me and I learn a lot of things from this blog.
I am working as a freelance full stack developer
Mua vé máy bay liên hệ Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ hạng thương gia
đặt vé máy bay giá rẻ từ mỹ về việt nam
vé khứ hồi phú quốc
vé máy bay giá rẻ hà nội nha trang
giá vé máy bay hà nội sài gòn khứ hồi
Great blog post,
ReplyDeleteDigital Marketing is right now the most stable job you could have. There are many openings for Digital Marketers around the globe. Hence we suggest you to attend our Digital Marketing Course in Hyderabad to acquire skills that a Digital Marketer needs.
Thank you so much for sharing all this wonderful information !!!! It is so appreciated!! You have good humor in your blogs. So much helpful and easy to read!
ReplyDeleteJava Training in Pune
Thank you quite much for discussing this type of helpful informative article. Will certainly stored and reevaluate your Website.
ReplyDeleteAWS Training in Hyderabad
Mua vé máy bay tại Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ
chuyến bay mỹ về việt nam
vé máy bay khứ hồi từ đức về việt nam
chuyến bay từ nga về việt nam
khi nào có chuyến bay từ anh về việt nam
chuyến bay từ châu âu về việt nam
khách sạn cách ly tphcm
Keep sharing the informative blogs. Thanks!
ReplyDeleteJava Classes in Pune
Nice and very informative blog, glad to learn something through you.
ReplyDeleteai course in aurangabad
Nice blog. it is very nice java question of interview. keep it up, Thanks for sharing these information with all of us. whatsapp mod
ReplyDeleteGreat blog, it is very impressive.
ReplyDeleteBlockchain Course in Chennai
Blockchain Training in Chennai
Great post and thanks for sharing.
ReplyDeleteAlso visit:
CCNA Training In Madurai
Thank you for this blog. Share more like this.
ReplyDeleteAWS Training in Chennai
AWS Online Training
AWS Training in Bangalore
AWS Course in Coimbatore
great blog. keep sharing more.
ReplyDeleteArtificial Intelligence Training in Chennai
AI Training In Bangalore
Artificial Intelligence Training in Coimbatore
Great blog. keep sharing more.
ReplyDeleteFull-stack developers have the qualifications and experience to add market-exciting features to your product. The experts can handle the entire stack from the ground up. If you want to see a return on your investment, you must rely on such knowledge. Not everyone is equipped to handle your web project from start to finish. Learn over 30 Full Stack tools and technologies and put them to use on numerous projects. Complete a Full stack training in Pune to master these abilities and land a job.
(https://www.iteducationcentre.com/full-stack-training-institute-in-pune.php)
Java is a programming language that can create programmes for a variety of platforms. Sun Microsystems created Java, a high-level programming language. There are several programmes and websites that will not function unless Java is installed. It is a popular choice among developers and hubs since it is dependable, quick, and secure. Java can be found anywhere.
ReplyDeleteExpertise in both front end and back end JavaScript-based technologies. more It-education-learning Java Classes In Pune
Wow it is one of the best things i came across on the internet.
ReplyDeleteJava Classes in Pune
I like your blog. Your interview question really helpful for me. I gain more knowledge about java from your blog. If candidate want to know more about then you search 8 Most Common Guesstimate Interview Questions & Answers [For Freshers] for more questions.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThanks for the blog, these questions really help in interview. To Learn a Java course, join an institute for Java course, which provides Java training in Kanpur, Gorakhpur, Delhi, Noida, and many more cities in India.
ReplyDeleteGreat blog post! I found your insights on the topic to be really helpful and informative. Your writing style is engaging and easy to follow, making it a pleasure to read. Thanks for sharing valuable resources Besides this if you want to learn about Python Training Course in Mohali, Allahabad, Gurgaon, and all cities in India.
ReplyDeletethat's very informative and superb blog.Keep up with your great work.
ReplyDeletealso, check Java Course in Nagpur