Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Andy Jack

Ranch Hand
+ Follow
since Nov 22, 2012
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andy Jack

I have a particular problem in mind for which I have a software solution. Eg. If the problem is to find a means for quick, easy and instant communication over the internet, I think of developing an instant messenger. Before I think of
coding, I want to resolve the following questions -
How do I design my program?
How do I get the requirements right?
Then, how do I decide how many classes or which classes are needed and what functionality they will provide?

Is there a book that can teach me all these things? I am looking for a book which will give me a small problem statement or a real world problem and then ask me to design the code, make use cases, flow charts etc.
Then, it will show me a suggested solution which I can compare with my solution.

Thanks in advance.

8 years ago

Campbell Ritchie wrote:

Andy Jack wrote: . . . So, use an IDE and and learn the basics taught in the SCJP book quickly. Once you learn all the basics, you can do all your coding without an IDE. . . .

Not at all. It should be the other way round.

Learn to use an IDE after you are experienced in the use of text editors and the command line or terminal

That is exactly what I had done for the SCJP. I found it to be a serious impediment to my progress. In hindsight, I realized that I could have learned things much faster and then done all the compile, make package, make jar commands for SCJP. If I wanted to learn WAY more than what was covered in the SCJP,
then I would use command line and build tools instead of an IDE. The command line based topics in the SCJP are such that you can do them after you learn the language using an IDE.
8 years ago

Terry Tucker wrote:Thanks for the reply and advice. I am using command line and vim for this because the SCJP Study Guide recommended putting aside the IDE. I did create a couple classes as you suggest and have shown that both constructors and methods, without an access modifier specified, behave with "default" access.

Again, thanks for the help...

Well, the SCJP guide has good reasons to recommend a non-IDE approach. Right now, I guess that your goal is to learn quickly. So, use an IDE and and learn the basics taught in the SCJP book quickly. Once you learn all the basics, you can do all your coding without an IDE.
The SCJP book by kathy sierra and bert bates is excellent. But, do not use that or any SCJP book as your first book to learn Java.

8 years ago
And please read some good text books for questions like these - head first java, absolute java by walter savitch, thinking in java etc.
8 years ago

Terry Tucker wrote:Greetings Moose People:

I would like to know if a constructor that has no access modifier explicitly stated behaves the same as a class that is declared without an access modifier; that is, does if have "package access" (default)? What about methods? When no access modifier is supplied, do they have package access?

Thanks for the input...

When you have little questions like these. Please make code yourself to see how things behave. Create a package called 'src'. In that, create 2 packages ex and dummy.

...this is ok.

but this is not -

If you are not using an IDE to compile and run your code, then please do it. Its good because it shows you errors the moment you make them. This is good for beginners. You can experiment quickly and see results with less effort.
Do command line once you know the language well.

8 years ago

bharat bhasin wrote:Thank you Andy for your answer .

But I don't understand the explanation .
You say the "this" is a reference of class A , OK I got it .
But I don't understand why it cannot see the show() method of class B . I know it is private and not visible to class A but the JVM checks whether its present in class B and it is present .
I didn't understand how this whole thing works .

I did not say that the JVM can see it. YOU and I can see it. But as far as any other class is concerned, it cannot see private methods of B, even if they are in the same package. This is what the keyword private is meant for.
Please read more about access modifiers and such.
8 years ago
I don't know how much the API for servlets has changed. I suggest that you use only the API's in bert's book and learn all the basic stuff (eg.MVC) from the book. Once you get a solid foundation, read the oracle docs to upgrade your knowledge.
If you go to the docs first, you might not understand much and might get frustrated and discouraged.

8 years ago
I wish I was smart enough to understand your code the moment I saw it. Please describe your code in detail with comments. Nobody has the time to go through lots of code.
To see what it feels like if you were in our position, please describe the code below and tell me if there is a problem in it.

Makes sense ?
8 years ago

bharat bhasin wrote:I wrote a program as follows :

public class A {

private void show() {


public void value() {;

public static void main(String[] args) {

A obj = new B();



class B extends A {

private void show() {


I was expecting the output to be this " B () " , but the output comes out to be : "A ()".I don't understand this . . Now after using "" I expect the method show belonging to class B to be called instead of the method of the class A , because of the following reasons :

1. show() is a private method in class A , so class B doesn't extend it .
2. I have assigned an object of type B to the reference of class A .
3. I am using the "this" operator with show() , so I expect that the method from class B should be called but show from class A is called instead .

Can anyone please this behavior ?

Firstly, good question !!!

1. show() is a private method in class A , so class B doesn't INHERIT it .
3. Consider another example. Forget the value() method for now. focus on showOff1().

The type of obj is A according to our declaration, but its actually B. So, the JVM checks if there is a method showOff1() in A. Good...then it proceeds to check the actual type of obj, which is B. Do we have a VISIBLE showOff1() in B ?
Yes, so execute the showOff1() of B and not of A.

When you look at show(), the same steps are performed. But, there is a difference.

The 'this' is a reference of type A. The JVM sees there if there is a show() in A. It is there. Then proceed to check 2. Is there a show() in B? We know that there is a show() in A and B.
But the code of class A, ie main method cannot see it because its private. So, the JVM chooses to execute show() of A. <EDIT: Bad choice of words>. The JVM will execute only what is legal/allowed.

Try this - put this code in B and see what happens.

8 years ago
I am not sure what you want exactly. But, i will try to help. PassObj(int p1, int p2) is to allow you to initialize the variables of a PassObj instance.
The instantiation PassObj obj1 = new PassObj(5,6); actually pass parameters to the above constructor - yes, but here parameters are passed by copy.
How to check when things are passed by copy or value? Try the code below.

And read this link too.
8 years ago
I am a newbie. So, it is obvious that jobs wont come easily or wont come at all initially. I am looking for companies where i can work and get a few hints & tips from experienced developers when needed, so that i can do some good work and develop my skills in the process. Paid position is nice to have, but not necessary. I can try open source projects, but they won't teach me corporate culture and workplace politics/dynamics like a real company job. Thats why i prefer companies instead of open source.

I regularly write custom cover letters faking interest and vision (I have passion, I am impressed by your company...blah blah), everything else being true. How the hell is everyone supposed to know what they want to be in 5 years from now and have a goal? How am I even supposed to figure out a goal? I like so many things - web development, java backend,...malware analysis and creation too ! (tears of joy meme) and mobile app development.

Right now, I just want a job to learn java (dont care if its mobile, backed, swing gui), I will decide later if i hate it or like it. People in the industry change jobs because they prefer other roles, besides others things like location, benefits etc. Sometimes, it take them a while to realize that they wanted something else. Thats not such a bad thing. Its ok if you have not defined your whole career path well and will figure out things along the way.

Why do some employers expect this vision and well-defined plan from the get go? Why don't they look at it like - hey! this guy has potential, has some skills and can do the job. We are hiring him for a junior position with low level responsibilities. So, why does his passion matter at this stage? Lets see what he can accomplish and then put him in a department where he will excel and add value to the company.

8 years ago

fred rosenberger wrote:If we take all the chaff out of your toString method, we are left with this:

That line 4 is a call to a method. The method you are calling happens to be itself. Which then calls itself. Which then calls itself...

oh yes.
8 years ago
Assume that scientists have not discovered Ostrich, Penguin, Chicken which cannot fly Chicken can fly for about 20 seconds When they discover that, they will have to change bird class. Flying bird, non flying bird. Flying implements canFLy and other one does not.
8 years ago

Lucy Rai wrote:Please tell me answer. I am java fresher.

Say we are making a computer game that depicts the earth and all the living and non-living things in it.

When two (or more) things are closely related you can combine all their common functions and properties inside an Abstract class and then derive from it. Example. Bird and Mammal are living beings, they can move(), eat(), breathe(), reproduce(), exist as dimorphs(male/female). We know all this from our knowledge of biology. So, we create an Abstract class Animal with abstract methods like move(), eat() etc and variables like sex = male or female (or transgender???). Then Bird and Mammal define methods in their unique way - bird eats with beak, mammal with mouth etc.
Tomorrow, if we discover a new animal in some jungle, its quite likely that it will be similar to bird and mammal, at least in some ways. To define that new animal, we will simply extend from Abstract animal class and add the add the extra features or modify animal methods accordingly.

Interfaces are used when two things can perform similar functions, but are not very closely related. Example bird and bat can fly. Even airplanes can fly. So, is a bat a bird or vice versa ? No, bats don't lay eggs and they breastfeed. So we make an interface canFly or flyable or something like that. Bat and
bird implement that interface. When a third person reads the documentation for bat and bird, he sees "implements canFly" and extends Animal. So, he knows immediately that they are animals, but not the same kind. They can fly (and have two feet etc) but a bat is not a bird.

(Hey, potato has skin. I have skin. So am i a potato ?...Monkey has hair, monkey has skin. It can walk, eat and reproduce like me. It looks like and shares a huge percentage of its DNA with me. So, am i a i am like a monkey... )

I feel that these may not be perfect examples. But, i thought they could guide you and maybe you can think of a better example.

8 years ago