Home Tutorialhelp Comment Not efficient

 
 

Comment

Ron
Not efficient,
December 17, 2009 at 4:24 PM

Re: primitive double to primitive int.

Yes, true, it works, but it's like going from India to UK by crossing the Pacific Ocean, you'll be there of course but...

Generating string and then parse it back? No, the right way to do it is simply:
double d = i;

since in Java int is always 32-bits, there would be no data loss when converting int to double.

For example, to force floating-point division:

int a = 5;
int b = 2;
double d = a / b; // doesn't work, d will be 2.0 because a / b is integer division

double da = a;
double db = b;
d = da / db; // works, d will be 2.5 since da / db is floating-point division

That's good if da and db will be reused again later (save you some int-to-double conversions) but if you just need it once, use casting:

d = (double)a / (double)b; // no need for temporary variables
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Java Beginners

Making efficient program - Java Beginners
Making efficient program  Hi, How you can write efficient programs in Java? Thanks 

Java Beginners

Which method is more efficient?
Which method is more efficient?  I'm faced with initializing a bunch of text fields in java. The problem is that the number of text fields is quite large, so i thought of putting them into an array and using a loop to initialize 

Java Beginners

What is an efficient way to implement a singleton pattern in Java?
What is an efficient way to implement a singleton pattern in Java?  What is an efficient way to implement a singleton pattern in Java 

Java Beginners

java conversion
java conversion  how do i convert String date="Aug 31, 2012 19:23:17.907339000 IST" to long value 

Java Beginners

what fastest DataStructre(efficient) in java? and why? - Java Beginners
what fastest DataStructre(efficient) in java? and why?  what is the fastest data Structres in java? and how,why compare to other DataStructer from other 

Java Beginners

object conversion - Java Beginners
/java-conversion/ObjectToDouble.shtml Thanks... sandeep kumar suman...object conversion   Hi, Can anybody tell me the object conversion in java.   Hi sandeep Can u please tell me in details about your 

Applet Questions

conversion Applet
conversion Applet  I am a java beginner.................. strong texthow to create JApplet that prompts the user to enter a distance in miles in a JTextField and then converts mile to kilometers and display the result as XX.XX 

Java Beginners

Java Conversion Question - Java Beginners
Java Conversion Question   Hello sir ,How i can Convert Java Code to Vb.net ,Plz Help Me 

Java Beginners

Language Conversion
Language Conversion  write a java program to convert "Hello World" in spanish 

Java Beginners

html2xml conversion
html2xml conversion  java code to convert html file to xml 

Java Beginners

Type Conversion - Java Beginners
for conversion 

Java Beginners

image conversion tools
image conversion tools  how many tools are available in image conversion at particularlly in java 

Java Beginners

Distance conversion - Java Beginners
Distance conversion  Write an application that reads a distance in metres. The program will then present a user menu of conversion types, converting the distance to kilometres, feet and inches, according to the user?s selection 

UML Questions

hexadecimal conversion java compilation - UML
hexadecimal conversion java compilation  write a simple program..., Please visit the following links: http://www.roseindia.net/java/java-conversion/BinaryToHexa.shtml http://www.roseindia.net/java/java-conversion 

Java Beginners

form to java script conversion
form to java script conversion  I am using a form one more form cotain a piece of code . how to convert it to java script to function it properly? code is shown below <form action="http://www.google.com" id="cse-search 

Java Beginners

conversion - Java Beginners
 

Java Beginners

Excel conversion tool. - Java Beginners
Excel conversion tool.  Hi, I need a conversion tool which can convert .xls(Excel 2003) to .xlsx (Excel 2007) and vice-versa. Please suggest any links ro tools. Thank You 

Java Beginners

Java To Vb.Net Conversion - Java Beginners
Java To Vb.Net Conversion  How to convert Java Code To VB.net,which Software is useful to convert java to vb.net,plz Help Me 

Programming Tutorials

Implement mechanisms for efficient inter-component calls
Implement mechanisms for efficient inter...; Implement mechanisms for efficient inter-component calls Bean Interfaces...-by-reference semantics. The local interface is a standard Java interface 

Development process Questions

Conversion - Development process
Conversion  Why is there a need to convert from Java to .NET? What is the theory of conversion from java to .NET? How it is done?   Hi... Conversion Assistant (JLCA). Code that calls Java APIs can convert to comparable C# code 

Java Beginners

String to Date Conversion - Java Beginners
)); For read more information : http://www.roseindia.net/java/java-conversion...  Hi friend, For conversion in this format : 11/SEP/2008 07:07:32 

Java Beginners

Another distance conversion - Java Beginners
a method for each conversion ? toKilometres(), toFeet(), and toInches 

Java Beginners

PDF to Word Conversion - Java Beginners
PDF to Word Conversion  Hello, Can we convert a PDF document to Microsoft word document thru Java. If its not possible in Java, is it possible in any other language 

Java Interview Questions

Conversion In Collections - Java Interview Questions
Conversion In Collections  Hi Friends, can u give code to convert ArrayList to HashMap and HashMap to ArrayList. Thanks Prakash  Hi Friend, 1)Convert ArrayList To HashMap: import java.io.*; import java.util. 

Date Calendar

Java Date conversion - Date Calendar
Java Date conversion  How do I convert 'Mon Mar 28 00:00:00 IST 1983' which is a java.util.Date or String to yyyy/MM/dd date format in sql 

Java Beginners

Reports to pdf conversion
Reports to pdf conversion  I need to convert reports into pdf format using java.. Will i get any sample code 

Java Beginners

pdf to xml conversion
pdf to xml conversion  i want to convert pdf file into xml file.. where i am having a table in pdf file with some headers and some data into it. i want the headers to be the tag of xml file. how can i do that using java? please 

Java Beginners

HSSFCell to String type conversion
://www.roseindia.net/tutorial/java/poi/readExcelFile.html 

Java Beginners

Conversion from color to Gray Image - Java Beginners
Conversion from color to Gray Image  Hi... Sakthi here.. i am new to java. and i haven't try this so far How to convert the color image to gray scale image in java? could u plz help me out to start the process 

Development process Questions

java code for conversion of arraylist to string - Development process
java code for conversion of arraylist to string  Hi, i have an arraylist contains [a,b,value,c,d,value]when ever value comes it will split into seperation.fo that i want to convert into string, after that split the string 

Java Beginners

ascii to thai language conversion - Java Beginners
 

General

Java Date Conversion
Java Date Conversion In java date conversion, two packages are used... seconds and even then only Java provides implementation that actually track leap... Java Converts String into Date In this example we are going to convert 

Development process Questions

Java code for conversion between .xls and .xlsx or vice versa - Development process
Java code for conversion between .xls and .xlsx or vice versa  I've some problems in my Project. I'm working on a web based application which... or tool in Java for converting between .xls to .xlsx or Vice versa 

Struts Questions

jsp to struts 2 action conversion problem - Struts
jsp to struts 2 action conversion problem  i have one jsp page that includes 3 other jsp pages(using RequestDispactcher).how to convert that jsp...(i.e no java code is involved).remaining pages involve java code.  Hi 

General

Java Conversion
Java Conversion      ... are trying to make understand the conversion of an input stream into an output... to ByteArray Here we will learn the conversion of an input stream into a byte 

General

Java Conversion
 

Java Tips and Examples

Conversion of Decimal to Binary in Java
Conversion of Decimal to Binary  in Java In this section we will discuss about conversion of Decimal to Binary in Java. You know that number having.... Now here is the code for conversion.  class Conversion { public static 

Java-Tutorials

Java : String Case Conversion
Java : String Case Conversion In this section we will discuss how to convert a String from one case into another case. Upper to Lower case Conversion... into lower case char/String. Lower to Upper case Conversion : By using toUpperCase 

Java Beginners

conversion
 

Java Beginners

conversion
 

Java Beginners

java
java  please suggest me the best books for learning efficient java 

General

Casting (Type Conversion)
are there in java. Some circumstances requires automatic type conversion, while in other cases... Java performs automatic type conversion when the type of the expression... Casting (Type Conversion)       

Java Beginners

Java Servlets
Java Servlets  If the binary data is posted by both doGet and doPost then which one is efficient?Please give me some example by using both doGet and doPost. Thanks in Advance   The doPost method is more efficient 

Java Tips and Examples

Programming: Numeric Conversion
Java NotesProgramming: Numeric Conversion Name ________________________________ Description Write a program which converts a measurement from one system of units to another. Read a number (or numbers) in one system and output 

Core Java

String to Int Conversion
String to Int Conversion      ... equivalent. To demonstrate the conversion of string into an integer we are taking...;} }   Here is the Output of the program: C:\>java 

Java Tips and Examples

Programming: Numeric Conversion
Java NotesProgramming: Numeric Conversion Name... of it as a conversion, it could also be a calculation, eg, to calculate the air... with Kilometers to Miles as an example of how a conversion program might 

Core Java Tutorials

Conversion from String to char
Conversion from String to char: In this tutorial we will learn how to convert a string type data to char type data. Description: This program will take...(buffreader.readLine()); String mystring = "Welcome to Java"; Character 

Java Beginners

java
java  why data structures?   The data structures provided by the Java utility package are very powerful and perform a wide range... are more powerful, efficient and dynamic 

Java Tips and Examples

Java - Arithmetic Operation, Conversion and Casts in java
Java - Arithmetic Operation, Conversion and Casts in java... into another. This is important for the type conversion in developing any... of the program : public class conversion{   

Java Beginners

java
java   Write a program that uses a ‚??FOR‚?? loop that convert Inch to Centimetre that produce the following output. Create a method toCentimetre that will return the conversions. The formula for the conversion is Centimetre 

Java Beginners

java
to this: Hi friends and how are you? i have a problem i need to write a java program which has a two java packages, one has the interface and the other has classes, with each class calculating the conversion of the South african rand to US dollar 

Java Beginners

java
java  Hi friends and how are you? i have a problem i need to write a java program which has a two java packages, one has the interface and the other has classes, with each class calculating the conversion of the South african 

Free Magazine

Java Developers Desk- Annotations
Java Developers Desk- Annotations      ... and more efficient in jdk 5. The main objective to develop the annotations... meaning of meta data is data about data. Java also signifies this meaning 

Java-Tutorials

Insertion Sort Java
, Insertion Sort in Java is less efficient when it comes to larger data sets... of Insertion Sort in Java: It can be simply implemented Efficient for small...Insertion Sort in Java is an algorithm that is used to sort integer values 

Training

Java Server Faces (JSF)
to build rapid data-driven Java web applications. To make efficient... Java Server Faces (JSF)      ... Efficiency in Java programming language and well skilled in developing Java Server 

JSP Servlet Questions

currency conversion
currency conversion   hi frds.. I wan jsp code to convert currency in different formats??... if u know plz plz plz post it   Please visit the following link: http://www.roseindia.net/tutorials/I18N/currency 

Java Technology Tutorials

Java date to String, Convert date object into a string with a pattern
Convert date object into a string with a pattern This section illustrates you the conversion of date object into a string pattern. Java has provide many classes for formatting and parsing the date and time. Here we have used 

Java Beginners

java - Java Beginners
links: http://www.roseindia.net/java/java-conversion/DecimalToBinary.shtml http://www.roseindia.net/java/beginners/DataConversion.shtml Thanks...java  write a java program that will read a positive integer 

Java Beginners

java
methods if they are efficient and eliminate redundant code, but they must 

Java Interview Questions

java - Java Interview Questions
java  which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2 

Java Beginners

java - Java Beginners
a program for a Java application / applet which contains a set of GUI components as detailed below.\ 1. The Java applet page/application models a currency converter, containing a set of currency (minimum SIX) and the conversion result. 2 

General

Interthread communication
Interthread communication       Java implements a very efficient way to interprocess... InterThread.java C:\nisha>java InterThread Produce: 1 

JavaScript Questions

javascript conversion
 

Java Beginners

String conversion
 

Java Beginners

core java - Java Beginners
-in-java/ it's about calculating two numbers Java Program Code for calculating two numbers http://www.roseindia.net/java/java-conversion/calculating-three 

General

Inter-Thread Communication
Java provides a very efficient way through which multiple-threads...:\nisha>javac InterThread.java C:\nisha>java InterThread...\thread>java DemoWait Demo1 value is20 value is :40 C:\j2se6 

Applet Questions

java - Applet
java  Hi, I need very urgent code............ please help me......... How to convert text to wave conversion? I need java code............ Regards, Valarmathi 

Java Beginners

java encoding - Java Beginners
://www.roseindia.net/java/java-conversion/CharToASCIIi.shtml Your comments are welcome regarding...java encoding  how to encode String variable to ASCII,FromBase64String,UTF8  Hi It's very easy to convert String Variable into ASCII 

Java Beginners

java programming - Java Beginners
java programming  write and run a programme that accept a string from keyboard and convert it into a number.  Hi Friend, Please visit the following link: http://www.roseindia.net/java/java-conversion 

Java Beginners

java - Java Beginners
operations like loading an image, blurring, grey scale conversion, increase...;Hi Friend, Please visit the following links: http://www.roseindia.net/java/example/java/swing/color-effect-image.shtml http://www.roseindia.net/java 

Framework Questions

java - Framework
java  what is the difference between hibernate and spring frameworks in usage? which of the two is efficient and more advantageous 

Blog

Sitemap Core Java Tutorial Section
Conversion | Return Java Keyword | Remote Method Invocation (RMI... Map | Business Software Services India Java Tutorial Section Core Java... | JDK 6 Tutorial | Java UDP Tutorial | Java Threading Tutorial | Java

Struts Questions

java - Struts
://www.roseindia.net/java/java-conversion/StringToDate.shtml Thanks 

Java Interview Questions

Java programming approch
Java programming approch  What are the approaches that you will follow for making a program very efficient 

Java Beginners

java - Java Beginners
: http://www.roseindia.net/help/java/m/method-overloading-in-java.shtml http://www.roseindia.net/java/master-java/method_overloading.shtml http://www.roseindia.net/java/javascript-array/modified-java-method-overriding.shtml http 

Java Beginners

Core Java-java.util.date - Java Beginners
); } } } For more information on Java Conversion Visit to : http://www.roseindia.net/java/java-conversion/ Thanks Vineet...Core Java-java.util.date   How we can convert string to Date   

Java Interview Questions

Java - Java Interview Questions
application. * Image conversion-Scaling maps, and so on. * Data compression-Making... to : http://www.roseindia.net/java/example/java/util/ Thanks 

Java Beginners

java application/applet - Java Beginners
java application/applet  In this project, the student has to develop and submit a program for a Java application / applet which contains a set of GUI components as detailed below. 1. The Java applet page/application models 

Java Interview Questions

.wav file conversion
.wav file conversion   how to read .wav file and converd the data into text format 

Struts Questions

conversion of language in a project
conversion of language in a project  how can we convert the database code in the project dynamically 

JavaScript Questions

Number conversion in JavaScript
Number conversion in JavaScript  How do you convert numbers between different bases in JavaScript 

Java Beginners

java - Java Beginners
-conversion/how-to-get-primenumber.shtml http://www.roseindia.net/java/java-conversion http://www.roseindia.net/java/beginners I hope this will help you...java  Q 1- write a program in java to generate Armstrong numbers 

Mobile Applications Questions

NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   Hi, Please see NSString to float conversion 

Java Beginners

java basics
java basics  What is a native method?  The Java native method is a great way to gain and merge the power of C or C++ programming into Java. To use Java as a scientific and high performance language, when efficient 

Java Beginners

JAVA - Java Beginners
java 1.4 vs java 1.5  What is the difference between java 1.4 and java 1.5?  Difference between java 1.4 and java 1.5Java programming language is simple,distributed , robust, object oriented & secure.The Java 2 SDK 

Java Beginners

Java bufferedreader
Java bufferedreader  Hi, How to write program using Java...;In Java the BufferedReader class is used to read the stream successfully with buffering. The BufferedReader class provides efficient reading from the input 

Java-Tutorials

Convert a file name path to url and vice versa in java
 

Java Tips and Examples

Convert InputStream to ByteArray
Convert InputStream to ByteArray       Here we will learn the conversion of an input... InputstramToByteArray.java C:\rajesh\io>java InputstramToByteArray 106 

JDBC-Tutorials

Prepared Statement Example
is used to make the SQL statement execution efficient. In Java, when we use... will create a Java classes into which we will use the classes and interfaces... a new record When you will compile and execute the above Java code 

Mobile Applications Questions

NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   HI, Use the following code: NSScanner *strXpos 

Java Beginners

java problem - Java Beginners
java problem  a) Binary numbers is important in computers. Binary... available in Java that will allow us to convert from denary integer (base 10... the integer in its binary equivalent. You are to write your own logic of conversion 

Java Tips and Examples

Autoboxing
Java NotesAutoboxing Autoboxing, introduced in Java 5, is the automatic conversion the Java compiler makes between the primitive (basic) types... required by Java Collections, which can not be used with primitive types. Example 

Java Tips and Examples

Exception Usage
Java NotesException Usage Exceptions Exception Usage | Exceptions - More Common Exceptions The most common exceptions to catch are number conversion exceptions and I/O exceptions. Here are some common exceptions to catch 

Servlets

What is Servlet in Java?
fast and efficient. Servlets are mostly used to develop interactive Web-based applications that can run on any servlet enabled web server. Servlets use of Java... dynamic content to a web server. Servlets generally embed HTML inside Java code 

Java Beginners

java-io - Java Beginners
://www.roseindia.net/java/java-conversion/two-dimensional-array-program-using-nested-loop.shtml http://www.roseindia.net/java/beginners/SquareMatrix.shtml Thanks...java-io  Hi Deepak; down core java io using class in myn 

Java Beginners

Logic - Java Beginners
Logic  In a sorted array, write an efficient algorithm to find any element satisfying the condition a[i] = i 

Date Calendar

is this programm efficient to find the day of the given date . can it be more normalized ?
is this programm efficient to find the day of the given date . can it be more normalized ?  #include <stdio.h> int main(void) { int dd,mm,yy,i,leap=0,ordi=0,odd_years,month_days= 0,total ; char week[7][10 

Training

PHP Training
of the learners. Our efficient trainers have a strong command on PHP, HTML, MySQL, C, Java...; The knowledge of at least one scripting/programming language like C, Java or Perl 

Java Beginners

Conversion of String to Integer
Conversion of String to Integer  public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int 

JavaScript Questions

javascript integer to string conversion
javascript integer to string conversion  How to Javascript Integer to String Conversion   <script type="text/javascript"> /** * print out the value and the type of the variable passed 

Advertisements Advertisements
 

 

 

DMCA.com