Solved

Understanding byte in Java

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

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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
Comment Utility
cheers
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
allStar challenge 1 40
strDist challenge 35 83
What is JNDI datasource in spring 1 36
what is a "java.lang.System Property"   ? 20 27
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now