Solved

Understanding byte in Java

Posted on 2016-08-06
2
43 Views
Last Modified: 2016-08-06
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
Comment
Question by:zolf
2 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 41745377
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
 

Author Closing Comment

by:zolf
ID: 41745919
cheers
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
eclipse argument 14 60
Error in @AspectJ Based AOP with Spring 2 13
Java Restore security prompts not working 10 9
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question