This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

The parameter type of indexOf() isn't understandable,on page 107(Java OCA 8 Programmer I Study Guide  RSS feed

 
Ranch Hand
Posts: 207
27
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 107, first and second rows are:
When I practice this code in Netbeans I saw that the parameter type of indexOf() is int.


Then I look through Oracle documentation:
It is confusing for me, parameter type is int but we pass char type value as parameter?! When we pass int, return value always be “-1”. What happens?


When I note above question I saw another minor type. On the same page, second and fourth rows, second parameter type of method are incorrect:
should be:
 
Sheriff
Posts: 11604
178
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mushfiq Mammadov wrote:When I note above question I saw another minor type. On the same page, second and fourth rows, second parameter type of method are incorrect:


True! That's a typo: index is of course not a valid (primitive) data type and should be replaced with int
 
Roel De Nijs
Sheriff
Posts: 11604
178
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mushfiq Mammadov wrote:It is confusing for me, parameter type is int but we pass char type value as parameter?! When we pass int, return value always be “-1”. What happens?


No, it doesn't return always -1. Let's have a look at this example:Output: 1 -1 7

If you don't know what's happening behind the scenes, it looks like magic or even voodoo If you know what's happening, it's very easy (as always). Now let's look at this code snippet:Magic isn't it? What's really happening is very well explained in this (and following) posts. (Disclaimer: these posts are mine so probably a little biased )
 
Mushfiq Mammadov
Ranch Hand
Posts: 207
27
Java jQuery Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Roel De Nijs wrote:
Let's have a look at this example:Output: 1 -1 7

If you don't know what's happening behind the scenes, it looks like magic or even voodoo If you know what's happening, it's very easy (as always). Now let's look at this code snippet:Magic isn't it?


Wow! It is a very good example, Roel, I understand everything now I don't know we can initialize int as this: int i3 = 'a'; I also learn this. Thanks, Roel
 
author & internet detective
Posts: 39208
726
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mushfiq. Added to the list.

The "index" parameter type is a typo. The "char" vs "int" was me simplifying the method signature as I did here. In hindsight, that wasn't a good decision as it didn't make things easier
 
Whatever you say buddy! And I believe this tiny ad too:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!