Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How do I use real Java in Cocoa applications?

How do I use real Java in Cocoa applications?
Thread Tools
Forum Regular
Join Date: Sep 2000
Location: Ronneby, Sweden
Status: Offline
Reply With Quote
Oct 26, 2000, 10:05 AM
 
Is it possible to use pure java in Cocoa applications? For example I would like to use java's string class but I can't. The NSString seams to be used instead.

String s = new String(10);

Is a perfectly valid java statement but when I compile it the compiler says it can't convert int to char[] so it seams it's trying to use NSString instead of java.lang.String. It doesn't matter if I write

java.lang.String s = new java.lang.String(10);

or if I import java.lang.*; or both it still complains about the int to char convertion. Is there any other place than apple's developer pages where I can find info on the Cocoa framework? I don't really them and most of the pages seams to be under construction.

Thanks,

/Gabbe
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Oct 26, 2000, 12:09 PM
 
Originally posted by gabrielf:

String s = new String(10);

Is a perfectly valid java statement Thanks,

/Gabbe

I don't know WHAT version of the JDK you are using, but in 1.3 there is no constructor in java.lang.String matches <init>(int).
Therefore you are wrong!

I am not sure what you are trying to do, but I think
String s = new String("10");
might be what you are looking for.
Read the Javadoc for java.lang.String, and you will see:

Constructor Summary
String()
Initializes a newly created String object so that it represents an empty character sequence.

String(byte[] bytes)
Construct a new String by converting the specified array of bytes using the platform's default character encoding.

String(byte[] ascii, int hibyte)
Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a character-encoding name or that use the platform's default encoding.
String(byte[] bytes, int offset, int length)

Construct a new String by converting the specified subarray of bytes using the platform's default character encoding.

String(byte[] ascii, int hibyte, int offset, int count)
Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a character-encoding name or that use the platform's default encoding.

String(byte[] bytes, int offset, int length, String enc)
Construct a new String by converting the specified subarray of bytes using the specified character encoding.

String(byte[] bytes, String enc)
Construct a new String by converting the specified array of bytes using the specified character encoding.

String(char[] value)
Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.

String(char[] value, int offset, int count)
Allocates a new String that contains characters from a subarray of the character array argument.

String(String value)
Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.
String(StringBuffer buffer)
Allocates a new string that contains the sequence of characters currently contained in the string buffer argument.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Forum Regular
Join Date: Sep 2000
Location: Ronneby, Sweden
Status: Offline
Reply With Quote
Oct 26, 2000, 02:53 PM
 
Hahaha, how embarrassing! I was so sure you could do that so I didn't check the API docs I thought it was pretty logical since you could write things like myString = "Hello" + 5; you just have to be able to write just new String(int). Ah well, I'll be checking and double checking the docs before I ask something again

/Gabbe
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:51 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2