Java Programming Assignment Help - Princeton University USA| Java Programming Homework Help - Princeton University USA | Java Programming Project Help - Princeton University USA | Online Java Programming Help - Princeton University USA

In basic Java programming online underpins predominantly two classes of Data Types . Students of Java Assignment Help Princeton Universty faces lots of problem in understanding the concept of data types . Following is the description with example :-

1. Primitive Types

2. Reference Types

Primitive Types

Java dialect bolsters 8 primitive sorts of information.

Those are:

byte, short, int, long

drift, twofold

boolean

scorch

byte, short, int and since a long time ago used to store whole number qualities

buoy and twofold used to store genuine qualities.

Boolean used to store genuine or false values

burn is utilized to store single character.

Instructions to characterize variable

Grammar:

dataType variableName = esteem;

Illustration:

int intVariable = 10;

Here

dataType is int

variableName is intVariable

esteem is 10

A variable is a named memory area, which holds an esteem.

Naming tradition to characterize a variable

1. A variable name must begin with a character or underscore

2. Variable name can contain alpha numeric characters

3. varibale names shouldn't be a reserverd or catchphrase of java

4. By tradition a variable name begins with little letter, abd every sub sequent word begins with capital letter.

Ex: noOfChar, mySalary and so on.,

Java Keywords

Catchphrase is a saved word, which has extraordinary importance characterized for it.


abstract

continue

for

New

switch

assert

default

goto

package

synchronized

boolean

do

if

private

this

break

double

implements

protected

throw

byte

else

import

public

throws

case

enum

instanceof

return

transient

catch

extends

int

short

try

char

final

interface

static

void

class

finally

long

strictfp

volatile

const

float

native

super

while

 

Note: All keywords are in lower case only

/* Simple Program to Print the variable values */
class DataTypes{
public static void main(String args[]){
byte byteVariable = 10;
short shortVariable = 20;
int intVariable = 30;
long longVariable = 40;
float floatVariable = 10;
double doubleVariable = 20.123;
boolean booleanVariable = false;
char charVariable ='A';

System.out.println("******************************************");
System.out.println("Value Of byte Variable is " + byteVariable);
System.out.println("Value Of short Variable is " + shortVariable);
System.out.println("Value Of int Variable is " + intVariable);
System.out.println("Value Of long Variable is " + longVariable);
System.out.println("Value Of float Variable is " + floatVariable);
System.out.println("Value Of double Variable is " + doubleVariable);
System.out.println("Value Of boolean Variable is " + booleanVariable);
System.out.println("Value Of char Variable is " + charVariable);
System.out.println("******************************************");
}
}

Output
******************************************
Value Of byte Variable is 10
Value Of short Variable is 20
Value Of int Variable is 30
Value Of long Variable is 40
Value Of float Variable is 10.0
Value Of double Variable is 20.123
Value Of boolean Variable is false
Value Of char Variable is A
******************************************

Points to Remember

1. Like many other languages Java doesn't support unsigned numbers. There is no unsigned specifier in Java

class UnsignedEx{
unsigned int a;
}

When you try to compile the above class, below error is thrown.

UnsignedEx.java:2: error: <identifier> expected
unsigned int a;
^
UnsignedEx.java:2: error: <identifier> expected
unsigned int a;
^
2 errors

2. In java all the bytes, shorts are promoted to int before performing operations on them, So we need to explicitly cast them.

class ConversionEx{
public static void main(String args[]){
byte b1 = 1;
byte b2 = 2;
byte b = (b1 + b2);

System.out.println(b);

short s1 = 1;
short s2 = 2;
short s = (s1 + s2);

System.out.println(s);
}
}

When you tries to compile the above program, compiler throws the below error

ConversionEx.java:6: error: possible loss of precision
byte b = (b1 + b2);
^
required: byte
found: int

ConversionEx.java:10: error: possible loss of precision
short s = (s1 + s2);
^
required: short
found: int
2 errors

To make the program compiles fine, we need to explicitly cast, after performing the operation

class ConversionEx{
public static void main(String args[]){
byte b1 = 1;
byte b2 = 2;
byte b = (byte)(b1 + b2);
System.out.println(b);

short s1 = 1;
short s2 = 2;
short s = (short)(s1 + s2);
System.out.println(s);
}
}

Output
3
3

3. In Java, if one of the operand is double, then other also promoted as double, and the final result will be double

Example

class ConversionEx{
public static void main(String args[]){
float f1 = 1.1f;
double f2 = 1.2f;
float f = (f1 + f2);
System.out.println(f);
}
}

When you tries to compile the above program, compiler throws the below error

ConversionEx.java:6: error: possible loss of precision
float f = (f1 + f2);
^
required: float
found: double
1 error

To make the program run, cast the result to float.
class ConversionEx{
public static void main(String args[]){
float f1 = 1.1f;
double f2 = 1.2f;
float f = (float)(f1 + f2);
System.out.println(f);
}
}

Output
2.3000002

Our Team

We have 2500+ expert pool from all over the world. They are highly qualified and well experienced. All experts have experinced in teaching and good command over programming topics. Some of our experts are as follows:


John Doe

JAVA EXPERT(10+ Yrs Exp.)

Larry Doe

C EXPERT(12+ Yrs Exp.)

Ranith Kays

C++ EXPERT(8+ Yrs Exp.)

Joan Ray

OPEN SOURCE LANGUAGE EXPERT(8+ Yrs Exp.)