Hub Of Geekz

  • Home
  • About Me
  • Contact Us
  • Home
  • Languages
    • C++
    • Java
    • Perl
    • Prolog
    • Bootstrap
  • Database
    • SQL
    • PL/SQL
  • Study
    • Java
      • Java Collection
      • Java Concurrency
      • Java Interview Questions
      • Java Networking
    • Number System
  • Kavita
  • Entertainment
    • Hinglish Cafe
    • Videos
    • Jokes
  • Windows Tricks
  • How To

Wednesday, 6 August 2014

Type Conversion and Casting in Java

 Earthcare Foundation NGO     10:05     Java     No comments   

 Hi friends i am going to you the type conversion and cast of java if the two variables are compatible then java perform the conversion automatically.

For example it is always possible to assign an integer value to long type of variable.And if the variables are not compatible then there is not any explicit conversion in the assignment for instance there is no conversion from double to int.

 Java's automatic conversion
:

 When one type of variable is assigned to another type of variable,an automatic conversion will take place if the following conditions are met:
  • The two types are compatible
  •  The destination type is larger than source type


If we have two incompatible types then we have to a cast it.What if you want to assign a int value to a byte type of variable then implicit conversion cannot take place in Java. We have to put the value of integer into byte  so this kind of conversion is sometimes called narrowing conversion  since you are explicitly making  the value in narrower.
How to create a conversion between two incom
patible types  we have to use a general form:
              target type( value) ;
 the target type specifies the target type to convert a specified value
 for example
            int a;
            byte b;
            b=(byte) a;

   
Automatic Type Promotion in Expressions
 byte b=50;
 b=b*2;//error


because the sub expression b*2  is converted to int and then this is evaluated.So the correct expression is
     b=(byte)b*2;
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Ad


Jobsmag.inIndian Education BlogThingsGuide

Subscribe

Do you want fresh and hot updates about us? Then subscribe to our Feeds.

Total Pageviews

Popular Posts

  • Write a program in PL/SQL to print the factorial of a number.
    In this post I will explain how to get the factorial of any given number. For that first you need to know what is the procedure to find ...
  • To find the GCD of two numbers in PROLOG.
    gcd(X,Y):-X=Y,write('GCD of two numbers is '),write(X); X=0,write('GCD of two numbers is '),write(Y); Y=0,write('G...
  • Write a PL/SQL code to get the Fibonacci Sequence
    First, I will explain what is Fibonacci Sequence and how to get this series. So, Fibonacci Sequence is a series of numbers 0,1,1,2,3,5,8,1...

Label

All Articles Best Resources Blogging Boost Traffic Bootstrap C Plus Plus Collection Comedy Comedy Posts Comedy Videos Concurrency creative commons website Education Employee Entertainment Fibonacci Sequence free images GirlFriend Hinglish Cafe How To Image Websites Inspirational Java Java Interview Questions Java Networking Kavita Sangrah Life Lock Sreen Love Number System Patterns Perl Picture PL/SQL Plastic Engineering Programming Prolog public domain SEO Servlet Short Story Shortcut Keys Social Media Social Services SQL SuVichar Thread Traffic True Events Ultimate Guide Windows Tricks Windows8.1 WordPress

Blog Archive

  • ►  2020 (43)
    • ►  September (41)
    • ►  August (2)
  • ►  2019 (1)
    • ►  July (1)
  • ►  2018 (9)
    • ►  September (7)
    • ►  July (1)
    • ►  May (1)
  • ►  2017 (8)
    • ►  June (3)
    • ►  May (3)
    • ►  March (1)
    • ►  January (1)
  • ►  2016 (2)
    • ►  September (1)
    • ►  January (1)
  • ►  2015 (91)
    • ►  December (1)
    • ►  November (1)
    • ►  October (6)
    • ►  May (10)
    • ►  March (20)
    • ►  February (50)
    • ►  January (3)
  • ▼  2014 (339)
    • ►  December (1)
    • ►  October (55)
    • ►  September (58)
    • ▼  August (94)
      • सुविचार
      • सुविचार
      • और कहता है मत हार तू
      • ओ मेरी गुडिया रानी ओ मेरी गुडिया रानी मेरे एहसास...
      • तुझमे बेसुध होना नही चाहता
      • उनके जाने से मन का दिल से यु बवाल होगा इनके झगड़े ...
      • हम बेसुध रहे आंसू बहते रहे पर पता ना चला कब तुम...
      • सुविचार
      • मेरा मुझमे क्या है ये रोज सवाल करता हूँ
      • कुछ हकीकत ख्वाब
      • Scroll Bar in Java
      • Check Box in Java
      • Button in Java
      • Image Program in Java
      • Animation in Java
      • Box Layout Demo in Java
      • Comedy
      • Even or Odd in Java
      • For loop in Java
      • भूलना चाहू मै हर पल फिर भी क्यों याद आती है
      • जय भारत
      • Comedy
      • Comedy
      • Comedy
      • Comedy
      • Comedy
      • Comedy
      • Jokes
      • Jokes
      • Jokes
      • Comedy Posts
      • Jokes
      • टाइटैनिक के दो दृश्य
      • सुविचार
      • Jokes
      • Print Hello World in Java
      • Hinglish Cafe
      • Hinglish Cafe
      • Jokes
      • बेगाना मौसम
      • अन्जाना एहसास
      • Hinglish Cafe
      • दिल की बात
      • जज्बाते मुहब्बत
      • कौन सा फर्ज  कौन सी बात  बीत गयी वो रात  अब हम ...
      • दर्दे दिल
      • जज्बाते मुहब्बत
      • जज्बाते मुहब्बत
      • Modern Hinglish Cafe
      • Modern Hinglish Cafe
      • सुविचार
      • सुविचार
      • जज्बाते मुहब्बत
      • जज्बाते मुहब्बत
      • सुविचार
      • सुविचार
      • Jokes
      • सुविचार
      • सुविचार
      • बात पूनम की आती है याद आती है उस चाँद की जिसकी पल...
      • गंदे दिमाग में हमेसा गंदगी भरी रहती है और वो हमार...
      • procedure of plastic pipe production
      • तेरी माँग भर के आज तुझे सिन्दूरी किया था हमने
      • जब साथ थे तो पता भी न था की रोने से भी सुकून मिलत...
      • चुप तुम रहो चुप हम है सखी आँखों को आँखों से बात क...
      • A cute boy singing a song
      • बहक गए जो कदम तो संभलना मुस्किल है
      • क्योकि उस राह से गुजरा था मै भी कभी
      • plastic info
      • आज याद आता है यारो वो गोलगप्पे का ठेला
      • फिर वही रात याद आ गयी
      • विचार
      • विचार
      • Type Conversion and Casting in Java
      • वो मिटटी से बनाइ सूरत थी मैंने
      • या कल्पना है कोई जिसका दीदार हो गया
      • My new song tujhme fna hoon
      • Data Types in Java
      • मुहब्बत की गली में अभुमे चलना
      • मुहब्बत की गली में गुजर कर हम
      • मुहब्बत की गली में गुजर कर हम
      • की अब इक बात तुमसे ऐ सखी कहना जरूरी है मुहब्बत की...
      • Java mind blowing facts
      • Best parts of Java
      • राजनीति की नीति कहे क्या नेत्रहीन से ये हो गए
      • सावरी सी सखी अब जवा मै हुई
      • रिस्तो की अभिव्यक्ति
      • फिर भी ये नयन रो जाते है वो आज भी याद आ जाते है
      • बस तू मेरी माँ मुझे प्यार करे
      • मुहब्बत की गली में गुजर कर हम
      • मुहब्बत की गली में गुजर कर हम भी देखेंगे है जो दरि...
      • है समंदर भी अब तो दीवाना हुआ
      • Java Basics
      • है समंदर भी अब तो दीवाना हुआ बूँद पाने को उसकी तड़...
    • ►  July (64)
    • ►  June (67)
  • ►  2013 (34)
    • ►  August (5)
    • ►  April (29)
  • ►  2012 (20)
    • ►  November (1)
    • ►  October (15)
    • ►  September (4)

Author

  • Earthcare Foundation NGO
  • Kavita house
  • Unknown
  • Unknown

Info

Copyright © Hub Of Geekz | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates