Skip to main content

Posts

Showing posts with the label Java

Finding the sub-array with the largest sum.

Question: You are given an array with integers (both positive and negative) in any random order. Find the sub-array with the largest sum. Answer: This is an all-time favorite software interview question. The best way to solve this puzzle is to use Kadane’s algorithm which runs in O(n) time. The idea is to keep scanning through the array and calculating the maximum sub-array that ends at every position. The sub-array will either contain a range of numbers if the array has intermixed positive and negative values, or it will contain the least negative value if the array has only negative values. Here’s some code to illustrate.   void maxSumSubArray( int *array, int len, int *start, int *end, int *maxSum ) { int maxSumSoFar = -2147483648; int curSum = 0; int a = b = s = i = 0; for( i = 0; i < len; i++ ) { curSum += array[i]; if ( curSum > maxSumSoFar ) { maxSumSoFar = curSum; a = s; b = i; ...

Head First Java 2nd Edition - Popular Book

  Rs. 625 This is a book that is tailored for Java novices. Ideal for those who are interested in learning Java but have been put off by the complexities of learning the language, Head First Java explores a new way of teaching the same. Head First Java is aimed at people who are complete novices when it comes to programming with the language, and the book makes the learning experience fun - one that?s filled with innovative and novel measures. If you?re not a fan of wracking your brain with dull theoretical concepts that put you to sleep, Head First Java can be a welcome addition to your shelf. The book starts from the fundamentals and progresses to extremely advanced levels, employing an easy-to-learn approach throughout. From distributed programming with RMI and network sockets, object oriented design, and object properties and methods, to graphical user interfaces, Java archives, network connectivity and Java 5.0, the book explores every facet of th...

Java knowledge for android

The Java programming language is one of the glorious tools that make programming Android a breeze compared with programming for other mobile platforms. Whereas other languages insist that you manage memory, deallocate and allocate bytes, and then shift bits around like a game of dominoes, Java has a little buddy called the Java Virtual Machine (JVM) that helps take care of that for you. The JVM allows you to focus on writing code to solve a business problem by using a clean, understandable programming language (or to build that next really cool first-person shooter game you’ve been dreaming of) instead of focusing on the plumbing just to get the screens to show up. You’re expected to understand the basics of the Java programming language before you write your first Android application . If you’re feeling a bit rusty and need a refresher course on Java, you can visit the Java tutorials site at http://java.sun.com/docs/books/tutorial . or you can find some tutorial here - JAVA ...

Cafe Babe? Or, what's in a name?

    The name Java is not an acronym. In particular, it does not stand for Just Another Vague Acronym . The language was originally called Oak, but the language lawyers worried about the name Oak Technology (at the time a maker of video cards). So a meeting was held (varying accounts of that meeting were gathered up by JavaWorld) , and the name Java made the short list. The language lawyers approved, and the rest is history. Most kinds of executable file formats have some kind of "magic number" that identifies them. For example, old PDP-11 executables for the UNIX system used the "magic number" 0407 (the real magic there, and the putative origin of the term, is that 0407 was a machine instruction for a jump forward of 7 words, i.e., past the 8-word-long executable header, to the first executable statement in the program). Some versions of the Berkeley UNIX memory allocator use the hexadecimal string 0xDEADBEEF, which is considered unlikely to occur in normal o...

Top Ten Things Every Java Programmer Should Know

These are in no particular order, but these are things that all Java programmers should probably know. Who Invented Java, and when? James Gosling, at Sun Labs, around 1992; the group was building a set-top box and started by "cleaning up" C++ and wound up with a new language and runtime. What does Java stand for? Java is not an acronym (not even Just Another Vague Acronym :-)). The language was first named Oak, after the tree outside James' window. The lawyers found another language called Oak so, legend has it, the gang went out to the local cafe to discuss names and wound up naming it after the beverage Java (which is in turn named after the island of Java). Possible confirmation of this theory . What is the JLS? JLS is The Java Language Specification. Every developer should buy or download (free) this specification and read it, a bit at a time. How do changes get into Java? JCP (Java Community Process) . Why is there no printf-like f...

In Java, what’s the difference between method overloading and method overriding?

The difference between overriding and overloading in Java is a common source of confusion – but it is fairly simple to understand. Let’s start the discussion by talking more about method overloading. Overloading in Java can occur when two or more methods in the same class share the same name or even if a child class shares a method with the same name as one of it’s parent classes. But, in order to actually have overloaded methods, the methods not only have to have the same name, but there are other conditions that must be satisfied – read below to see what those conditions are. Suppose we have a class called TestClass which has 2 methods, and both methods have the same name – let’s say that name is “someMethod” – this would be considered to be method overloading if    at least one of these 2 things is true: 1.) The number of parameters is different for the methods 2.) The parameter types are different. ...

What is method overriding in java?

About method overriding: Overriding methods is completely different from overloading methods. If a derived class requires a different definition for an inherited method, then that method can be redefined in the derived class. This would be considered overriding. An overridden method would have the exact same method name, return type, number of parameters, and types of parameters as the method in the parent class, and the only difference would be the definition of the method. Let’s summarize the differences between overloading and overriding. When overloading, one must change either the type or the number of parameters for a method that belongs to the same class. But, overriding a method means that a method inherited from a base class is what’s being changed.

Is the JVM (Java Virtual Machine) platform dependent? What is the advantage of using the JVM, and having Java be a translated language?

JVM translates bytecode into machine language Every Java program is first compiled into an intermediate language called Java bytecode. The JVM is used to both translate the bytecode into the machine language for a particular computer, and actually execute the corresponding machine-language instructions as well. The JVM and bytecode combined give Java its status as a "portable" language – this is because Java bytecode can be transferred from one machine to another. Machine language is OS dependent Given the previous information, it should be easier to figure out an answer to the original question. Since the JVM must translate the bytecode into machine language, and since the machine language depends on the operating system being used, it is clear that the . The key here is that the JVM depends on the operating system – so if you are running Mac OS X you will have a different JVM than if you are running Windows or some other operating system....

In Java, how does System.out.println() work?

This question is an excellent example of how just some very basic knowledge of Java can lead you to the correct answer. Most interviewers would not expect you to know the answer to do this right away – but would like to see how you think and arrive at an answer. Marcus Aurelius once said: "Of each particular thing ask: what is it in itself? What is its nature?". This problem is an excellent example of how that sort of thinking can help one arrive at an answer with only some basic Java knowledge. With that in mind, let’s break this down, starting with the dot operator. In Java, the dot operator can only be used to call methods and variables so we know that ‘out’ must be either a method or a variable. Now, how do we categorize ‘out’? Since println() is clearly a method, and its called using ‘out’, then we know that ‘out’ can not possibly be a method because it doesn’t make sense to have one method invoke another method with the dot operator in Java. This means ‘out’ must be a ...

Advanced JAVA – Technical interview questions

In last post we have seen Core Java Based Interview Questions now lets see some Questions based on Advanced Java Technical Interview Question On Advanced Java If you are truncated using JDBC , how can you that how much data is truncated? How will you perform truncation using JDBC? What is the latest version of JDBC? What are the new features added in that? What is the difference between RMI registry and OS Agent? To a server method, the client wants to send a value 20, with this value exceeds to 20 a message should be sent to the client . What will you do for achieving this? How do you invoke a Servelet? What is the difference between doPost method and doGet method? What is difference between the HTTP Servelet and Generic Servelet? Explain about their methods and parameters? Can we use threads in Servelets? What is RMI? Explain about RMI Architecture? What are Servelets? What is the order of method invocation in an Applet? What is ODBC and JDBC? How do you connect the Database? Wh...

JAVA – Technical interview questions

JAVA – Technical interview questions When will you use an interface and abstract class? What is the exact difference in between Unicast and Multicast object? Where will it be used? What is the main functionality of the remote reference layer? How do you download stubs from Remote place? I want to store more than 10 objects in a remote server? Which methodology will follow? What is the main functionality of Prepared Statement? What is meant by Static query and Dynamic query? What are Normalization Rules? Define Normalization? What is meant by Servelet? What are the parameters of service method? What is meant by Session? Explain something about HTTP Session Class? In a container there are 5 components. I want to display all the component names, how will you do that? Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA? Tell some latest versions in JAVA related areas? What is meant by class loader? How many types are there? When will we use them? ...

Fundamental Building Blocks of Programs

T here are two basic aspects of programming: data and instructions. To work with data, you need to understand variables and types ; to work with instructions, you need to understand control structures and subroutines . You'll spend a large part of the course becoming familiar with these concepts. A variable is just a memory location (or several locations treated as a unit) that has been given a name so that it can be easily referred to and used in a program. The programmer only has to worry about the name; it is the compiler's responsibility to keep track of the memory location. The programmer does need to keep in mind that the name refers to a kind of "box" in memory that can hold data, even if the programmer doesn't have to know where in memory that box is located. In Java and in many other programming languages, a variable has a type that indicates what sort of data it can hold. One type of variable might hold integers -- whole numbers such as ...

What is Java Virtual Machine (JVM)

--------------Note on JavaVirtual Machine-------------- • The Java Language runs on a “Java Virtual Machine” – Java Virtual machine abstracts away the details of theunderlying platform and provides a uniform environment for executing Java“byte-code” • The Java compiler (javac) compiles Java code intobyte-code – Bytecode is an intermediate form which can run on theJVM – JVM does the translation from byte-code to machine-codein a platform dependent way.

Explain Difference between Java and C++

C++ Java C++ is a complex language Java is Simple Language C++ has signed and unsigned data types By default, all data types in java are signed( Exception char) Characters in C++ are 8 bit and 16 bit chars are represented by wide character types By default all the characters 16 bit and supports Unicode C++ supports pointers and pointer arithmetic No low-level pointers or pointer arithmetic. Instead have variables and expressions of reference type. Objects needs to be deallocated explicitly using destructors Objects are Garbage collected automatically Variables can be used before its initialization No Variable can be used before its initialization Array bounds are not checked by default Strict array bounds checking No built in support for multithreading. Built in support for multithreading Struct,union , typedef available No struct, union, typedef—classes and objects are used uniformly instead. C++ platform dependent Java is platform independent and machine independent C++ is...

Explain Features of Java - Introduction

1) Simple • Similar to C/C++ in syntax • But eliminates several complexities of – No operator overloading – No direct pointer manipulation or pointer arithmetic – No multiple inheritance – No malloc() and free() – handles memory automatically – Garbage Collector • Lots more things which make Java more attractive. 2) Object-Oriented • Fundamentally based on OOP – Classes and Objects – Uses a formal OOP type system – Lends an inherent structure/organization for how wewrite Java programs • Unlike spaghetti code in languages like Perl – Efficient re-use of packages such that the programmeronly cares about the interface and not the implementation 3) Distributed / Network Oriented • Java grew up in the days of the Internet – Inherently network friendly – Original release of Java came with Networking libraries – Newer releases contain even more for handlingdistributed applications...

JAVA Tutorial 1- Introduction to Java

•          Java was developed by James Gosling at Sun Microsystems in 1991. •          His Original Aim was to develop a low cost, Hardware Independent Language based on C++. •          Due to technical reasons that idea was dropped. •          A new programming Language called Oak was developed based on C++. •          The language oak was developed by removing undesirable features of C++. •          Those features include: •          Multiple Inheritance •          Automatic type conversions •          Use of pointers •          Memory Management. •    ...

Simple Java Template Engine

Template engines are widely used in Web Frameworks, such as Struts, JSF and many other technologies. Apart from classical Web Framework, template engines can be very useful in integration projects. In an actual integration project that deals with a lot of XML data exchange, I discovered the Java Template Engine Library FreeMarker. This Open Source Library is a generic template engine in order to generate any output, such as HTML, XML and any other user defined output based on your given template. "[...]FreeMarker is designed to be practical for the generation of HTML Web pages , particularly by servlet-based applications following the MVC (Model View Controller) pattern. The idea behind using the MVC pattern for dynamic Web pages is that you separate the designers (HTML authors) from the programmers. Everybody works on what they are good at. Designers can change the appearance of a page without programmers having to change or reco...

Mobile Computing Application Development - Java Platform

Java Based Integrated Application Development Tools On server Side -  Java has become a standard dominant language for server-side programming. Java makes it easier to write safe, reliable code through features, such as automatic memory management and structured exception-handling. A large set of APIs and cross-platform design provide power and portability. Sun has announced significant enhancements for mobile computing and interfaces to wireless networks. Several application servers support Java interfaces. J2EE - Java Second Version Enterprise Environment Development - Go here Java (J2ME) Application Development On Client Side- Go here Java Application Development Enhancement Products - Go here

Mobile Computing & Wireless Application Development - Java Enhancement Products -

Jeode PDA Edition Jeode™ PDA Edition is an implementation of the Insignia's Java virtual machine environment that is tailored for the limited memory resources and browsing requirements of Pocket PCs, PDAs and related handheld devices. Jeode PDA Edition is the first in a series of planned announcements to support Insignia's mobile wireless initiative. Insignia is also aggressively pursuing initiatives for the interactive television and automotive markets. Jeode PDA Edition supports Insignia's claim as the leading provider of Java virtual machine (JVM) technologies for the fast-growing Windows CE and Linux PDA market segments. It incorporates the Jeode EVM™ runtime engine, a "Sun Authorized Virtual Machine " that is fully compatible with the PersonalJava™ specification, and supports all PersonalJava 1.2 class libraries, including optional classes. Jeode Platform  The Jeode platform enables accelerated and robust Java functionality on informat...

Mobile Computing & Wireless Application Development - J2ME -

Wireless application development has the following characteristics: multi-platform and multi-device support, since no single device can serve entire organization's needs multi-RF network support multi-backend application and database support integration with web application server platforms While several different device platforms are being promoted by major device vendors, such as  PalmOS, Microsoft Windows CE, PocketPC and Sambian's EPOC, Motorola and Lutris Technologies (a Santa Cruz, California company) have teamed up to offer Java-based development platform for iDEN handsets. They duo have decided to bundle Lutris' open-source Enhydra application server with Motorola's SDK for iDEN. With this set of Enhydra and J2ME (Java 2 Micro Edition), programmers can develop both server-side and client-side software that takes advantage of Sun's J2ME specifications. ...