Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 56
  • Last Modified:

Understanding byte in Java

Hello there,

I am trying to understand what it means when the return type in byte. is it number format or ascii??confused. ALso I have this code below when retunrs the buffer length. first it prints 0 and then in the second print it outputs 28. I want to know where it gets this 28 from. I will appreciate your help to understand this concept.

cheers
Zolf

public class App
{
	public static void main(String[] args)
	{
		System.out.println("Hello Vert.x!");

		Buffer buffer = Buffer.buffer();

		System.out.println("buffer.length() = " + buffer.length());

		buffer.setByte  ( 0, (byte)  127);
		buffer.setShort ( 2, (short) 127);
		buffer.setInt   ( 4,         127);
		buffer.setLong  ( 8,         127);
		buffer.setFloat (16,      127.0F);
		buffer.setDouble(20,      127.0D);

		System.out.println("buffer.length() = " + buffer.length());

Open in new window

0
zolf
Asked:
zolf
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
Here is the 'doc' page for JAVA data types:  http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html   It defines all of them.  

As for your code above, declaring the buffer does not assign anything to it but the 'buffer.set...' statements do.  If you run the code below, you will see that the buffer.length increases with each assignment.

public class App
{
	public static void main(String[] args)
	{
		System.out.println("Hello Vert.x!");

		Buffer buffer = Buffer.buffer();

		System.out.println("buffer.length() = " + buffer.length());

		buffer.setByte  ( 0, (byte)  127);
		System.out.println("buffer.length() = " + buffer.length());
		buffer.setShort ( 2, (short) 127);
		System.out.println("buffer.length() = " + buffer.length());
		buffer.setInt   ( 4,         127);
		System.out.println("buffer.length() = " + buffer.length());
		buffer.setLong  ( 8,         127);
		System.out.println("buffer.length() = " + buffer.length());
		buffer.setFloat (16,      127.0F);
		System.out.println("buffer.length() = " + buffer.length());
		buffer.setDouble(20,      127.0D);

		System.out.println("buffer.length() = " + buffer.length());

Open in new window

1
 
zolfAuthor Commented:
cheers
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now