Solved

Understanding byte in Java

Posted on 2016-08-06
2
50 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

751 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