L Hasan

Greenhorn
+ Follow
since Oct 02, 2016
L likes ...
Eclipse IDE Java Linux
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
4
In last 30 days
0
Total given
0
Likes
Total received
10
Received in last 30 days
0
Total given
6
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by L Hasan

Hey guys,

Just wanted to say that I recently sat this exam, scoring 91% which smashes the pass mark of 65%, and I want to share some of my experiences:

Read Selikoff and Boyarsky's official OCA exam guide. It is incredibly useful, and be sure to check the errata site. One tip when reading the book is; there is a small appendix towards the end which gives you a basic timetable you can work from, to read through each chapter. Read this before anything else in the book!

The Enthuware suite was so useful in my preparation, there are topics the book does not fully cover which some of their practice exam questions do. The Enthuware suite seemed to be a step up in complexity compared to the real exam; which I think comes down to the variable time limits you have on some of the practice exams. The insight they give on why each question you get wrong either enforces, or adds to, the info you glean from the book. It is also valuable in helping you get an idea of how many questions you can do in the allotted 2 hour time.

Finally I would like to say thanks to everyone who has helped answering my queries here, and those before me who shared their successes and inspired me to achieve highly in this exam.

Regards,

L.

Tim Cooke wrote:You cannot be certain because you don't know what the method s(B b) in class A does with the reference to object b that's passed into it. It may pass that reference on to something else that keeps hold of it, or maybe it doesn't. You just don't know.

Make sense?



To expand on what Tim said, and to help solidify my understanding too ;)  :

It's possible that the method s(b) passes the reference to a static class member (e.g. ArrayList) of A. Because static members don't go out of scope until the program ends, then it's possible the object that 'b' referred to isn't eligible until this time.

Hope that helps,

Liyaan.
Apologies, I forgot to use code tags and cannot find how to edit.

So. When in the directory (command line) and compiling - they see each other. Once I introduce the "package directoryName;" statement on the first line of each class, I need to go to the parent directory in order to compile them.

Surely it shouldn't make a difference, as long as they are declared under the same package.

L.
Public, they are both defined in their own files:

Order.java -
public class Order
{
...
}

OrderDriver.java -
public class OrderDriver
{
...
public static void main(String[] args)
{
}
}
Hi all,

The question defines 2 classes, Order.java and OrderDriver.java. They are both defined in as what I can assume would be the same package, even though line 1 does not start with a package declaration for either class. I assume they exist in the same package as I can compile them and they reference each other without imports.

If I add a package definition for each, I can no longer compile OrderDriver, at least from within the directory they exist. If I move to the parent directory, I am able to compile OrderDriver.java. My question is, why do they stop seeing each other when a package definition is provided on line 1 - I can't even import one into another - which all happens when I try to compile within said package directory.

Thanks in advance,

L.

Hello William and welcome to the Ranch!

I have a question as someone who has only recently picked up Linux myself. What are your thoughts on certifications (such as LPIC) as a teaching method to learning Linux?

It's something I used and it did give me a basis to work on however, I see it more as "here is the information that will be on the exam, learn this book" type syllabus as opposed to the systems admin that it conveys you can become from it. I would love to hear your thoughts on it.

L.
6 years ago
Hi,

I think I understand what you're trying to get out of the method, but at best it would be guessing; you want to take an order and, based on said order, reduce the inventory amounts of stock appropriately, and then return the cost of the sale?

You could easily break this into separate methods, one for handling inventory updates, and one that increases sales by the cost of the order.

L.
7 years ago
Hi,

I'm working on some performance testing myself, having to get benchmarks from an already in production software. My question conveys a bit of a chicken and an egg scenario;

How do you know that the benchmark/metrics you get from production are accurate? Wouldn't you need performance testing in the first place to say that the metrics you acquire are *good* metrics. But then without the initial benchmarks, how can you measure your tests with any reliability?

I hope that makes sense.

L.

7 years ago
One possible value I could think of as being static might be a 'banned player list'. As is usual in somewhere like Vegas, if a player is banned from one casino, they are blacklisted from other casino's in the same area.

But then this [possibly] wouldn't apply to casino's outside the area. It depends on what your problem domain relating to casino's is?

L.
7 years ago
The missing = on the loop init is my bad. This information comes from the OCA Java SE 8 Programmer 1 Certification book by Boyarsky and Seikoff.

How do you know that a String Builder is used at runtime? Quoted from the book page 111: However, because the String object is immutable, a new String is assigned to alpha and the "" object becomes eligible for garbage collection."

It then goes on to state that proceeding strings created to replace alpha, like "a", "ab" etc. will all also become eligible for GC after each loop.

Thanks for the response,

L.
7 years ago
Hi,

I'm reading through the OCA certification book and am on the section regarding Strings. There's an example of not using a StringBuilder:



It states that every time you go through the loop, the alpha reference is assigned a new String object, and the old one becomes eligible for garbage collection. e.g. first loop alpha = "", second alpha = "a" and "" is for GC.

However, from what I've read of the String Pool, it would seem that each literal created in this way would be placed into the Pool. So wouldn't that mean said literals don't become eligible for GC because the pool still holds reference to them?

Thanks,

L.
7 years ago
In response to Junilu; I will take the advice of the JLS, the source is the most correct! Maybe this would be one to raise as an errata.

Not to derail the original thread. Don't be disheartened, I meant to get practice on things like variable scope (class, instance and local variables), when to declare and assign variables, working with arrays etc.

If you feel you are ready to tackle classes, I'll give you a clue as to what you need to do to fix your class as it stands. Read up on 'instance variables' and apply that to the UserName attribute. Take a look at 'method overriding', if you want to pass the object you instantiate to println(), you'll want to override toString() found in the 'Object class'.

Hope that helps,

L.
7 years ago

Junilu Lacar wrote:

L Hasan wrote:A constructor is a class method that has no return type.


That is incorrect.  Yes, a constructor looks like a method that doesn't have a return type. However, constructors are not methods, they are not considered members of the class, and they are not inherited nor do they participate in polymorphism.

See these articles:
http://www.dummies.com/programming/java/how-to-use-a-constructor-in-java/
http://www.javaworld.com/article/2076204/core-java/understanding-constructors.html



Hi,

I'm currently studying the OCA Java 8 study guide pg. 17 (Jeanne Boyarsky and Scott Selikoff)

It's called a constructor, which is a special type of method... and there's no return type.

.

Is this one of those instances where it's one opinion versus another, and there's no definitive answer? It's very confusing when there are sources (online also) that contradict the ones posted.

Thanks,

L.
7 years ago
Hi,

There's a number of separate topics to be discussed here, but first an observation to your 'User' class:

You've declared and assigned your UserName variable within the constructor. This means you can't access this variable anywhere else, not even within the scope (a point of study) of your class, only your constructor knows about this.

A constructor is a class method that has no return type. It guarantees that a class is instantiated to a certain level of state, at the objects' creation.

The other issue you have is that you cannot print 'John' directly, as this only prints a value that represents the memory address of the object. The needs to have its method overridden (parent class being Object) to print anything meaningful. (another point of study)

As an aside, it might be better to step away from classes at the moment (even though everything in Java is built around this concept) and focus on writing methods to use within a main(), sort of like a mini-script. Try to understand the creation and scope of variables, how these can be passed into, and modified by methods. How a method can collect a group of commonly used statements and be used over and over with a single line of code.

I could go on, and I might based on responses.. =]

I hope that helps,

L.
7 years ago

Campbell Ritchie wrote:What a nice post You explained what I meant better than I could have.

Except you wrote

. . . if(canInit == true) . . .

Never use == true , or == false.
I have written about that many times. It is very error‑prone.
Use
if (b) ...
or
if (!b) ...
instead.



That's no problem, glad to be of assistance!

Could you tell me why it is error prone? My best guess is that you could mistakenly assign:



As opposed to comparing for equality:



L.
7 years ago