Is Array in java are Object?
is Array in java are Object?
int a[]=new int[10];
new will allocate memory. but int is a type not an Class ?
please help me.......
An array in Java is an object. Array elements may be primitives or references, depending on the way the array is declared.
Similar Messages
-
Passing Array of java objects to and from oracle database-Complete Example
Hi all ,
I am posting a working example of Passing Array of java objects to and from oracle database . I have struggled a lot to get it working and since finally its working , postinmg it here so that it coudl be helpful to the rest of the folks.
First thinsg first
i) Create a Java Value Object which you want to pass .
create or replace and compile java source named Person as
import java.sql.*;
import java.io.*;
public class Person implements SQLData
private String sql_type = "PERSON_T";
public int person_id;
public String person_name;
public Person () {}
public String getSQLTypeName() throws SQLException { return sql_type; }
public void readSQL(SQLInput stream, String typeName) throws SQLException
sql_type = typeName;
person_id = stream.readInt();
person_name = stream.readString();
public void writeSQL(SQLOutput stream) throws SQLException
stream.writeInt (person_id);
stream.writeString (person_name);
ii) Once you created a Java class compile this class in sql plus. Just Copy paste and run it in SQL .
you should see a message called "Java created."
iii) Now create your object Types
CREATE TYPE person_t AS OBJECT
EXTERNAL NAME 'Person' LANGUAGE JAVA
USING SQLData (
person_id NUMBER(9) EXTERNAL NAME 'person_id',
person_name VARCHAR2(30) EXTERNAL NAME 'person_name'
iv) Now create a table of Objects
CREATE TYPE person_tab IS TABLE OF person_t;
v) Now create your procedure . Ensure that you create dummy table called "person_test" for loggiing values.
create or replace
procedure give_me_an_array( p_array in person_tab,p_arrayout out person_tab)
as
l_person_id Number;
l_person_name Varchar2(200);
l_person person_t;
l_p_arrayout person_tab;
errm Varchar2(2000);
begin
l_p_arrayout := person_tab();
for i in 1 .. p_array.count
loop
l_p_arrayout.extend;
insert into person_test values(p_array(i).person_id, 'in Record '||p_array(i).person_name);
l_person_id := p_array(i).person_id;
l_person_name := p_array(i).person_name;
l_person := person_t(null,null);
l_person.person_id := l_person_id + 5;
l_person.person_name := 'Out Record ' ||l_person_name ;
l_p_arrayout(i) := l_person;
end loop;
p_arrayout := l_p_arrayout;
l_person_id := p_arrayout.count;
for i in 1 .. p_arrayout.count
loop
insert into person_test values(l_person_id, p_arrayout(i).person_name);
end loop;
commit;
EXCEPTION WHEN OTHERS THEN
errm := SQLERRM;
insert into person_test values(-1, errm);
commit;
end;
vi) Now finally create your java class which will invoke the pl/sql procedure and get the updated value array and then display it on your screen>Alternatively you can also check the "person_test" tbale
import java.util.Date;
import java.io.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class ArrayDemo
public static void passArray() throws SQLException
Connection conn = getConnection();
ArrayDemo a = new ArrayDemo();
Person pn1 = new Person();
pn1.person_id = 1;
pn1.person_name = "SunilKumar";
Person pn2 = new Person();
pn2.person_id = 2;
pn2.person_name = "Superb";
Person pn3 = new Person();
pn3.person_id = 31;
pn3.person_name = "Outstanding";
Person[] P_arr = {pn1, pn2, pn3};
Person[] P_arr_out = new Person[3];
ArrayDescriptor descriptor =
ArrayDescriptor.createDescriptor( "PERSON_TAB", conn );
ARRAY array_to_pass =
new ARRAY( descriptor, conn, P_arr);
OracleCallableStatement ps =
(OracleCallableStatement )conn.prepareCall
( "begin give_me_an_array(?,?); end;" );
ps.setARRAY( 1, array_to_pass );
ps.registerOutParameter( 2, OracleTypes.ARRAY,"PERSON_TAB" );
ps.execute();
oracle.sql.ARRAY returnArray = (oracle.sql.ARRAY)ps.getArray(2);
Object[] personDetails = (Object[]) returnArray.getArray();
Person person_record = new Person();
for (int i = 0; i < personDetails.length; i++) {
person_record = (Person)personDetails;
System.out.println( "row " + i + " = '" + person_record.person_name +"'" );
public static void main (String args[]){
try
ArrayDemo tfc = new ArrayDemo();
tfc.passArray();
catch(Exception e) {
e.printStackTrace();
public static Connection getConnection() {
try
Class.forName ("oracle.jdbc.OracleDriver");
return DriverManager.getConnection("jdbc:oracle:thin:@<<HostNanem>>:1523:VIS",
"username", "password");
catch(Exception SQLe) {
System.out.println("IN EXCEPTION BLOCK ");
return null;
and thats it. you are done.
Hope it atleast helps people to get started. Comments are appreciated. I can be reached at ([email protected]) or [email protected]
Thanks
Sunil.sHi Sunil,
I've a similar situation where I'm trying to insert Java objects in db using bulk insert. My issue is with performance for which I've created a new thread.
http://forum.java.sun.com/thread.jspa?threadID=5270260&tstart=30
I ran into your code and looked into it. You've used the Person object array and directly passing it to the oracle.sql.ARRAY constructor. Just curios if this works, cos my understanding is that you need to create a oracle.sql.STRUCT out of ur java object collection and pass it to the ARRAY constructor. I tried ur way but got this runtime exception.
java.sql.SQLException: Fail to convert to internal representation: JavaBulkInsertNew$Option@10bbf9e
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:239)
at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:274)
at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:115)
at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:1314)
at oracle.sql.ARRAY.<init>(ARRAY.java:152)
at JavaBulkInsertNew.main(JavaBulkInsertNew.java:76)
Here's a code snippet I used :
Object optionVal[] = {optionArr[0]}; // optionArr[0] is an Option object which has three properties
oracle.sql.ArrayDescriptor empArrayDescriptor = oracle.sql.ArrayDescriptor.createDescriptor("TT_EMP_TEST",conn);
ARRAY empArray = new ARRAY(empArrayDescriptor,conn,optionVal);If you visit my thread, u'll see that I'm using STRUCT and then pass it to the ARRAY constructor, which works well, except for the performance issue.
I'll appreciate if you can provide some information.
Regards,
Shamik -
How to pass Array of Java objects to Callable statement
Hi ,
I need to know how can I pass an array of objects to PL/SQL stored procedure using callable statement.
So I am having and array list of some object say xyz which has two attributes string and double type.
Now I need to pass this to a PL/SQL Procedure as IN parameter.
Now I have gone through some documentation for the same and found that we can use ArrayDescriptor tp create array (java.sql.ARRAY).
And we will use a record type from SQL to map this to our array of java objects.
So my question is how this mapping of java object's two attribute will be done to the TYPE in SQL? can we also pass this array as a package Table?
Please help
ThanksI seem to remember that that is in one of Oracle's online sample programs.
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html -
How many java String objects are created in string literal pool by executin
How many java String objects are created in string literal pool by executing following five lines of code.
String str = "Java";
str = str.concat(" Beans ");
str = str.trim();
String str1 = "abc";
String str2 = new String("abc").intern();
Kindly explain thanks in advance
Senthilvirtuoso. wrote:
jverd wrote:
In Java all instances are kept on the heap. The "String literal pool" is no exception. It doesn't hold instances. It holds references to String objects on the heap.Um, no.
The literal pool is part of the heap, and it holds String instances.
[http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#22972]
[http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html#67960]
You're referring to the JVM. That's not Java.It's part of Java.
There is nowhere in Java where it is correct to say "The string literal pool holds references, not String objects." -
Are there any problems to expect when srializing java.lang.Object?
When having code like this:
public class SomeClass implements Serializable{
private final String NULL_CONSTANT="dmmystring";
private Object result=new String(NULL_CONSTANT);
...whatever
Class java.lang.Object is not implementing the Serializable Interface. In practise, this works fine however, I would like to understand this question. Will serialization work in every case as long as result is set to a serializable type?hi,
If the object does not implement the Serilizable marker interface, then when you try to serialize the object, you will get a NotSerializableException. Also when you try to serialize a object, java will check to see if any variables contained in the object are also serializable and if so it serializes the same so in effect all attributes of the object must be either serializable or marked transient. When you mark a variable as transient, for eg
transient Vector v;
this object will not be serialized.
you might want to check out the article at
http://java.sun.com/docs/books/performance/1st_edition/html/JPIOPerformance.fm.html#11352
It contains ways to improve serialization, but it will also be useful in understanding the Serialization concepts as such...
hope this helpzz
cheerz
ynkrish -
Passing parameters to Java JT400 object
I need to pass a byte array as my input and an int as the output length for the Class ProgramCall.
My error is
parameterList[0] (null): Parameter value is not valid.
My thoughts are
I think (but I'm not completely sure) I'm having trouble because I'm passing a Coldfusion Array where a Java Array is needed to pass the arguments.
Coldfusion arrays start at index 1 and Java Arrays start at index 0.
(1) Am I correct in what I believe is causing my error?
(2) How can I convert the Coldfusion Array to a Java Array?
Here is the documentation for Java JT400 object Class ProgramCall
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/info/rzahh/javadoc/com/ibm/as400/access/ ProgramCall.html
Here is my code
<!--- I am the system object --->
<cfobject
action="create"
type="java"
class="com.ibm.as400.access.AS400"
name="mysystem">
<!--- I am the program call object --->
<cfobject
action="create"
type="java"
class="com.ibm.as400.access.ProgramCall"
name="myprogram">
<!--- I am the program parameter object --->
<cfobject
action="create"
type="java"
class="com.ibm.as400.access.ProgramParameter"
name="myparameter">
<!--- I am the as400 text object --->
<cfobject
action="create"
type="java"
class="com.ibm.as400.access.AS400Text"
name="mytext">
<!--- Initialize our system object --->
<cfset mysystem.init(AS400system,Trim(UCase(loginname)),Left(Trim(loginpass),10)) />
<!--- Execute our AS400 username validation --->
<cfset mysystem.ValidateSignon() />
<!--- Initialize our as400 text object and convert string to a byte array --->
<cfset mytext.init(5) />
<cfset nametext = mytext.toBytes("hello") />
<!--- Initalize our program parameter object --->
<cfset myparameter.init(2) />
<!--- Set input data and output data length using the Class methods of ProgramParameter --->
<cfset myparameter.setInputData(nametext) />
<cfset myparameter.setOutputDataLength(20) />
<!--- Set parameters to a Coldfusion Array --->
<cfset parameterlist = ArrayNew(1) />
<cfset parameterlist[1] = myparameter.getInputData() />
<cfset parameterlist[2] = myparameter.getOutputDataLength() />
<!--- Initalize our program object and run our program --->
<cfset myprogram.init(iseries,ProgramtoRun, parameterlist) />
<cfset myprogram.run() />reggiejackson44 wrote:
I need to pass a byte array as my input and an int as the output length for the Class ProgramCall.
My error is
parameterList[0] (null): Parameter value is not valid.
My thoughts are
I think (but I'm not completely sure) I'm having trouble because I'm passing a Coldfusion Array where a Java Array is needed to pass the arguments.
Coldfusion arrays start at index 1 and Java Arrays start at index 0.
(1) Am I correct in what I believe is causing my error?
(2) How can I convert the Coldfusion Array to a Java Array?
(1) Yes.
(2) A ColdFusion array and a Java array are 2 entirely different things. You have yourself identified one difference, the starting index. In fact, the following line of code will tell you that a ColdFusion array is essentially a Java vector.
<cfoutput>#arrayNew(1).getClass().getSuperClass().getname()#</cfoutput>
In my opinion, your question should read the other way around: how to convert a Java array into ColdFusion, not necessarily into a ColdFusion array.
Here are some tips and tricks:
http://blogs.adobe.com/cantrell/archives/2004/01/byte_arrays_and_1.html
http://www.bennadel.com/blog/1030-Building-Java-Arrays-In-ColdFusion-Using-Reflection.htm -
Passing an array from Java to Pl/SQL Procdures
I am relatively new to the Java world and I am unable to pass back an array from Java back to the calling PL/SQL procedure. I have read many of the posts that deal with this issue and in specificly have viewed Ask Tom. My main issue is trying to get the data types matched up. I am able to return varchar2, numbers, and the like, but an array of filenames is not happening. I have tried a variety of "types" but unable to accomplish the task. Please help.
I have my Java class basically defined as:
public static oracle.sql.ARRAY[] getCollection(String directory)
throws SQLException
{ // provide a directory and get a listing of files
File path = new File( directory );
String[] list = path.list();
return list;
SQL Type and PL/SQL Procedure is:
CREATE OR REPLACE TYPE PTO_FILE IS TABLE OF VARCHAR2(100);
create or replace function get_dir_collection( p_directory in varchar2 ) RETURN PTO_FILE
as language java
name 'DirCollection.getCollection( java.lang.String ) return oracle.sql.ARRAY[]';
/I know that it is not an ARRAY. It is however an "array" and I am attempting to map Java's String[][ to some "object" on the oracle side. I have looked at the link you sited and was not able to find the data mapping. I have found that mapping data types between different "languages" is some of the most difficult aspects of working with multiple languages.
Any suggestions? Thanks -
What exactly are objects?
Hi, i am new to java and i do not exactly understand the concept of OBJECTS...they are somehow relates to methods and classes. Is there a place where is can know about objects in java? Maybe someone here can help me..
Think about it this way? What is an object? Is a man, woman, pen, employee, map, napkin? All of those are objects correct?
So in Object Oriented Programming, like Java, you can create something called a class that describes these.
An object or class(in most cases), is used to describe just that, an object.
For example, take a man, he is an object, so how would you descibe a man? Maybe, name, weight, height, hair color, or however much more detailed you want to get. So you create a class that contains all that information in a way that you can reuse it for any man object that you want to create later.
Does that make more sense? -
How to set an array element in an object type of array??
Hi,
I have set attribute as follow:
Color[] colors;
Color[] colors = new Color[20];
colors[0] = "Red";
colors[1] = "blue";I can't compile this code. It said:
"Incompatible type -found java.lang.String but expected Colors
Could you tell me how to set an array elements when the array type is an object?in your case, the array shouldn't be Color[] but String[] since you re intending to put strings into it
by the way, you could also use a hashmap to map a string to a color:
HashMap<String, Color> hm = new HashMap<String, Color>();
hm.put("Red", Color.RED);
hm.put("Blue", Color.BLUE);
etc. -
Java Label object not displaying ascii chars (128-159)
I am having a problem getting ASCII characters between 128 and 159 to show up in a Label object which is inside a Panel which is in turn inside a Frame. There is other code in a different class that uses a Graphics object and drawString and Paint methods to display the same text, and that works. However, simply passing the text containing the above mentioned ascii characters like so:
lb = new Label("€‚ƒ„…†‡");
results in mostly empty boxes being displayed (there is other code that eventually displays the label in the Frame). The Euro sign comes through, as does the integral sign. Some others come through, and they are mostly modifed letters of some sort.
I've tried coding a mock up simple Frame with a few labels. I've passed in literal strings, String objects derived from hex and integer byte arrays and a String object with the Cp1252 encoding passed in. None display the characters in question. However, in the same code, I pass a title string containing these characters into the Frame's constructor, and it appears with no problems.
I just want to be able to handle all characters that may be entered into this application, and that may include these Cp1252 characters. Is there any way of using Label objects and getting these characters to display correctly?
[Windows-1252 Chart|http://upload.wikimedia.org/wikipedia/commons/e/e7/Windows-1252.svg]I am having a problem getting ASCII characters between 128 and 159 to show up in a Label object which is inside a Panel which is in turn inside a Frame. There is other code in a different class that uses a Graphics object and drawString and Paint methods to display the same text, and that works. However, simply passing the text containing the above mentioned ascii characters like so:
lb = new Label("€‚ƒ„…†‡");
results in mostly empty boxes being displayed (there is other code that eventually displays the label in the Frame). The Euro sign comes through, as does the integral sign. Some others come through, and they are mostly modifed letters of some sort.
I've tried coding a mock up simple Frame with a few labels. I've passed in literal strings, String objects derived from hex and integer byte arrays and a String object with the Cp1252 encoding passed in. None display the characters in question. However, in the same code, I pass a title string containing these characters into the Frame's constructor, and it appears with no problems.
I just want to be able to handle all characters that may be entered into this application, and that may include these Cp1252 characters. Is there any way of using Label objects and getting these characters to display correctly?
[Windows-1252 Chart|http://upload.wikimedia.org/wikipedia/commons/e/e7/Windows-1252.svg] -
Java/lang/NoClassDefFoundError: java/lang/Object
Hi Experts,
We are installing Java "1.6.0_31.We have updated the environment variables with the correct Java Path but which checking the java -version we are getting the following error.
java -version
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
hence the DAC service is not starting giving the following error.
startserver.h: startserver.h: cannot open
OS detected: SunOS
ld.so.1: java: fatal: libjli.so: open failed: No such file or directory
Killed
Following are the environment variable entries.
PATH=/opt/SUNWspro/bin:/../oracle/product/10.2.0/client_1/bin:/.../Informatica/PowerCenter8.6.1/server/bin:/usr/sfw/bin:/...../JAVA631/jdk1.6.0_31/bin/sparcv9:/.../JAVA631/jdk1.6.0_31/lib:/..../JAVA631/jdk1.6.0_31/jre/lib/sparcv9/jli:/...../JAVA631/jdk1.6.0_31/jre/lib/sparcv9:$PATH
export PATH
Need ur support.
ThanksWhere do you run shell script?
What's your Oracle's version?
What's text of your shell script?
By asking 100 questions and keeping 90 of them "unanswered" you throw yourself to the list of "blacklist users"
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com
[Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]
Edited by: Kamran Agayev A. on May 19, 2009 1:28 PM -
Sort(java.util.LinkedList java.lang.Object ) doesn't work
Why doesn't this work?
LinkedList<Object> sysPropsKeys = new LinkedList<Object>(System.getProperties().keySet());
Collections.sort(sysPropsKeys);
cannot fnd symbol
symbol : method sort(java.util.LinkedList<java.lang.Object>)
location: class java.util.CollectionsI will admit to not having Java1.5 installed on my machine. Haven't yet had the chance to play with generics, but the above DOES work in 1.4, and SHOULD work in 1.5
Maybe I'm naive but, System.getProperties() returns a Properties object right?
According to the API: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html: Each key and its corresponding value in the property list is a string.
All the keys SHOULD be strings.
AFAIK string are comparable, and shouldn't throw class cast exceptions
Thus the keys returned from getProperties SHOULD be comparable, and compatible for comparision.
Ok, I can see your point in that some hackers abuse the Properties class by putting non string keys/values into the Properties Map. In that case the code would become more like your above. I'd probably still go with a TreeMap though, rather than a sorted list of keys. Most time you want the keys, you want the values as well. So if the intention is to print out a sorted list of system properties, and their values, keeping it in a map is best.
Just my 2 cents,
evnafets -
OID and binding java serialized object
Hi there,
How are you doing? I am trying to bind a serialized java object to a name in Oracle Internet Diectory (oid) using JNDI.
it gives me an errror.
"OperationNotSupported LDAPA error 53: Unwilling to perform:
I have directory manager 2.1.1 and JNDI 1.2.1
I arrpeciate any clue and/or help
Thanks
nullHello:
Although OID supports calls from JNDI, the JNDI schema for storing JAVA serialized objects is not yet a standard part of the OID schema. This is easy to remedy. Go to javasoft.sun.com and download the JNDI schema for java serialized objects and load the attributes and objectclasses into OID from the ldif files provided at this web site. . Make sure the attributes are loaded before the objectclasses.
Once this schema is loaded this problem should go away
Use the ldapmodify command line tool to add the schema items from the ldif file.
Let me know if you need further assistance setting this up. A future version of OID will contain these schema items standard.
Thanks,
Jay
null -
Theme in WebDynpro java callable object
Hi Experts,
I have created a portal theme and deployed on the server.
Now i want to use this portal theme in my WebDynpro java callable object.
I know how to use themes in WebDynpro application, set the theme in Exit plug of component interface view.
However in WebDynpro java callable object how do i achieve this?
here should i use WebDynproCOInterfaceView to set the desired theme to the callable object ?
or should i set the theme in my Componet's interface view?
i tried in both but its not working, i can still see the default theme.
Am i missing anything here?
AshishHi Guys,
Any idea on this one?
Has anyone done this? are there any SAP Note for this?
Regards,
Ashish -
The first quthor of java.lang.Object
The biggest mystery for me in Java still exists as to who really coded the mother of all classes java.lang.Object.
Here�s what the source of it says in JavaDocs
* Class <code>Object</code> is the root of the class hierarchy.
* Every class has <code>Object</code> as a superclass. All objects,
* including arrays, implement the methods of this class.
* @author unascribed
* @version 1.61, 01/23/03
* @see java.lang.Class
* @since JDK1.0
public class Object {
�
See the annotation @author above, it says �unascribed� which means unknown. Any one who can solve this mystery for me and come up with the real author of this jni implementation class called �Object�
I mean, the first one to code Object class...Please help mecross-post
Maybe you are looking for
-
Performance: Cursor declaration versus explicit query in BEGIN/END block
Hi guys! Anyone knows if declare an explicit cursor inside a pl/sql block is faster than using a cursor declaration, and how fast it its? Which block runs faster? And how fast? ( once, twice, once and a half ? ) Block1: DECLARE CURSOR cur_test (p1 NU
-
Hi, I have got an assignment to find out reasons for deadlock error in two forms. Client doesnot have any records like error number,message what soever. Please tell me how to trobleshoot it, what are things which I should check in forms,procedures et
-
Does captivate allow for quizzing that includes selecting proper electronic medical record action
Looking to see if Captivate will allow screen recording and interactivity to have end user select proper action in a medical record
-
Photoshop CS3 Ext./Quits on "Save As" command in Leopard
IMac Leopard/3GB RAM/500GB HD: CS3 worked fine with IMac Tiger; just upgraded to Leopard and "Save As" command crashes the whole program. Message: "The application Photoshop has unexpected quit. A crash report has been generated." Then Photoshop goes
-
Premiere Elements 11 refuses to read Premiere 8 files
- perhaps because my old premiere 8 was for pc, and my new premiere 11 is for mac? Anyone out there who knows of a way to make the Premiere 8 files compatible with premiere 11? Thanks in advance