Java Queries Here..

Can you please elaborate on this? I think I didn't get you. What do you mean by not implicit?

By implicit I understand JDK/JRE automatically converts it, you don't have to do it manually (invoking any method).

did u open the link just after that line??
this :: Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

implicit conversion = Widening Primitive Conversion
explicit conversion = Narrowing Primitive Conversions

i will now quote fragment from this page :: Conversions and Promotions
the important thing are in bold
5.1.2 Widening Primitive Conversion
The following 19 specific conversions on primitive types are called the widening primitive conversions:

* byte to short, int, long, float, or double
* short to int, long, float, or double
* char to int, long, float, or double
* int to long, float, or double
* long to float or double
* float to double

Widening primitive conversions do not lose information about the overall magnitude of a numeric value. Indeed, conversions widening from an integral type to another integral type and from float to double do not lose any information at all; the numeric value is preserved exactly. Conversions widening from float to double in strictfp expressions also preserve the numeric value exactly; however, such conversions that are not strictfp may lose information about the overall magnitude of the converted value.

Conversion of an int or a long value to float, or of a long value to double, may result in loss of precision-that is, the result may lose some of the least significant bits of the value. In this case, the resulting floating-point value will be a correctly rounded version of the integer value, using IEEE 754 round-to-nearest mode (§4.2.4).

A widening conversion of a signed integer value to an integral type T simply sign-extends the two's-complement representation of the integer value to fill the wider format. A widening conversion of a character to an integral type T zero-extends the representation of the character value to fill the wider format.

Despite the fact that loss of precision may occur, widening conversions among primitive types never result in a run-time exception (§11).

Here is an example of a widening conversion that loses precision:

Code:
   class Test {
    	public static void main(String[] args) {
    		int big = 1234567890;
    		float approx = big;
    		System.out.println(big - (int)approx);
    	}
    }

which prints:

-46

thus indicating that information was lost during the conversion from type int to type float because values of type float are not precise to nine significant digits.

5.1.3 Narrowing Primitive Conversions
The following 23 specific conversions on primitive types are called the narrowing primitive conversions:

* byte to char
* short to byte or char
* char to byte or short
* int to byte, short, or char
* long to byte, short, char, or int
* float to byte, short, char, int, or long
* double to byte, short, char, int, long, or float

Narrowing conversions may lose information about the overall magnitude of a numeric value and may also lose precision.

A narrowing conversion of a signed integer to an integral type T simply discards all but the n lowest order bits, where n is the number of bits used to represent type T. In addition to a possible loss of information about the magnitude of the numeric value, this may cause the sign of the resulting value to differ from the sign of the input value.

A narrowing conversion of a character to an integral type T likewise simply discards all but the n lowest order bits, where n is the number of bits used to represent type T. In addition to a possible loss of information about the magnitude of the numeric value, this may cause the resulting value to be a negative number, even though characters represent 16-bit unsigned integer values.

The example:

Code:
  class Test {
    	public static void main(String[] args) {
    		float fmin = Float.NEGATIVE_INFINITY;
    		float fmax = Float.POSITIVE_INFINITY;
    		System.out.println("long: " + (long)fmin +
    						".." + (long)fmax);
    		System.out.println("int: " + (int)fmin +
    						".." + (int)fmax);
    		System.out.println("short: " + (short)fmin +
    						".." + (short)fmax);
    		System.out.println("char: " + (int)(char)fmin +
    						".." + (int)(char)fmax);
    		System.out.println("byte: " + (byte)fmin +
    						".." + (byte)fmax);
    	}
    }
produces the output:

long: -9223372036854775808..9223372036854775807
int: -2147483648..2147483647
short: 0..-1
char: 0..65535
byte: 0..-1

The results for char, int, and long are unsurprising, producing the minimum and maximum representable values of the type.

The results for byte and short lose information about the sign and magnitude of the numeric values and also lose precision. The results can be understood by examining the low order bits of the minimum and maximum int. The minimum int is, in hexadecimal, 0x80000000, and the maximum int is 0x7fffffff. This explains the short results, which are the low 16 bits of these values, namely, 0x0000 and 0xffff; it explains the char results, which also are the low 16 bits of these values, namely, '\u0000' and '\uffff'; and it explains the byte results, which are the low 8 bits of these values, namely, 0x00 and 0xff. Despite the fact that overflow, underflow, or other loss of information may occur, narrowing conversions among primitive types never result in a run-time exception (§11).


the whole concept can be actually explained in one line ::
if result takes more memory then implicit conversion. otherwise explicit conversion or compiler error
 
Last edited:

Garbage

God of Mistakes...
Err.. Seems you didn't get my point. What you are talking about is primitive data types. And String is an object.

Correct me if you are still talking about String + <something> conversion and given link / explanation applies to that.
 

iamharish15

Broken In
I want to make a major project in Java Se. Can anybody suggest me the ideas for the project and the slight overview of the project you would suggest.
 

Garbage

God of Mistakes...
I want to make a major project in Java Se. Can anybody suggest me the ideas for the project and the slight overview of the project you would suggest.

:|

How much time do you have?
How much years of experience you have?
How many people will be doing the project?
What are your interest areas about programming / software?
Are you ready to buy services needed (ex. product hosting site, etc.)
 

iamharish15

Broken In
I have about 1 to 2 months
I have just 8-9 months of experience in programming in Java SE in minor individual projects like contact management project etc..
Atmost 2 or 3 people will be working on the project
Well I'm not sure about my interest areas, but any project that can run without much knowledge of database would be fine
No, I would not prefer not to buy such services.

Now can you suggest any project that fits in my requirements and eligibility.
 

dead.night7

Journeyman
Guys is there a compiler to run java, so as that the c++ compilers. Is it inbuilt into windows or any other please tell me direct link preferred. Anybody thanks :)
 

Piyush

Lanaya
i'm gonna buy a book on java programming
it should cover all topics:from basics to expertise concepts

any good recommendation?
i would be ordering from flipkart most probably
 

sakumar79

Technomancer
I found Java How to Program by Dietel and Dietel publishers a very good book... Another option is Thinking in Java by Bruce Eckel (available as free ebook) which is also good. TiJ may not be suited for novices - if you have a basic idea of OOP it will be very good...

Arun
 

Piyush

Lanaya
Is this the one?
Flipkart.com: Head First Java: Kathy Sierra (9788173666025)

there is one more but cost a fortune
Flipkart.com: Head First Java: Kathy Sierra, Bert Bates (9780596009205)

whats the difference?
 

Piyush

Lanaya
The one for 358. Might be a mistake at their side. If it costs 2000 bucks, i'd rather add 2500 and get HD5670.... :D

:lol:

anyways I'll be needing one book for computer networks also
I've a vague idea about it, but the book should cover all relevant topics which comes in computer networks
 

Liverpool_fan

Sami Hyypiä, LFC legend
:lol:

anyways I'll be needing one book for computer networks also
I've a vague idea about it, but the book should cover all relevant topics which comes in computer networks

Not all topics, but Head First Networking will really build your basics very well.

The one for 358. Might be a mistake at their side. If it costs 2000 bucks, i'd rather add 2500 and get HD5670.... :D

The 2k one is imported edition. Not quite worth it though.
 

bijay_ps

Broken In
thread creation & "this" keyword doubt

what is the use of "this" keyword in thread creation in java? And check out this program:
Code:
[CODE]class NewThread implements Runnable{
	Thread t;
	NewThread(){
		t=new Thread(this,"Demo Thread");
		System.out.println("Child Thread: " + t);
		t.start();
	}
public void run(){
	try{
		for(int i=5;i>0;i--){
			System.out.println("Child Thread: " + i);
			Thread.sleep(500);
		}
	}catch(InterruptedException e){
		System.out.println("Child interrupted.");
		}
        System.out.println("Exiting child thread.");
		}
}
class ThreadDemo {
	public static void main(String args[]){
		new NewThread();
		try{
			for(int i=5;i>0;i--){
				System.out.println("Main Thread: " + i);
				Thread.sleep(1000);
			}
		}catch(InterruptedException e){
			System.out.println("Main thread interruoted.");
		}
	System.out.println("Main thread exiting.");
	}
}
[/CODE]
In this program if instead of keyword "this" i use only "t", I get output but only for main thread and not for child thread. Why the output differs? If "this" keyword only refer to the instance of the class from its method then why can't we use that instance directly?
 

Garbage

God of Mistakes...
:lol:

anyways I'll be needing one book for computer networks also
I've a vague idea about it, but the book should cover all relevant topics which comes in computer networks

This is THE book for learning all about Computer Networks
Amazon.com: Computer Networks (9780133499452): Andrew S. Tanenbaum: Books
 
anyways I'll be needing one book for computer networks also
I've a vague idea about it, but the book should cover all relevant topics which comes in computer networks

java:
beg: head first / complete reference
adv: Kathy Sierra / Khalid Mughal

networking :
beg: head first
med: computer networks by Tanenbaum
adv: CCNA course material (Vol 1 + Vol 2)
 
Top Bottom