google search

Thursday, January 26, 2012

CREATE A JAVA PROGRAM WITHOUT MAIN METHOD

class Cool
{
static
{
System.out.println("This java program have run without the run method");
System.exit(0);

}
}


AS THE MAIN BLOCK EXECUTES THE STATIC BLOCK FIRST, IT ENCOUNTERS STATIC BLOCK AND EXECUTES THE STATEMENTS PRESENT. BUT IT THROWS A EXCEPTION AS THERE IS NO MAIN METHOD. TO ERADICATE THIS WE USE SYSTEM.EXIT(0) STATEMENT TO EXIT FROM THE PROGRAM FORCIBLY.

Read more...

Wednesday, January 4, 2012

differences between java and c++ #4

Java does not support typedefs, defines, or a preprocessor. Without a preprocessor, there are no provisions for including header files.

Since Java does not have a preprocessor there is no concept of #define macros or manifest constants. However, the declaration of named constants is supported in Java through use of the final keyword.

Java does not support enums but, as mentioned above, does support named constants.

Java supports classes, but does not support structures or unions.

Java does not support pointers (at least it does not allow you to modify the address contained in a pointer or to perform pointer arithmetic). Much of the need for pointers was eliminated by providing types for arrays and strings.

The interface keyword in Java is used to create the equivalence of an abstract base class containing only method declarations and constants. No variable data members or method definitions are allowed. (True abstract base classes can also be created in Java.) The interface concept is not supported by C++.
Java does not support multiple inheritance. To some extent, the interface feature provides the desirable features of multiple inheritance to a Java program without some of the underlying problems.
Java does not support the goto statement (but goto is a reserved word). However, it does support labeled break and continue statements, a feature not supported by C++. In certain restricted situations, labeled break and continue statements can be used where a goto statement might otherwise be used.
Java does not support operator overloading.
Java does not support automatic type conversions (except where guaranteed safe).
Unlike C++, Java has a String type, and objects of this type are immutable (cannot be modified). Quoted strings are automatically converted into String objects. Java also has a StringBuffer type. Objects of this type can be modified, and a variety of string manipulation methods are provided.

The scope resolution operator (::) required in C++ is not used in Java. The dot is used to construct all fully-qualified references. Also, since there are no pointers, the pointer operator (->) used in C++ is not required in Java.

1.it support the basic oops concept
2.java Does't support structure and union,where as c++ supports it.
3.goto statement is avoided in java but not in c++.
4.pointers are not available in java but present in c++.
5.java Does't support multiple inheritance.it supports multilevel inheritance.but c++ supports it
6.operator overloading is avoided.but c++ support operator overloading
7.java is an automatic garbage collector where as in c++ destructor is use to frees memory.
8.java works only on reference where as c++ works on reference as well as on value

Read more...

difference between java and c++ #3

Java can be run anywhere that's the main difference and it available freely. Java has desighn netbeans to support for designing like to to do any project but i n C++ the project is rather tough to built as it doesn't support GUI.

Java uses both Complier and interpreter.

Java is an pure object oriented programming language, it uses the concepts of Classes, Objects, Inheritance, Polymorphism. And the execution of a program is non-linear.
It is so called because you can't write a program with out using classes & objects.

When you compile a Java program, an intermediate bytecode is generated, which itself is interpreted by the Java Virtual Machine. This way you write a program once, and the virtual machine translates the bytecode into instructions a specific processor can understand. Execution of a Java program is by consequence a bit slow, because the intermediate bytecode has to be interpreted.

Java uses a "Garbage Collector" which manages memory automatically so the programmer doesn't have to handle that.

Variables in Java can be declared anywhere in a program. (Although it is recommended to declare/define them at the beginning of blocks).
Reuse of code achieved by inheritance.
By default members are private.
During the execution of bytecode by JVM, it does not substitute the entire classes of package which are imported in the program. It just enters the package and executes the class and returns result in to the program. Due to this less memory is used by java program.

C uses concept of structures (not object oriented).
In C we use the concept of pointers whereas there are no pointers used in JAVA
In C the programmer needs to manage memory manually. "malloc()" and "free()" are the fundamental memory allocation library calls.
In C the declaration of variables should be on the beginning of the block.
C supports go to statement, struct and union unlike Java
C is compiled to the machines "native language" so it's execution is much faster than Java's.
No reuse in code and by default members are public.
C programs will have a larger memory footprint than an equivalent program written in pure machine code, but the total memory use of a C program is much smaller than the a Java program because C does not require the loading of an execution interpreter like the JVM.
--------------------------------------------------------------------------------------------

Java
Java is an pure object oriented programming language, it uses the concepts of Classes, Objects, Inheritance, Polymorphism. And the execution of a program is non-linear.
It is so called because you can't write a program with out using classes & objects.

Java's motto (so to speak) is "write once run anywhere".
When you compile a Java program, an intermediate bytecode is generated, which itself is interpreted by the Java Virtual Machine. This way you write a program once, and the virtual machine translates the bytecode into instructions a specific processor can understand. Execution of a Java program is by consequence a bit slow, because the intermediate bytecode has to be interpreted.

Java uses a "Garbage Collector" which manages memory automatically so the programmer doesn't have to handle that.

Variables in Java can be declared anywhere in a program. (Although it is recommended to declare/define them at the beginning of blocks).
Reuse of code achieved by inheritance.
By default members are private.
During the execution of bytecode by JVM, it does not substitute the entire classes of package which are imported in the program. It just enters the package and executes the class and returns result in to the program. Due to this less memory is used by java program.

C
C uses concept of structures (not object oriented).
In C we use the concept of pointers whereas there are no pointers used in JAVA
In C the programmer needs to manage memory manually. "malloc()" and "free()" are the fundamental memory allocation library calls.
In C the declaration of variables should be on the beginning of the block.
C supports go to statement, struct and union unlike Java
C is compiled to the machines "native language" so it's execution is much faster than Java's.
No reuse in code and by default members are public.
C programs will have a larger memory footprint than an equivalent program written in pure machine code, but the total memory use of a C program is much smaller than the a Java program because C does not require the loading of an execution interpreter like the JVM.

Read more...

  © Blogger templates ProBlogger Template by Ourblogtemplates.com 2008

Back to TOP