The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java data types with examples

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Java data types with examples Posted: Mar 9, 2015 8:18 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Java data types with examples
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
  1. Primitive data types or Fundamental data types.
  2. Referenced data types or Derived data types.

1.Primitive Data types


1.byte

  1. package com.instanceofjava;
  2.  
  3. public class ByteDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         byte a=10; // a is a variable of type byte holding the value 1;
  8.         byte b=20;// b is a variable of type byte holding the value 2;
  9.         
  10.         byte c= (byte)(a+b);
  11.         System.out.println(c);
  12.  
  13.     }
  14. }

Output:

  1. 3

2.short

  1. package com.instanceofjava;
  2.  
  3. public class ShortDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         short a=1;
  8.         short b=2;
  9.         
  10.         short c= (short)(a+b);
  11.         System.out.println(c);
  12.  
  13.     }
  14. }

Output:

  1. 3

3.int

  1. package com.instanceofjava;
  2.  
  3. public class IntDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         int a=10; // a is a variable of type integer holding the value 10;
  8.         int b=20;// b is a variable of type integer holding the value 20;
  9.         
  10.         int c= a+b;
  11.         System.out.println(c);
  12.  
  13.     }
  14. }

Output:

  1. 30


4.long

  1. package com.instanceofjava;
  2.  
  3. public class LongDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         long a=1234567890;
  8.         long b=1234567890;
  9.  
  10.         long c= a+b;
  11.  
  12.         System.out.println(c);
  13.  
  14.     }
  15. }

Output:

  1. 2469135780


5.float

  1. package com.instanceofjava;
  2.  
  3. public class FloatDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         float a=1234567.8f;
  8.         float b=1234567.8f;
  9.  
  10.         float c= a+b;
  11.  
  12.         System.out.println(c);
  13.  
  14.     }
  15. }

Output:

  1. 2469135.5


7.double

  1. package com.instanceofjava;
  2.  
  3. public class DoubleDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         double a=1234567910112181314151634444422233334491.1d;
  8.         double b=1234567910112181314151634444422233334491.8d;
  9.         double c= a+b;
  10.         System.out.println(c);
  11.  
  12.     }
  13. }

Output:

  1. 2.4691358202243627E39

8.char

  1. package com.instanceofjava;
  2.  
  3. public class CharDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         char a='A';
  8.         char b= 'B';
  9.  
  10.       System.out.println(a);
  11.       System.out.println(b);
  12.       System.out.println(a+b);
  13.  
  14.     }
  15. }

Output:

  1. A
  2. B
  3. 131


9.boolean

  1. package com.instanceofjava;
  2.  
  3. public class BooleanDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         boolean a=true;
  8.         boolean b= false;
  9.  
  10.       System.out.println(a);
  11.       System.out.println(b);
  12.   
  13.  
  14.     }
  15. }

Output:

  1. true
  2. false

1.Referenced Data types

1.class


  1. package com.instanceofjava;
  2.  
  3. public class Sample{
  4.  int a,b; 
  5.  
  6. void add(){
  7. System.out.println(a+b);
  8. }

  9. public static void main(String[] args) {
  10.  
  11.        Sample obj= new Sample();
  12.  
  13.        obj.a=10;
  14.        obj.b=12;

  15.        obj.add();
  16.  
  17.     }
  18. }

Output:

  1. 22

2.Array

  1. package com.instanceofjava;
  2.  
  3. public class ArrayDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.         int a[]={1,2,3,4,5,6};
  8.  
  9.         for (int i = 0; i < a.length; i++) {
  10.             System.out.println(a[i]);
  11.         }
  12.   
  13.  
  14.     }
  15. }

Output:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6


Read: Java data types with examples

Topic: Webinar Recap: Git at Scale for Growing Teams Previous Topic   Next Topic Topic: So you want to become a software company?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use