Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!

Ankit Garg

Sheriff
+ Follow
since Aug 03, 2008
Ankit likes ...
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
Bangalore, India
Cows and Likes
Cows
Total received
42
In last 30 days
0
Total given
17
Likes
Total received
298
Received in last 30 days
0
Total given
241
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ankit Garg

The question says that "For simplicity, let's give each module the same name as the package". The question doesn't say that the module name is magic.helper. I guess instead of making it simpler, the question made it more confusing
Hi Shoeb, welcome to the Ranch.

Did you try to contact your credit card provider?
The compiler is intelligent these days, so as Charles said, it can figure out that the value you are giving on the right hand side is within the range of short.

The only exception to this is when you are passing an int literal to a method which takes short as argument. In that case you have to do explicit type-cast. There is an example specifically in the JLS for this:

5.3. Method Invocation Conversion

Also, I am sorry if I posted this under wrong forum title. I am new here and trying to learn how this website functions.


Welcome to the Ranch, no need to apologize, we've all been there

As Tim said, OCP certification won't help you much with getting an Android developer job, but it won't hurt either. So if you have the time you can study for it. Depending on which companies you interview with, Algorithms/Data-Structures, problem solving or aptitude might also be part of the interview.

Just out of curiosity I keep checking jobs in my area and most of the employers ask for knowledge in company specific software they are using.


These type of requirements are never a must have, they are always a good to have. If you are familiar with Android development for example, it won't take much time to start using any Android framework or library. You can read intro of these frameworks if you want, but your focus should be getting basics and concepts clear.

Any books that someone can recommend?


I've personally not gone through any Android training or books recently, but you can go for free trials of Lynda or Pluralsight and explore the courses there.
I think you might want to start by looking at a basic Spring program, few example project tutorials I found are listed below:

https://www.tutorialspoint.com/spring/spring_hello_world_example.htm
https://www.vogella.com/tutorials/SpringDependencyInjection/article.html
https://dzone.com/articles/dependency-injection-in-spring

There are multiple ways to make Spring work, java config, xml config, component-scan to automatically find the beans (or a combination of these). Dependency injection can also be explicit or auto-wiring. You should start with whatever approach you find easiest to understand first.
5 months ago
The stream package javadoc sums it up pretty well.

javadoc wrote:Consumable. The elements of a stream are only visited once during the life of a stream. Like an Iterator, a new stream must be generated to revisit the same elements of the source.

Alexandros Collie wrote:You misspelled superman in line 8.


That's a great catch

However even if you spell it correctly, the output won't change. The compiler changes String s2 = "Superman" + ""; to String s2 = "Superman"; as at compile time it knows the result of the concatenation. This happens for any String concatenation with literals. So if you wrote String s2 = "Super" + "man";, the compiler will change this to String s2 = "Superman";...
Check the java.lang.Object class which every class in Java inherits from (directly or indirectly), see what methods you see in there.
IMO 3rd option is the least confusing

Isn't this how lambda works, if you need an instance of an interface, and the interface is functional i.e. it only has one abstract method, then you can use any method with the same parameters and return type as an implementation of the interface using lambda. In this case the interface has more methods with default implementation, but for any method to be used as an implementation of the interface, you only need to worry about the abstract method in the interface.

To add to Salvin's answer, can you do this:


In the same way do the lambda in all the other options qualify as implementation of Carnivore interface.
In the first case since you are concatenating two literal values, the compiler can do the concatenation and JVM will have the value in the pool. And since both the literal values are same, both string variables are pointing to the same value in the pool. In the second case since there is a variable involved, compiler cannot do the concatenation. At runtime JVM will do the concatenation and in that case the value doesn't go into the pool.
If the element should be at the first place in the array (which means it is smaller than all elements in the array) i.e. at index 0, you'll get -1 as result (as it can't return you -0 as there is no -0). If the element should be at the 1st index of the array, you'll get -2 and so on. So if the element should be at the last of the array i.e. it is greater than all the elements of the array, you'll get -(array.length + 1). Length of your array is 4, so you'll get -5 in that case. Since the element is greater than all the elements in the array, it should be placed at 5th index of the array which doesn't exist.

But why does not superString add new Object as the generic type says "? super String" and Object is super of String.



Are you still confused? If you are let me try another example


Let's say I'm writing this API for anyone to call. The second call doesn't compile. Why? Because there is no guarantee that the List I'm passed can store Object. If the compiler allowed me to add Object to this List, it can break type safety. What if I wrote the following code to call this method:

If the  manipulateList method was allowed to add Object to stringSuperList, the above code will end up having an Object in a String list. An Object is-not-a String. If somehow I'm able to add Object to it, when I retrieve the element, I'll get ClassCastException. Generics is supposed to save you from ClassCastException, not let it happen.
Yay you found it

Why can't anyone have your copy? You can have it back whenever you need it