[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
Java -- FAQ  XML
Forum Index » New to Java
Author Message
destin

Newbie
[Avatar]
Joined: 01/07/2006 19:13:04
Messages: 224
Offline

1) How can I convert a primitive data type or Object into a String?
The String class provides a static method for this:

Alternatively, you can use the toString() method that every class inherits from the Object class. (String.valueOf(Object) actually calls the toString method).


2) How can I convert a String into a primitive data type or Object?
For a byte:

For a short:

For an int:

For a long:

For a float:

For a double:

For a boolean:

For an Object:


3) How can I get the ASCII value of a char?


4) I have two Strings, str1 and str2, both "abc", yet str1 == str2
is false. Why?

This is a common question in Java. == will only compare state of
primitive data types; with objects it checks if they have the same place in memory (ie. they are the exact same object).

The following code:

prints "str1 != str2".

You must use the equals(Object) method to compare Strings.

This prints "str1.equals(str2)".

5) I am comparing two Objects with the equals(Object) method.
In the String class this checks state, but now it's checking memory.
Why?

The equals(Object) method is inherited by the Object class. This
will check memory unless you override it to check state (which is
what the String class does).

eg:

At this point, comparing these two instances of MyClass with
the equals(Object) method would not return true.

After overriding the equals(Object) method, they will:


6) How can I force garbage collection?
You can't. You can suggest to perform garbage collection.
You cannot force it.

Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects. -- Java API

This message was edited 12 times. Last update was at 06/13/2007 05:06:51

[Email]
mark40

Newbie

Joined: 10/28/2011 01:57:15
Messages: 1
Offline

Thank you

Good post

I like your post.
 
Forum Index » New to Java
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2011 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle