Java is the future !: August 2010

Thursday, August 26, 2010

Java Programming Tutorial - 41 - Building Objects for Constructors

Java Programming Tutorial - 40 - Set and Get Methods

Java Programming Tutorial - 39 - Multiple Constructors

What is "this" in Java

The "this" keyword can be used inside methods and constructors.

It returns the reference to the current object.

For example:


Here the setValue tries to set the value of the argument to the class variable n. Since the name n is already used in the method's parameter name, so n=n is absurd. The workaround is to use the “this” keyword to refer to the object. That's why we used “this.n=n”.

Another example of using “this” is when you need to pass your current object to another method.

Example:

In the above example, B has a member variable n. The method setMe calls another class method and passing itself as a object.

Java Programming Tutorial - 38 - Public, Private and this

Java Programming Tutorial - 37 - Display Regular time

Java Programming Tutorial - 36 - Time Class

Java Programming Tutorial - 35 - Variable Length Arguments

Java Programming Tutorial - 34 - Table for Multi Arrays

Java Programming Tutorial - 33 - Multidimensional Arrays

Java Programming Tutorial - 32 - Arrays in Methods

Java Programming Tutorial - 31 - Enhanced for Loop

Java Programming Tutorial - 30 - Array Elements as Counters

Java Programming Tutorial - 29 - Summing Elements of Arrays

Wednesday, August 25, 2010

Java Programming Tutorial - 28 - Creating an Array Table

Java Programming Tutorial - 27 - Introduction to Arrays

Java Programming Tutorial - 26 - Random Number Generator

Java Programming Tutorial - 25 - Math Class Methods

Java Programming Tutorial - 24 - do while Loops

Java Programming Tutorial - 23 - Compound Interest Program

Java Programming Tutorial - 22 - for Loops

Java Programming Tutorial - 21 - Simple Averaging Program

Java Programming Tutorial - 20 - Conditional Operators

Java Programming Tutorial - 19 - else if Statement

Tuesday, August 24, 2010

Java Programming Tutorial - 18 - Nested if Statements

Java Programming Tutorial - 17 - Constructors

Java Programming Tutorial - 16 - Many Methods and Instances

Java Programming Tutorial - 15 - Use Methods with Parameters

Java Programming Tutorial - 14 - Using Multiple Classes

Java Programming Tutorial - 13 - While Loop

Java Programming Tutorial - 12 - Switch Statement

Java Programming Tutorial - 11 - Logical Operators

Java Programming Tutorial - 10 - If Statement

Java Programming Tutorial - 9 - Increment Operators



Source code:

Java Programming Tutorial - 8 - Math Operators



Source code:

Java Programming Tutorial - 7 - Building a Basic Calculator



Source code:

Java Programming Tutorial - 5 - Variables



Source code:

Java Programming Tutorial - 6 - Getting User Input




 Source code:

Tuesday, August 17, 2010

The History of Java Technology




Since 1995, Java has changed our world . . . and our expectations..

Today, with technology such a part of our daily lives, we take it for granted that we can be connected and access applications and content anywhere, anytime. Because of Java, we expect digital devices to be smarter, more functional, and way more entertaining.

In the early 90s, extending the power of network computing to the activities of everyday life was a radical vision. In 1991, a small group of Sun engineers called the "Green Team" believed that the next wave in computing was the union of digital consumer devices and computers. Led by James Gosling, the team worked around the clock and created the programming language that would revolutionize our world – Java.

The Green Team demonstrated their new language with an interactive, handheld home-entertainment controller that was originally targeted at the digital cable television industry. Unfortunately, the concept was much too advanced for the them at the time. But it was just right for the Internet, which was just starting to take off. In 1995, the team announced that the Netscape Navigator Internet browser would incorporate Java technology.

Today, Java not only permeates the Internet, but also is the invisible force behind many of the applications and devices that power our day-to-day lives. From mobile phones to handheld devices, games and navigation systems to e-business solutions, Java is everywhere!

Saturday, August 14, 2010

Chapter 2: Positioning text version pt.1

Just as we did with the previous program it displays as label. It is identical to the previous one with a single exception that the TextOne object is displayed instead of the Label object.

What is a TextOne object?

It's not part of the standard library like the label was. This is a class of our own. A Canvas object is a displayable component just like a label except the Canvas object doesn't do anything but provide a blank window and permission to draw graphics of our own. So the TextOne class extends the Canvas class and adds a method to draw a single line of text.

The paint method is called by java whenever TextOne object needs to be displayed. Whenever the TextOne window first appears the paint method is called to draw the content of the window. (Paint method is called again if any changes happens like size change etc to redraw the window)

Graphics object is passed to paint method.

Setsize method specifies the original size of the window.




Chapter 2: Font anatomy

Chapter 1: Adding exits to Howdy Window

In the previous program the window that we made was not closing, to overcome that problem we have to add some new methods to our class. Here's the source code.




Chapter 1: The source code of a Howdy Window

Tuesday, August 10, 2010

What’s inside a reference varible in Java?

We know that the object reference variable holds bits that represent a way to access an object.
It doesn't hold the object itself, but it holds something like a pointer or an address.
I was going through the Head-First Java (2nd edition) book and in the book it is written that
"In Java we don't really know what is inside a reference variable. We do know that whatever it is, it represents one and only one object. And the JVM knows how to use the reference to get to the object." - Chapter 3 (page 54)
I want to ask:
  • Do an object reference variable holds Pointer, Address or what?
  • How does JVM interpret that?

Answers

1. It's entirely up to the JVM to determine what goes inside a reference.
In the simplest case it would just be a pointer (i.e. an address). In more sophisticated cases, the VM may use different representations depending on the situation - for example, you may want to read the paper on "Compressed oops in HotSpot" to see how the HotSpot VM can avoid doubling the size of references in some (but not all) places when running as a 64-bit VM.
The important thing is that you should neither know nor care. As far as you're concerned as a programmer, it's just an opaque set of bits - its only purpose is to let you get to the object in question (or identify a null reference).    Jon Skeet

2. That's up to the JVM. A Java reference isn't guaranteed to have any semantics besides that you can access an object through it. Sunacle might do that differently to IBM as well.
In practice it may often be a pointer of some sort, though maybe not directly to the object since that can be moved by the GC.    Johannes Rössel

3. It's entirely JVM specific. It may be an address, a pointer, or something more complicated. You don't have, or need, any harder guarantees than the fact that you can get an Object using the reference.    GaryF

4. It's up to the JVM to decide exactly how the reference is implemented.
Having said that, any "sane" implementation would probably use either a direct pointer or some form of compressed pointer for performance reasons. I believe this applies to all current production JVMs.

5. Have a look at an open implementation such as OpenJDK if you're that curious :)    Samuel_xL

6. A legitimate question would be "how are references implemented in 's JVM" though.    Samuel_xL

7. @Samuel - it depends on how you define "legitimate". Unless you're looking to modify the JVM itself there's no practical use for this information. Curiousity is fine, but these kind of questions always make me think that someone is clinging to a C mindset.    Andrzej Doyle


Monday, August 9, 2010

GuessGame Program

Summary: 

The guessing game involves a 'game' object and three 'player' objects. The game generates a random number between 0 and 9 and the three player objects try to guess it.

Classes:

GuessGame.class   Player.class   GameLauncher.class

Logic:

1) The GameLauncher class is where the application starts; it has the main() method.
2) In the main() method, a GuessGame object is created, and its startGame() method is called.
3) The GuessGame object's startGame() method is where the entire game plays out. It creates three players, then "thinks" of a random number (the target for the players to guess). It then asks each player to guess, checks the result, and either prints out information about the winning player(s) or asks them to guess again.

You can download the source code of the program from the link given below.

Friday, August 6, 2010

Finally got my first book of Java (Head First Java)


I ordered the Head First Java book (2nd edition) on 2 august and today I got a call from the Aramex courier company at 4 PM. One person told me that he came to deliver the book but he didn't find the home so he tried to call on my cellphone but my mobile was switched off. He asked me if I can come to their office and receive the package. I agreed and searched the company's address on internet just to see where the office is located I took help of the Google map. It was showing that the office is in "Chandpole" near "Janana hospital". It's about 6 km far from my home. I took my bike and went there. There people told me that there isn't any office of that company. Then I called back to that person and he told me that you went to a wrong place, He said "Our office is in Rambagh". It's about 4 km far from my home. I went back to Rambagh and then searched there. I saw a big board of the company from distance, I parked my bike and went there. I got my book there. I scolded the guys out there for wrong tagging there address in Google map. They said that are sorry and they will make it ok as soon as possible. Then I returned to home and unpacked the package. The book looks nice. I mean it's like GUI in printed pages. I checked about the authors "Kathy Sierra" and "Bert Bates" and had a look on the Table of Contents and How to use the book. I will start the first lesson "Breaking the Surface" from tomorrow. So before signing off I'll let you guys know the reviews of the book.

Here they are.. 

...The only way to decide the worth of a tutorial is to decide how well it teaches. Head First Java excels at teaching. ---slashdot.org

...It's definitely time to dive in--Head First. --Scott McNealy, Sun Microsystems, Chairman, President, and CEO

Head First Java transforms the printed page into the closest thing to a GUI you've ever seen. In a wry, hip manner, the authors make learning Java an engaging, 'what're they gonna do next?' experience. --Warren Keuffel, Software Development Magazine

It's fast, irreverent, fun, and engaging. Be careful you might actually learn something! --Ken Arnold, coauthor (with James Gosling, creator of Java), The Java Programming Language

Thursday, August 5, 2010

Eclipse and Java for total beginners

An introduction to using the Eclipse development platform to build Java applications. Includes installing Eclipse and the supporting downloads required to get up and running with Eclipse.

PART 1:

                        

PART 2: