School Papers

Assignment So, memory management is far better than

Assignment 1Advanced Programming UsingJAVASubmitted By- Hariom (CCVT B3)Roll. No. – R110216069Faculty- Mr. Ravi TomarIntroduction to JavaJava is one of the most widely adopted programming languages all across theworld. Java was first developed by Sun Microsystems. Later it was bought byOracle.What is Java?? Java is object oriented language which is simple to code.? Java is robust and secure. Java is used for creating highly reliablesoftware. It can be operated on distributed environment. Java has nopointers like C and C++. So, memory management is far better than cand C++ programs.? Java is architecture neutral and portable. After compilation of a javacode file, JVM creates a bytecode file which is fully platformindependent. Any machine running java can run this bytecode. It isportable because there exist no data type incompatibilities acrosshardware and software architectures.? Java offers more performance compared to C++. Java has inbuiltAutomatic garbage collector running in the background which makessure that every program has allocated memory when required.? Java is interpreted, threaded and dynamic. Java supports multithreading. A class ‘Thread’ provides the multi-threading functionalitywithout conflicting concurrent threads of execution.Java Inbuilt classes and methodsJava.lang – the collection of the base types (wrapper classes, streams and random access files.Java.util – container and utility classes (dictionary, hash tables etc.)Java.awt – A toolkit that allows us to port a program from one systemto another.Main features of Java –Java is similar with c++ to an extentPrimitive data typesExcept primitive data types, everything is object in JAVA. Mainly there are onlythree kinds of primitive datatype in java (numeric, Boolean and array)ArrayArrays in java language are first class language objects unlikely to C and C++.In contrast to C language, Access to elements of an array can be performed viathe normal C-style indexing, but all array accesses are checked to ensure thattheir indices are within the range of the array. An exception is generated if theindex is outside the bounds of the array.Inbuilt method length() is used to find the number of elements given inside ofan array.StringsIn C, strings are pseudo-arrays of characters. But in java, Strings are objects.Memory ManagementC and C++ languages have a lots of problems with memory management(allocating memory, freeing memory and keeping track of memory when itneed to be allocated to the required program). This explicit management ofmemory causes lots of bugs in the program and also crashes, memory leaksand poor performance.In java, programmer doesn’t have to take care of memory managementexplicitly. ‘Pointers’, ‘calloc’, ‘malloc ‘and ‘free’ keywords do not exist in java.Java has automatic garbage collector as its integral part. There is ‘new’operator to allocate memory to objects but there is no ‘free’ operator to freethe allocated memory explicitly. Once you have allocated an object, the runtime system keeps track ofthe object’s status and automatically reclaims memory when objects are nolonger in use, freeing memory for future use.The memory management model of java is based on objects and references toobjects. Because Java has no pointers, all references to allocated storage,which in practice means all references to an object, are through symbolic”handles”.The Java memory manager keeps track of references to objects. When anobject has no more references, the object is a candidate for garbage collection.Java’s memory allocation model and automatic garbage collection makeprogramming tasks easier, eliminate possibility of bugs, and in general providebetter performance than you’d obtain through explicit memory management.Features Removed from C and C++Typedef, define or pre-processor are not present in java.There is no need of header files in java. Instead of header files, java languagesource files provide definition of other classes and their methods.#define and typedef are replaces by classes. Java becomes context free byremoving all these baggages.Structures and UnionsJava do not have any structure or union as complex data typesInstead of structures and unions, in java we can create classes with morefunctionalityMultiple InheritanceIn many cases, multiple inheritance caused ambiguity in programs.Java has no concept as multiple inheritance. The desirable features of multipleinheritance are provided by “Interfaces” in java.An interface defines the set of methods that can be implemented and used byvarious objects.GotoJava has removed goto statement. Removal of goto led to the simplification ofthe language. Break and continue statements can provide the functionality ofgoto in java.Also the concept of operator overloading has been removed from java