lang, util, io, text (optional) packages

N

NickName

Hi,

Following an advice on getting started with the very foundametal
elements of java, would one one write some simple and yet elegant code
sample using some core methods from java.lang, java.util and java.io
(optional) and java.text (optional) packages? And if this little thing
is fun for you, I'd appreciate it.

TIA.
 
O

Oliver Wong

NickName said:
Hi,

Following an advice on getting started with the very foundametal
elements of java, would one one write some simple and yet elegant code
sample using some core methods from java.lang, java.util and java.io
(optional) and java.text (optional) packages? And if this little thing
is fun for you, I'd appreciate it.

You're asking someone to post source code using classes from the above
packages?

- Oliver
 
N

NickName

Oliver said:
You're asking someone to post source code using classes from the above
packages?

- Oliver

Yes, exactly, sorry, I hesitated a second on "using core methods", it
should be "using core classes".
 
N

NickName

Oliver said:

The references are great, thanks, however, it would be more
fun/interesting when some java guru writes some little code that seems
to solve a particular problem or even several problems at one shot,
that's the reason why I did not google for it (notice my post entitled
"alias"? the results of which is quite fruitful and fun).
 
A

Andrew Thompson

NickName wrote:
....
...that's the reason why I did not google for it (notice my post entitled
"alias"? the results of which is quite fruitful and fun).

The title was so stupid and boring I did not bother
to read the thread content. This title was less stupid,
it got me curious enough to read the post and determine
if you deserved further attention..

Andrew T.
 
N

NickName

Addition to my OP. Use one sample code to cover three packages of
java.lang (implicit), java.util and java.io. And make it fun, are you
able to?

TIA.

Andrew said:
NickName wrote:
...

The title was so stupid and boring I did not bother
to read the thread content. This title was less stupid,
it got me curious enough to read the post and determine
if you deserved further attention..

Andrew T.

Ok, you have a point. But you did not address the problem in question,
so, in that sense, useless.
 
O

Oliver Wong

NickName said:
Addition to my OP. Use one sample code to cover three packages of
java.lang (implicit), java.util and java.io. And make it fun, are you
able to?

TIA.

Because of the strange way human psychology works, when you make it
sound like you're "tricking us" into helping you (e.g. by masquerading the
request for help as a challenge or contest), we're less likely to help you,
despite the fact that had you just asked straightforwardly, we would have
been willing to help you for free. Crazy, isn't it? I'll never understand
the human mind...

Good luck with your challenge, though.

- Oliver
 
M

Mike Schilling

NickName said:
Hi,

Following an advice on getting started with the very foundametal
elements of java, would one one write some simple and yet elegant code
sample using some core methods from java.lang, java.util and java.io
(optional) and java.text (optional) packages?

Sure; what kind of hourly rate were you thinking of paying?
 
L

Lew

Oliver said:
Because of the strange way human psychology works, when you make it
sound like you're "tricking us" into helping you (e.g. by masquerading the
request for help as a challenge or contest), we're less likely to help you,
despite the fact that had you just asked straightforwardly, we would have
been willing to help you for free. Crazy, isn't it? I'll never understand
the human mind...

Good luck with your challenge, though.

- Oliver

/** This is Fun.
*/
public class Fun
{
/** Main method.
* @param args <code>java.lang.String []</code> arguments.
*/
public static void main( String [] args )
{
java.util.Map<String, String> map =
new java.util.HashMap<String, String> ();
map.put( "", "" );
System.out.println( java.text.DateFormat.getDateInstance()
.format(new Date()) +": "+ map );
}
}

- Lew
 
G

Greg R. Broderick

Subject: Re: lang, util, io, text (optional) packages
From: "NickName" <[email protected]>
Newsgroups: comp.lang.java.programmer


Oliver said:

The references are great, thanks, however, it would be more
fun/interesting when some java guru writes some little code that seems
to solve a particular problem or even several problems at one shot,

The ONLY way for YOU to learn how to program in Java using the classes in
these various classes is for YOU to write programs in Java that uses the
classes in these various classes.

Cheers
GRB

--
---------------------------------------------------------------------
Greg R. Broderick (e-mail address removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 
G

Greg R. Broderick

Addition to my OP. Use one sample code to cover three packages of
java.lang (implicit), java.util and java.io. And make it fun, are you
able to?

No, we will not do your homework assignment for you.

--
---------------------------------------------------------------------
Greg R. Broderick (e-mail address removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 
N

NickName

Lew said:
[...]

/** This is Fun.
*/
public class Fun
{
/** Main method.
* @param args <code>java.lang.String []</code> arguments.
*/
public static void main( String [] args )
{
java.util.Map<String, String> map =
new java.util.HashMap<String, String> ();
map.put( "", "" );
System.out.println( java.text.DateFormat.getDateInstance()
.format(new Date()) +": "+ map );
}
}

- Lew

OK, this is kind of interesting. It looks like with parameters of
coordinates of x and y,
it would generate a simple map with today's date, yes?

Here's the code with IDE, JBuider 2005:
----------------------------------------------------------
package fun;

import java.util.*;
import java.text.*;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/

/* Generate a simple map.
*/

public class AboutMap {
/** Main method.
* @param args <code>java.lang.String []</code> arguments.
*/
public static void AboutMap( String [] args )
{
Map<String, String> map =
new HashMap<String, String> ();
map.put( "", "" );
// question, the put method is putting nothing there? How come?

System.out.println( java.text.DateFormat.getDateInstance()
.format(new Date()) +": "+ map );
}
}
------------------------------------------------------

Err msg:
java.lang.NoSuchMethodError: main

FYI, I'm using jre1.5 as its compiler. I explicitly added
import java.lang.String;
to no avail.

What's wrong?

Thanks.
 
M

Mike Schilling

package fun;

import java.util.*;
import java.text.*;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/

/* Generate a simple map.
*/

public class AboutMap {
/** Main method.
* @param args <code>java.lang.String []</code> arguments.
*/
public static void AboutMap( String [] args )
{
Map<String, String> map =
new HashMap<String, String> ();
map.put( "", "" );
// question, the put method is putting nothing there? How come?

System.out.println( java.text.DateFormat.getDateInstance()
.format(new Date()) +": "+ map );
}
}
------------------------------------------------------

Err msg:
java.lang.NoSuchMethodError: main

FYI, I'm using jre1.5 as its compiler. I explicitly added
import java.lang.String;
to no avail.

What's wrong?


Try renaming the method called "AboutMap" to "main"..
 
N

NickName

Mike said:
OP [...]

Try renaming the method called "AboutMap" to "main"..
Excellent, thank you. So, it seems that one of the rules is that any
java program must have one class named "main" with source file name of
main.java. Yes?

New err msg:
Hit uncaught exception java.lang.ClassNotFoundException

I thought the program would prompt a user for two parameters of
coordinates of x and y.

Also, JBuilder 2005 loaded URLClassLoader file when I ran the program
in debug mode. What's exactly going on?

Many thanks.
 
M

Mike Schilling

NickName said:
Mike said:
OP [...]

Try renaming the method called "AboutMap" to "main"..
Excellent, thank you. So, it seems that one of the rules is that any
java program must have one class named "main" with source file name of
main.java. Yes?

No, a *method* named main, not a *class* named main. E.g.

public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello, world");
}
}

Really, you should read an introductory book about Java to learn this sort
of terminology.
 
N

NickName

Mike said:
[...]

No, a *method* named main, not a *class* named main. E.g.

public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello, world");
}
}

Got it. Compiled and it runs. Many thanks. Now, a related question,
I attempted to use
the coordinates of 38°53'50"N 77°0'22"W for Union Station (DC) and
since the program does not prompt me for param input, I manually edited
the source code for the map.put method to
read as
map.put( "38°53'50\"N", "77°0'22\"W" );
// thought one backslash character is to escape special character like
quote

The code runs just fine. The debug console prints the following:
Dec 27, 2006: {38°53'50"N=77°0'22"W}

However, that seems meaningless unless I did not use it correctly. I
was expecting some sort of map albeit simple.
Really, you should read an introductory book about Java to learn this sort
of terminology.

Yes, will do. Thanks.
 
O

Oliver Wong

NickName said:
Mike said:
[...]

No, a *method* named main, not a *class* named main. E.g.

public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello, world");
}
}

Got it. Compiled and it runs. Many thanks. Now, a related question,
I attempted to use
the coordinates of 38°53'50"N 77°0'22"W for Union Station (DC) and
since the program does not prompt me for param input, I manually edited
the source code for the map.put method to
read as
map.put( "38°53'50\"N", "77°0'22\"W" );
// thought one backslash character is to escape special character like
quote

The code runs just fine. The debug console prints the following:
Dec 27, 2006: {38°53'50"N=77°0'22"W}

However, that seems meaningless unless I did not use it correctly. I
was expecting some sort of map albeit simple.

You DO have a simple map. More specifically, you have a string
representation of a map which has a single point as it's domain
("38°53'50"N") and a single point as it's range ("77°0'22"W"). Perhaps the
confusion arises because you were expecting some sort of geographical map?
"Map" here is in the mathematical sense:

http://en.wikipedia.org/wiki/Map_(mathematics)
http://www.purplemath.com/modules/fcns2.htm

- Oliver
 
N

NickName

Oliver said:
NickName said:
[...]
Got it. Compiled and it runs. Many thanks. Now, a related question,
I attempted to use
the coordinates of 38°53'50"N 77°0'22"W for Union Station (DC) and
since the program does not prompt me for param input, I manually edited
the source code for the map.put method to
read as
map.put( "38°53'50\"N", "77°0'22\"W" );
// thought one backslash character is to escape special character like
quote

The code runs just fine. The debug console prints the following:
Dec 27, 2006: {38°53'50"N=77°0'22"W}

However, that seems meaningless unless I did not use it correctly. I
was expecting some sort of map albeit simple.

You DO have a simple map. More specifically, you have a string
representation of a map which has a single point as it's domain
("38°53'50"N") and a single point as it's range ("77°0'22"W"). Perhaps the
confusion arises because you were expecting some sort of geographical map?
"Map" here is in the mathematical sense:

http://en.wikipedia.org/wiki/Map_(mathematics)
http://www.purplemath.com/modules/fcns2.htm

- Oliver

But this is oxymoronic. First of all, 38°53'50"N=77°0'22"W is
plainly wrong,
38°53'50"N <> 77°0'22"W,
one of them is longtitude and the other is latitude and the print out
is meaningless as far as I'm concerned. But if you're saying using
them for further calculation or processing (in math term) then that
would make sense. It's kind of an interesting start for Lew to post
it, however, it needs a step further for any value.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top