Serial port with Processing

I have uploaded this sketch into the arduino:

void setup() {
    pinMode(2, INPUT);
  Serial.begin(9600);  
}
void loop() 
{  
    Serial.println(analogRead(2));
}

and the analog pin is connected to the arduino's 5v, which means in the serial port it has to show only numbers around 1023.

though i have tried to read serial data from processing, it gives me numbers lower than 60. here is the processing code:

import processing.serial.*;
Serial myPort;  
int val;    
void setup() 
{
  String portName = Serial.list()[1]; //com3, same as arduino
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  if ( myPort.available() > 0)  // If data is available,
  {  
    val = myPort.read();         // read it and store it in val
    println(val);
  }
}

what can cause this problem?

what can cause this problem?

When you write from the arduino you are sending several ASCII bytes. When you read from processing you are only reading one byte.

See:- Arduino Playground - Processing

I'm having a problem with this line:
import cc.arduino.*;
the code says "The package "cc" does not exist. You might be missing a library"

although I have downloaded the library for firmata v1 into the processing libraries folder

anyone knows what is the problem now ?

You must have the hierarchy:
/libraries//library/.jar

best

thanks very much, that helped.

Don't know if you solved your original problem, but as Grumpy said it's because you're sending 2 bytes at a time when you send an int value...

Here is a method of sending and receiving int values that works for me:

Arduino:

Serial.print(0xff, BYTE); // Sync byte
Serial.print((val >> 8) & 0xff, BYTE);
Serial.print(val & 0xff, BYTE);

Processing:

while (port.available() >= 3) {
    if (port.read() == 0xff)
      val = (port.read() << 8) | (port.read());
}

zdroshnya, thank you very much, this is the hint I needed.
The problem of the normal arduino installation is the name of the file.
It is written "Arduino.jar" and so, I've got every time this error message.
I have renamed the file in "arduino.jar" and the library works well.
The guys of the arduino project should corred this in the "processing-arduino-0017.zip" file.

thanks a lot

Helmut