Sunteți pe pagina 1din 4

Advanced Programming Language

DAV Institute of Engineering and Technology, Jalandhar Submitted To: Ms.Raman Kumar Submitted By: Inderpal Singh M.Tech CSE 1stsem Advantages and Disadvantage of Java Programming: Simple:Java was designed to be easy for the professional programmer to learn and use effectively. Assuming that you have some programming experience, you will n ot find Java hard to master. If you already understand the basic concepts of obj ect-oriented programming, learning Java will be even easier. Best of all, if you are an experienced C++ programmer, moving to Java will require very little effo rt. Because Java inherits the C/C++ syntax and many of the object-oriented featu res of C++, most programmers have little trouble learning Java. Java was designe d to be easy to use and is therefore easy to write, compile, debug, and learn th an other programming languages. The reason that why Java is much simpler than C+ + is because Java uses automatic memory allocation and garbage collection where else C++ requires the programmer to allocate memory and to collect garbage. Java i s object-oriented: Object-Oriented: Although influenced by its predecessors, Java was not designed to be source-code compatible with any other language. This allowed the Java team t he freedom to design with a blank slate. One outcome of this was a clean, usable , pragmatic approach to objects. Borrowing liberally from many seminal object-so ftware environments of the last few decades, Java manages to strike a balance be tween the purists everything is an object paradigm and the pragmatists stay out of my way model. The object model in Java is simple and easy to extend, while primitiv e types, such as integers, are kept as high-performance no objects. Robust: The multiplatformed environment of the Web places extraordinary demands on a program, because the program must execute reliably in a variety of systems. T hus, the ability to create robust programs was given a high priority in the desi gn of Java. To gain reliability, Java restricts you in a few key areas to force you to find your mistakes early in program development. At the same time, Java f rees you from having to worry about many of the most common causes of programmin g errors. Because Java is a strictly typed language, it checks your code at comp ile time. However, it also checks your code at run time. Many hard-to-track-down bugs that often turn up in hard-to-reproduce run-time situations are simply imp ossible to create in Java. Knowing that what you have written will behave in a p redictable way under diverse conditions is a key feature of Java. To better understand how Java is robust, consider two of the main reasons for pr ogram failure: memory management mistakes and mishandled exceptional conditions (that is, run-time errors). Memory management can be a difficult, tedious task i n traditional programming environments. For example, in C/C++, the programmer mu st manually allocate and free all dynamic memory. This sometimes leads to proble ms, because programmers will either forget to free memory that has been previous ly allocated or, worse, try to free some memory that another part of their code is still using. Java virtually eliminates these problems by managing memory allo cation and deallocation for you. (In fact, deallocation is completely automatic, because Java provides garbage collection for unused objects.) Exceptional condi tions in traditional environments often arise in situations such as division by zero or file not found, and they must be managed with clumsy and hard-to-read cons tructs. Java helps in this areaby providing object-oriented exception handling. In a well-written Java program, all run-time errors canand shouldbe managed by you r program. Multithreaded:Java was designed to meet the real-world requirement of creating i nteractive, networked programs. To accomplish this, Java supports multithreaded

programming, which allows you to write programs that do many things simultaneous ly. The Java run-time system comes with an elegant yet sophisticated solution fo r multiprocess synchronization that enables you to construct smoothly running in teractive systems. Javas easy-to-use approach to multithreading allows you to thi nk about the specific behavior of your program, not the multitasking subsystem. Architecture-Neutral:A central issue for the Java designers was that of code lon gevity and portability. One of the main problems facing programmers is that no g uarantee exists that if you write a program today, it will run tomorroweven on th e same machine. Operating system upgrades, processor upgrades, and changes in co re system resources can all combine to make a program malfunction. The Java desi gners made several hard decisions in the Java language and the Java Virtual Mach ine in an attempt to alter this situation. Their goal was write once; run anywher e, any time, forever. To a great extent, this goal was accomplished. Interpreted and High Performance: As described earlier, Java enables the creatio n of cross-platform programs by compiling into an intermediate representation call ed Java bytecode. This code can be executed on any system that implements the Java Virtual Machine. Most previous attempts at cross-platform solutions have done s o at the expense of performance. As explained earlier, the Java bytecode was car efully designed so that it would be easy to translate directly into native machi ne code for very high performance by using a just-in-time compiler. Java run-tim e systems that provide this feature lose none of the benefits of the platform-in dependent code. Java Run Time Environment Distributed:Java is designed for the distributed environment of the Internet bec ause it handles TCP/IP protocols. In fact, accessing a resource using a URL is n ot much different from accessing a file. Java also supports Remote Method Invoca tion (RMI). This feature enables a program to invoke methods across a network. Dynamic:Java programs carry with them substantial amounts of run-time type infor mation that is used to verify and resolve accesses to objects at run time. This ma kes it possible to dynamically link code in a safe and expedient manner. This is crucial to the robustness of the Java environment, in which small fragments of bytecode may be dynamically updated on a running system. Disdvantages of JAVA Programming: The main disadvantage of Java is speed.Although Java s ability for producing por table, architecturally neutral code is desirable, the method used to create this code is inefficient. As mentioned above, once Java code is compiled into byte c ode, an interpreter called a Java Virtual Machine, specifically designed for a c omputer architecture, runs the program. Why is this a problem? "Java, being an i nterpreted system, is currently an order of magnitude slower than C." (Just Java , 302). Unlike natively compiled code, which is a series of instructions that co rrelate directly to a microprocessors instruction set, an interpreter must first translate the Java binary code into the equivalent microprocessor instruction. Obviously, this translation takes some amount of time and, no matter how small a length of time this is, it is inherently slower than performing the same operat ion in machine code. It is difficult to compile into a stand-alone application. Memory pointers are n ot allowed.

SPACE COMPLEXITY Space Complexity:Space complexity is measured by using polynomial amounts of mem ory, with an infinite amount of time. The difference between space complexity and time complexity is that space can be reused. Space complexity is not affected by determinism or nondeterminism. Amount of computer memory required during the program execution, as a function o f the input size a small amount of space, deterministic machines can simulate no ndeterministic machines, where as in time complexity, time increase exponentiall

y in this case. A nondeterministic TM using O(n) space can be changed to a deter ministic TM using only O2(n) space. Example of binary search Code for binary search in c programming language #include<stdio.h> int main(){ int a[10],i,n,m,c=0,l,u,mid; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements in ascending order: "); for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("Enter the number to be search: "); scanf("%d",&m); l=0,u=n-1; while(l<=u){ mid=(l+u)/2; if(m==a[mid]){ c=1; break; } else if(m<a[mid]){ u=mid-1; } else l=mid+1; } if(c==0) printf("The number is not found."); else printf("The number is found."); return 0; } Sample output: Enter the size of an array: 5 Enter the elements in ascending order: 4 7 8 11 21 Enter the number to be search: 11 The number is found. Here a more mathematical way of seeing it The question is, how many times can you divide N by 2 until you have 1? This is essentially saying, do a binary search (half the elements) until you found it. I n a formula this would be this: 1 = N / 2x multiply by 2x: 2x = N now do the log2: log2(2x) = log2 N

x * log2(2) = log2 N

x * 1 = log2 N this means you can divide log N times until you have everything divided. Which m eans you have to divide log N ("do the binary search step") until you found your element. A binary search works by dividing the problem in half repeatedly, someth ing like this (details omitted): Example looking for 3 in [4,1,3,8,5] 1. Order your list of items [1,3,4,5,8] 2. Look at the middle item (4), If it is what you are looking for, stop If it is greater, look at the first half If it is less, look at the second half 3. Repeat step 2 with the new list [1, 3], find 3 and stop It is a binary search when you divide the problem in 2. The search only requires log2 (n) steps to find the correct value.

Ques3. How to calculate communication overhead? Ans. Overhead is generally considered any combination of excess or indirect comp utation time, memory, bandwidth, or other resources that are required to attain a particular goal. It is a special case of engineering overhead. For example, an algorithm which caches results for quick retrieval has the overh ead of maintaining the cache memory. In terms of Algorithmic efficiency, overhea d is often a term which is asymptotic but irrelevant. In essence, extra memory or taken CPU cycles which may or may not be considered necessary to accomplish a specific computational task.

S-ar putea să vă placă și