The Artima Developer Community
Sponsored Link

Java Buzz Forum
Nested Classes and how they work

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ben Hosking

Posts: 208
Nickname: hoskinator
Registered: Apr, 2006

Ben Hosking is Java Developer with about 5 years experience and interest in OO
Nested Classes and how they work Posted: May 8, 2006 4:51 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ben Hosking.
Original Post: Nested Classes and how they work
Feed Title: A Funny Java Flavoured Look at the World
Feed URL: http://businesslogs.com/WebLog/RSS.xml
Feed Description: The blog looks at using Java and programming in general as it pops up in life as a Java programmer. It will have links to interesting Java articles and resources. It will also have a lot of SCJP Java 1.5 information and links as I am currently studying
Latest Java Buzz Posts
Latest Java Buzz Posts by Ben Hosking
Latest Posts From A Funny Java Flavoured Look at the World

Advertisement

One of the most confusing parts of Java our nested classes. The syntax can be very tricky with classes inside methods and methods overwriting others and semi colons on the end of curly brackets, the bottom line is it can be be very confusing.

Nested classes are probably one of the biggest SCJP Java 5 exam gotchas out there. The Java exam has a will not compile option on every question and inner classes makes this option very tricky because there syntax can look wrong and make the code look like it won't compile.

The examples are from the book Hardcore Java here is a link to the book if you are interesting in it http://www.oreilly.com/catalog/hardcorejv/

I also linked to another free PDF from this book which is a sample chapter on using the final keyword. Click the link to read my blog on the chapter and there is a link to the free pdf on final classes
http://hoskinator.blogspot.com/2006/04/hardcore-java-final-story.html

I really like the two sample chapters I have read from Hardcore Java here is a quote about the book from the OReilly website

"Hardcore Java takes this language and breaks it apart, piece by piece, revealing the important secrets and tricks that will take you from a junior-level programmer to a seasoned and expert developer."

nested classes in Java is one of the more confusing concepts and can make reading someone else's code very confusing, especially if you are not to sure how nested classes work. The chapter also squashes the myth/misinterpretation that Static nested classes are inner classes. With most things in Java the best way to understand the programming concepts being talked about is to give examples and this sample chapter gives lots of examples.

if you don't understand inner classes I would recommend reading these articles because they can be very useful. The way I look at Inner classes is that they are like composition and using another class in your code, except the inner class has access to all of your private variables, which is a big advantage. If you are studying for the SCJP exam I definitely recommed you read these articles because you will see a lot of inner class code in the exam and you must be able to tell what is legal and illegal code otherwise you could be throwing away a lot of marks by not being able to spot the difference.

The articles talk about these topics and each article looks at each topic in some depth

Inner Classes
Limited Scope Inner Classes
Static Nested Classes

Here are the links

Nested Classes, Part 1 - Inner Classes
http://www.onjava.com/pub/a/onjava/excerpt/HardcoreJava_chap06/index.html
Nested Classes, Part 2 - Limited Scope Inner Classes
http://www.onjava.com/pub/a/onjava/excerpt/HardcoreJava_chap06/index1.html
Nested Classes, Part 3 - Static Nested Classes
http://www.onjava.com/pub/a/onjava/excerpt/HardcoreJava_chap06/index2.html

A link to my blog for my SCJP information

Read: Nested Classes and how they work

Topic: [Apr 27, 2006 11:16 PDT] 8 Links Previous Topic   Next Topic Topic: The Ajax Experience 2006: Ajax with pleasure!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use