• Post Reply Bookmark Topic Watch Topic
  • New Topic

access modifiers exercise  RSS feed

 
ras oscar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Newbie here, first post so please be gentle.

I am a hobby programmer. Picked up and put aside Java programming out of frustration several times now. The source of my frustration is access specifiers. I seem to constantly be fighting my own code. I realize that compartmentalization and reusability are the cornerstones of good programing habits, and therefore I refuse to make all my objects public. Is there an exercise I could do for myself, or a published resource I could consult to make access specifiers more second nature? I can quote the access types and their definitions, That's not what I'm looking for.


I am currently using Matisse to create my GUIs. Matisse seldom seems to place components in the same alignment at run time as in the design window.

1.  Can I edit the Matisse code manually to adjust the component location and make the product more appealing without breaking the ability to use Matisse?

OR

2.  Is there a better free drag and drop GUI generator available for Java?
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the CodeRanch!  We are always (okay, usually) gentle.

First question: the term you're looking for is access modifiers.  Here is a good tutorial on the subject:

https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

Second question: let me research Matisse for a second...
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...ah!  It's NetBeans' Swing GUI builder, correct?  This question would fit better in the Swing / AWT forum: https://coderanch.com/f/2/GUI, but I can give you some advice here.  Most GUI builders create lousy Java code -- that is, very difficult to maintain.  A lot of the people here feel that you should code GUIs "by hand", that is, don't use a GUI builder.  If you choose to, you could use the GUI builder to create the basic layout and then tweak the code, but this will be difficult and you will not be able to use the GUI builder again on that project.  And since it is useful to be able to code a GUI on your own, I would start there.  Here is a good tutorial:

http://docs.oracle.com/javase/tutorial/uiswing/

But you should also know that Swing is being replaced (sort of) by JavaFX.  That would be a different forum: https://coderanch.com/f/98/JavaFX. ; And a different tutorial:

https://docs.oracle.com/javase/8/javafx/get-started-tutorial/jfx-overview.htm

JavaFX has a GUI builder called SceneBuilder.  If doesn't create code, but instead FXML files which can be pulled into your JavaFX program.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:. . . .  A lot of the people here feel that you should code GUIs "by hand", . . . .
I would agree, but when you are experienced enough to lay code out nicely by hand then try Matisse or similar. If you aren't happy with the layout, you will then know how to tear the code apart, though it will be hard work. If you are happy with the layout, there it is.

And, again welcome to the Ranch
 
Pete Letkeman
Ranch Foreman
Posts: 900
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a something quick to add to what has already been posted.

You could, using a free editor like Notepad++, create a few rather small (maybe 10 to 20 lines of code) Java files with different classes and access modifiers in them. At which point you could see what works and what doesn't work and how they work together. When doing something like this you are not using any frameworks or drag and drop editors as you are getting doing to bare bones of Java.

Access modifiers are one of the things which are drilled into everyone who wishes to take the OCA Java 1Z0-808 exam and it can also be one of the most misunderstood, especially default package access vs protected.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Protected access is far more complicated than default.
 
ras oscar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your responses. You've given me some things to ponder.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!