• 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
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Understanding where things come from - language/library references?  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi - new to java and NetBeans IDE.

One of my biggest frustrations in researching examples, reading tutorials, etc.  - which I'm doing a lot of in trying to learn Java ... is that they almost never seem to tell you what packages(?) need to be imported to run the code they are showing.  And even if they do, it's difficult (for me at least) to understand where a class/method is coming from. I'll see something like FooClass or fumMethod doing stuff, while having no idea where it is defined? Is this just a matter of grasping this stuff by osmosis over time, or am I missing some simple way to divine this information?

Related to this - and perhaps this is a  NetBeans specific question, is there a way to "Switch to" the class/method definition/file by highlighting a class or method name and typing some key shortcut or something?  Also - is there anyway to highlight a keyword or class name (for the base java classes I guess) and get some sort of language reference? In fact - is there language reference at all anywhere? I'm talking something like this (from SQL Server documentation - I pulled this at random):

https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-describe-cursor-transact-sql

Thanks - making progress - but too slowly and getting frustrated ....

 
Bartender
Posts: 19807
93
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ken Matson wrote:or am I missing some simple way to divine this information?



Yeah, Google. 

Alternatively, if I know the class, I may search the JavaDocs, assuming I know what source the package comes from, can locate its JavaDocs (assuming there are some - which most of the reputable systems do have).

Seriously, I too find it quite annoying when people display code snippets with insufficient context. You are not alone.

I can't speak for NetBeans these days, but it's not uncommon to be able to right-click on a word and bring up a context menu that can do things like jump to source or display a popup JavaDoc snippet. Sometimes holding the Ctrl or Alt keys helps.
 
Ranch Hand
Posts: 415
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ken i asked a similar question a few days ago...though i must admit you asked it better...

this is what somebody sent me..you prob have it already

Some references you should be sure to save:
http://docs.oracle.com/javase/8/docs/api/index.html
http://docs.oracle.com/javase/tutorial/reallybigindex.html
 
Marshal
Posts: 6121
418
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are new here, so welcome to the Ranch

Tim said already, the main source about the Standard Java Library is in JavaDocs (<-- click). These docs are for JDK9. There is one feature introduced since Java 9 came out, that they also created a search functionality within the docs - that's very helpful. So what you do, is you type class name or method name and if that is part of standard library, for sure you'll find there. That information will contain information API's user needs. You won't see implementation of them - but you don't need to. In case you want to have a look at actual source code, you can navigate to where Java is installed and unpack src.zip file and there you'll find source code. Or for a quick sneak you can look to classes implementation from within the IDE, at least IntelliJ IDEA can do that (ctrl+b or cmd+b) as it unpacks src.zip file itself under the hood. I'm quite certain Netbeans also can do something similar, just don't know the shortcut.
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ken Matson wrote:Related to this - and perhaps this is a  NetBeans specific question, is there a way to "Switch to" the class/method definition/file by highlighting a class or method name and typing some key shortcut or something?  Also - is there anyway to highlight a keyword or class name (for the base java classes I guess) and get some sort of language reference? In fact - is there language reference at all anywhere?



I expect there is -- both of those things exist in Eclipse so Netbeans should have them too. I copied this thread to the Netbeans forum so maybe somebody reading it there will know the answer.
 
Sheriff
Posts: 5287
142
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* When you've copied and pasted code that has no imports: click the class and press Alt-Enter (I believe it has to be the left Alt key).  This will give you suggestions as to which imports you should add.

* When you've not sure where a method is defined: right-click the method and select Navigate.  It will show you many useful tools.  Ctrl-B goes to the declaration and Ctrl-Shift-B goes to the source code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!