aspose file tools*
The moose likes Beginning Java and the fly likes Learning Project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Learning Project" Watch "Learning Project" New topic
Author

Learning Project

Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
Hello all,

I'm trying to learn Java through the Java Tutorials but I don't have anyone to discuss my code with. I'm hoping you guys could help me out. My plan is to create random programs (using the topics I'm currently working on) and then paste the code here, so that you could suggest improvements in the code (or anything else) or just leave a comment.

Thank you all in advance.

- - - - -

My first program converts degrees to radians or radians to degrees. Radians are often expressed as fractions of pi (ex. 90° = pi/2) but this is not the case here, as the program is fully computational. You are welcome to leave a comment. Also, the design is not my main concern, so please bear with me.

Here's the code:



Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Nice little utility, and very nice for your "first java program"

I would have named the class and inner class to be a bit more descriptive and I also like to initialize private non-static variables in the constructor, but those are my preferences. Again, nice!!

SCJA
~Currently preparing for SCJP6
Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
Thank you for your comment and your tips, Brian. To be honest, I've been working with Java the last month. In that time, I have managed to go through Farrell's Java Programming which gave me a decent insight, but there is still an enormous amount of learning to do in order to become half-decent Java programmer. (By the way, this is definitely not my "first Java program", I just titled it that way )

Thanks again for the feedback.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
What was the purpose of the example? To practise coding JFrames, or implement actionListeners, or write inner classes? Or all of the above?
Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
Fred Hamilton wrote:What was the purpose of the example? To practise coding JFrames, or implement actionListeners, or write inner classes? Or all of the above?


The main purpose was testing out nested classes since this is the topic I have currently finished. The rest is just to make things a bit more interesting.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Ted Scofield wrote:
Fred Hamilton wrote:What was the purpose of the example? To practise coding JFrames, or implement actionListeners, or write inner classes? Or all of the above?


The main purpose was testing out nested classes since this is the topic I have currently finished. The rest is just to make things a bit more interesting.


Ok, well it is not clear to me why you would specify a nested class as public. I'm not saying there isn't a reason, I just don't see it, cause to me the benefit of a nested class is more for readability and organization, when said nested class is only called from the class it is nested in, then you wouldn't need the public modifier.
Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
Fred Hamilton wrote:
Ok, well it is not clear to me why you would specify a nested class as public. I'm not saying there isn't a reason, I just don't see it, cause to me the benefit of a nested class is more for readability and organization, when said nested class is only called from the class it is nested in, then you wouldn't need the public modifier.


You are correct, there is no reason why InnerConverter is public. It should be private. Thanks for the heads-up.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Ted, how do you find the Sun Java Tutorials. I often found the examples rather difficult. For example you are looking for something really basic about JFrames, and you find the example is buried in some advanced coding technique which may constitute good programming practise, but obscures that small piece of information you want to learn.
Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
I believe it's a little to soon for me to be able to make a constructive critique about the Java Tutorials. I'm currently working on inheritance and for now, the only thing that confused me a little was casting interfaces. Other than that, I found the Tutorials pretty straightforward. (which doesn't mean I wont get stuck on some further topics). I'll let you know when I finish them.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
I have always found the tutorials easy to understand, but they put too much "real code" in the main method.

This makes the code easier to read, but it means readers don't see object creation or methods invoked on objects.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Campbell Ritchie wrote:I have always found the tutorials easy to understand, but they put too much "real code" in the main method.

This makes the code easier to read, but it means readers don't see object creation or methods invoked on objects.


The tutorials are excellent in certain ways, but in many cases rather advanced and thus not a great beginners intro to java or any part thereof, often I've had to look elsewhere for clarification, but as my knowledge has grown, they have become easier to understand.

Different strokes for different folks I guess.
Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
Fred Hamilton wrote:
The tutorials are excellent in certain ways, but in many cases rather advanced and thus not a great beginners intro to java or any part thereof, often I've had to look elsewhere for clarification, but as my knowledge has grown, they have become easier to understand.

Different strokes for different folks I guess.


Yeah, this pretty much sums it up
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
Fred Hamilton wrote:Different strokes for different folks I guess.
In this country we usually say "horses for courses" and the same applies to books. Somebody will like book "A" and somebody else will hate it but like book "B".
Nishant Arora
Greenhorn

Joined: Apr 21, 2009
Posts: 16
I think
It would have been better if you have handled the exception for empty text box or number format exception
Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
Nishant Arora wrote:I think
It would have been better if you have handled the exception for empty text box or number format exception


I agree. I was too lazy to do that. Thanks for pointing that out.
Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
Hi, me again.

The next program computes the determinant of an n x n matrix using Laplace expansion on the first row. It uses recursive calls to compute minors. The code itself is probably really bad, but that's where you guys step in and suggest improvements.

This one does not have a GUI, you have to manually insert the matrix as an multidimensional array (int[][]). If you have any suggestions on how the GUI should look like, let me know.

Here's the code:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
I shall go into pedantic mode, and say there is no such thing as a multi-dimensional array in Java, only arrays of arrays. That actually allows more flexibility because the member arrays can be different sizes.
[End pedantic mode]

Please don't ask questions unrelated to the original thread; I think your new application merits a thread of its own, so I suggest you copy-and-paste it.
Ted Scofield
Greenhorn

Joined: Apr 04, 2009
Posts: 26
Campbell Ritchie wrote:I shall go into pedantic mode, and say there is no such thing as a multi-dimensional array in Java, only arrays of arrays. That actually allows more flexibility because the member arrays can be different sizes.
[End pedantic mode]

Please don't ask questions unrelated to the original thread; I think your new application merits a thread of its own, so I suggest you copy-and-paste it.


Thanks for clearing that. I used the term which is also used in Farrell's Java Programming, where multidimensional array is defined as an array containing two or more dimensions. Also, I like pedantic mode
Wouldn't it be easier if I stick to this thread rather than opening a new one for every new code I paste?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
It might be easier to add to an old thread, but people who read the contents page will not realise there is new material on the thread.
 
jQuery in Action, 2nd edition
 
subject: Learning Project