You are on page 1of 5

Implicit conversion

Implicit conversions are automatically performed when a value is copied to a compatible type. For example:

1 short a=2000; 2 int b; 3 b=a;

Here, the value of a is promoted from short to int without the need of any explicit operator. This is known as astandard conversion. Standard conversions affect fundamental data types, and allow the conversions between numerical types (short to int, int to float, double to int...), to or from bool, and some pointer conversions. Converting to int from some smaller integer type, or to double from float is known as promotion, and is guaranteed to produce the exact same value in the destination type. Other conversions between arithmetic types may not always be able to represent the same value exactly:

If a negative integer value is converted to an unsigned type, the resulting value corresponds to its 2's complement bitwise representation (i.e., -1 becomes the largest value representable by the type, -2 the second largest, ...). The conversions from/to bool consider false equivalent to zero (for numeric types) and to null pointer (for pointer types); true is equivalent to all other values and is converted to the equivalent of 1. If the conversion is from a floating-point type to an integer type, the value is truncated (the decimal part is removed). If the result lies outside the range of representable values by the type, the conversion causesundefined behavior. Otherwise, if the conversion is between numeric types of the same kind (integer-to-integer or floating-to-floating), the conversion is valid, but the value is implementation-specific (and may not be portable).

Some of these conversions may imply a loss of precision, which the compiler can signal with a warning. This warning can be avoided with an explicit conversion. For non-fundamental types, arrays and functions implicitly convert to pointers, and pointers in general allow the following conversions:

Null pointers can be converted to pointers of any type Pointers to any type can be converted to void pointers. Pointer upcast: pointers to a derived class can be converted to a pointer of an accessible and unambiguousbase class, without modifying its const or volatile qualification.

Difference between c++ and java?


1. C++ supports pointers whereas Java does not pointers. But when many programmers questioned how you can work without pointers, the promoters began saying "Restricted pointers. So we can say java supports Restricted pointers.

2. At compilation time Java Source code converts into byte code .The interpreter execute this byte code at run time and gives output .Java is interpreted for the most part and hence platform independent. C++ run and compile using compiler which converts source code into machine level languages so c++ is plate from dependents 3. Java is platform independent language but c++ is depends upon operating system machine etc. C++ source can be platform independent (and can work on a lot more, especially embedeed, platforms), although the generated objects are generally platofrom dependent but there is clang for llvmwhich doesn't have this restriction. 4. Java uses compiler and interpreter both and in c++ their is only compiler 5. C++ supports operator overloading multiple inheritance but java does not. 6. C++ is more nearer to hardware then Java 7. Everything (except fundamental types) is an object in Java (Single root hierarchy as everything gets derived from java.lang.Object). 8. Java does is a similar to C++ but not have all the complicated aspects of C++ (ex: Pointers, templates, unions, operator overloading, structures etc..) Java does not support conditional compile (#ifdef/#ifndef type). 9. Thread support is built-in Java but not in C++. C++11, the most recent iteration of the C++ programming language does have Thread support though. 10. Internet support is built-in Java but not in C++. However c++ has support for socket programming which can be used. 11. Java does not support header file, include library files just like C++ .Java use import to include different Classes and methods. 12. Java does not support default arguments like C++. 13. There is no scope resolution operator :: in Java. It has . using which we can qualify classes with the namespace they came from. 14. There is no goto statement in Java. 15. Exception and Auto Garbage Collector handling in Java is different because there are no destructors into Java. 16. Java has method overloading, but no operator overloading just like c++. 17. The String class does use the + and += operators to concatenate strings and String expressions use automatic type conversion, 18. Java is pass-by-value. 19. Java does not support unsigned integer.

Top down and bottom up


Top-down and bottom-up are both strategies of information processing and knowledge ordering, used in a variety of fields including software, humanistic and scientific theories (see systemics), and management and organization. In practice, they can be seen as a style of thinking and teaching. A top-down approach (also known as stepwise design and in some cases used as a synonym of decomposition) is essentially the breaking down of a system to gain insight into its compositional subsystems. In a top-down approach an overview of the system is formulated, specifying but not detailing any first-level subsystems. Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. A top-down model is often specified with the assistance of "black boxes", these make it easier to manipulate. However, black boxes may fail to elucidate elementary mechanisms or be detailed enough to realistically validate the [1] model. Top down approach starts with the big picture. It breaks down from there into smaller segments. A bottom-up approach is the piecing together of systems to give rise to more complex systems, thus making the original systems sub-systems of the emergent system. Bottom-up processing is a type of information processing based on incoming data from the environment to form a perception. Information enters the eyes in one direction (input), and is then turned into an image by the brain that can be interpreted and recognized as a perception (output). In a bottom-up approach the individual base elements of the system are first specified in great detail. These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed. This strategy often resembles a "seed" model, whereby the beginnings are small but eventually grow in complexity and completeness. However, "organic strategies" may result in a tangle of elements and subsystems, developed in isolation and subject to local optimization as opposed to meeting a global purpose.

Difference between static and dynamic binding


Dynamic Binding or Late Binding Dynamic Binding refers to the case where compiler is not able to resolve the call and the binding is done at runtime only. Let's try to understand this. Suppose we have a class named ' SuperClass' and another class named 'SubClass' extends it. Now a 'SuperClass' reference can be assigned to an object of the type 'SubClass' as well. If we have a method (say 'someMethod()') in the 'SuperClass' which we override in the 'SubClass' then a call of that method on a 'SuperClass' reference can only be resolved at runtime as the compiler can't be sure of what type of object this reference would be pointing to at runtime. ... SuperClass superClass1 = new SuperClass(); SuperClass superClass2 = new SubClass(); ... superClass1.someMethod(); // SuperClass version is called

superClass2.someMethod(); // SubClass version is called .... Here, we see that even though both the object references superClass1 andsuperClass2 are of type 'SuperClass' only, but at run time they refer to the objects of types 'SuperClass' and 'SubClass' respectively. Hence, at compile time the compiler can't be sure if the call to the method 'someMethod()' on these references actually refer to which version of the method - the super class version or the sub class version. Thus, we see that dynamic binding in Java simply binds the method calls (inherited methods only as they can be overriden in a sub class and hence compiler may not be sure of which version of the method to call) based on the actual object type and not on the declared type of the object reference. Static Binding or Early Binding If the compiler can resolve the binding at the compile time only then such a binding is called Static Binding or Early Binding. All the instance method calls are always resolved at runtime, but all the static method calls are resolved at compile time itself and hence we have static binding for static method calls. Because static methods are class methods and hence they can be accessed using the class name itself (in fact they are encourgaed to be used using their corresponding class names only and not by using the object references) and therefore access to them is required to be resolved during compile time only using the compile time type information. That's the reason why static methods can not actually be overriden. Read more - Can you override static methods in Java? Similarly, access to all the member variables in Java follows static binding as Java doesn't support (in fact, it discourages) polymorphic behavior of member variables. For example:class SuperClass{ ... public String someVariable = "Some Variable in SuperClass"; ... } class SubClass extends SuperClass{ ... public String someVariable = "Some Variable in SubClass"; ... } ... ... SuperClass superClass1 = new SuperClass(); SuperClass superClass2 = new SubClass(); System.out.println(superClass1.someVariable); System.out.println(superClass2.someVariable);

... Output:Some Variable in SuperClass Some Variable in SuperClass

You might also like