Solved

Understanding byte in Java

Posted on 2016-08-06
2
54 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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

623 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