Postingan

Menampilkan postingan dengan label coding

Top 5 Books for Programming/Coding Interviews - Best of lot

If you are preparing for Programming Job interviews and looking for some of the best books for programming questions then you have come to the right place. In this article, I am going to share a couple of good books to prepare coding, software design, and data structure algorithm questions, which are essential for any coding interviews. Though a programming interview also explores other areas of software development e.g. the programming language you would be mainly using in your project e.g. C++ or Java. The database and SQL based questions, the operating systems and UNIX related questions, some of the software design and object oriented design pattern questions and much more, but coding based questions forms the core of programming interviews. Read more �

Membuat Grafik 3D

Jika pada posisi perintah sebagaimana contoh ke-tiga dari rangkaian ini dipanggil: make_3Dbar_graph, maka akan diperoleh grafik batang 3D. prosedur ini memanfaatkan sebuah rangkaian titik sebagaimana membuat diagram garis. perhatikan, bahwa untuk ke titik lebih atas, y harus dikurang, dan saya menggunakan pengurang sebesar 2 satuan pixel. “bayang-bayang” gambar diletakkan di sebelah kanan. Perhatikan prosedur untuk membuat gambar 3D berikut: procedure make_3dbar_graph; var k,x1,y1,x2,y2:integer; begin //w:= 4; //4 pixel for k:= 1 to length(GraphPoints)-1 do begin x1:= GraphPoints[k].X-3; x2:= GraphPoints[k].X+3; y1:= GraphPoints[k].Y; y2:= MostBottom; cv.Rectangle(x1,y1,x2,y2) ; // cv.polyline([point(x1,y1),point(x1+2,y1-2),point(x2+2,y1-2),point(x2,y1)]); cv.Polyline([point(x2,y1),point(x2+2,y1-2),point(x2+2,y2-2),point(x2,y2)]); end; end;

DRAG FILES KE FORM DELPHI

1.  unit Unit1; 2.  interface 3.  uses 4.    Windows, Messages, SysUtils, Classes, 5.    Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls, jpeg, 6.    OleCtrls, SHDocVw; 7.  type 8.    TForm1 = class(TForm) 9.      Image1: TImage; 10.      ListBox1: TListBox; 11.      WebBrowser1: TWebBrowser; 12.      procedure FormCreate(Sender: TObject); 13.    private 14.      { Private declarations } 15.    public 16.      { Public declarations } 17.      // mendeklarasikan procedure acceptfiles 18.      procedure AcceptFiles(var msg: TMessage); 19.        message WM_DROPFILES; 20.      end; 21.  var 22. ...

How to Reverse Array in Java - Int and String Array Example

This Java tips is about, how to reverse array in Java, mostly primitive types e.g. int , long , double and String arrays. Despite of Java�s rich Collection API, use of array is quite common, but standard JDK doesn�t has great utility classes for Java. It�s difficult to convert between Java Collection e.g. List , Set to primitive arrays. Java�s array utility class java.util.Arrays , though offers some of critical functionalities like comparing arrays in Java and support to print arrays , It lacks lot of common features, such as combining two arrays and reverse primitive or object array. Thankfully, Apache commons lang, an open source library from Apache software foundation offers one interesting class ArrayUtils, which can be used in conjunction with java.util.Arrays class to play with both primitive and object array in Java. This API offers convenient overloaded method to reverse different kinds of array in Java e.g. int, double, float, log or Object arrays. On a similar note,...

How to create Immutable Class and Object in Java - Tutorial Example

Writing or creating immutable classes in Java is becoming popular day by day, because of concurrency and multithreading advantage provided by immutable objects. Immutable objects offers several benefits over conventional mutable object, especially while creating concurrent Java application. Immutable object not only guarantees safe publication of object�s state, but also can be shared among other threads without any externa l synchronization . In fact JDK itself contains several immutable classes l ike String , Integer an d other wrapper classes. For those, who doesn�t know what is immutable class or object, Immutable objects are those, whose state can not be changed once created e.g. java.lang.String , once created can not be modified e.g. trim, uppercase, lowercase. All modification in String result in new object, see why String is immutable in Java for mor e details. In this Java programming tutorial, we will learn, how to write immutable class in Java or how to make a class immu...

2 ways to combine Arrays in Java � Integer, String Array Copy Example

There are multiple ways to combine or join two arrays in Java, both for primitive like int array and Object e.g. String array. You can even write your own combine() method which can use System.arrayCopy() to copy both those array into the third array. But being a Java developer, I first looked in JDK to find any method which concatenates two arrays in Java. I looked at java.util.Arrays class, which I have used earlier to compare two arrays and print arrays in Java , but didn't find a direct way to combine two arrays. Then I looked into Apache Commons, ArrayUtils class, and bingo, it has several overloaded method to combine int , long , float , double or any Object array. Later I also found that Guava ,earlier known as Google collections also has a class ObjectArrays in com.google.common.collect the package, which can concatenate two arrays in Java. It's always good to add Apache commons and Guava , as supporting library in Java project, they have lots of supporting clas...

How to Swap Two Numbers without Temp or Third variable in Java - Interview Question

How to swap two numbers without using temp or third variable is common interview question not just on Java interviews but also on C and C++ interviews. It is also a good programming questions for freshers . This question was asked to me long back and didn't had any idea about how to approach this question without using temp or third variable, may be lack of knowledge on bitwise operators in Java or may be it didn't click at that time. Given some time and trial error, I eventually come out with a solution with just arithmetic operator but interviewer was keep asking about other approaches of swapping two variables without using temp or third variable . Personally, I liked this question and included in list o f my programming interview question bec ause of its simplicity and some logical work, it force you to do. When learned bit-wise operation in Java I eventually find another way of swapping two variables without third variable, which I am going to share with you guys. Read m...

How to convert XMLGregorianCalendar to Date to XMLGregorianCalendar in Java - Example Tutorial

There are several ways to convert XMLGregorianCalendar to Date in Java. You can convert XMLGregorianCalendar to either java.util.Date or java.sql.Date based upon your need . JAXB (Java API/Architecture for XML Bindings) is a popular framework to create XML documents from Java Objects and Java objects from XML files. JAXB also helps to create Java classes from XML Schema file (.XSD file). By default JAXB maps XSD data type xs:date , xs:time and xs:dateTime to XMLGregorianCalendar in Java, but you can configure XJC to create java.util.Date objects instead of javax.xml.datatype.XMLGregorianCalendar . Sin ce java.util.Date is most popular way of dealing with date and time in Java, we often need to convert XMLGregorianCalendar instance to Date instance in Java. Thankfully by using Java API, we can easily do this conversion of XMLGregorianCalendar to Date and Date to XMLGregorianCalendar in Java. By the way, It's good to remember that XML Schema has three different types wh...

How to add leading zeros to Integers in Java � String left padding Example Program

From Java 5 onwards it's easy to left pad Integers with leading zeros when printing number as String. In fact, You can use the same technique to left and right pad Java String with any characters including zeros, space. Java 5 provides String format methods to display String in various format. By using format() method we can add leading zeros to any Integer or String number. By the way, this is also known as left padding Integers with zero in Java . For those who are not familiar with left and right padding of String, here is a quick recap; When we add characters like zero or space on left of a String, its known as left padding and when we do the same on the right side of String, it's known as right padding of String. This is useful when you are displaying currency amounts or numbers, which has fixed width, and you want to add leading zeros instead of space in front of Integers. Read more �

5 JSTL Core IF Tag Examples in JSP - Tutorial

<c:if> or if tag of JSTL core tag library in JSP is one of the most versatile and useful tag. JSTL if tag allows you to test for a condition, like checking for a particular parameter in requestScope , sessionScope or pageScope . You can also check any parameter in request parameters and headers or can check for a variable in JSP page using <c:if> tag. JSTL if tag helps a lot to reduce amount of Java code from JSP page and if used, along with expression language JSTL core tag library, can remove almost all Java code from JSP files. Earlier we have seen examples o f JSTL foreach tag and JSTL core set tag an d this JSP JSTL tutorial is based on if tag of JSTL core tag library. We will, see how to use <core:if> tag inside JSP files and different example of <core:if> tag to get ourselves familiar with functionality and power offered by JSTL <c:if> tag. After seeing these examples of <core:if> tag along with expression language, You will be amazed...

How to convert JSON String to Java object - Jackson Example

JSON stands for JavaScript object notation, is a lightweight text or string representation of an object and quickly becoming a popular data exchange format. Though it's pretty early to say that JSON is going to replace XML as popular data interchange format, It is certainly providing an alternative. JSON represent data in two format either an object or an array. JSON object is an unordered collection of key and value, similar to String representation of hash table . On the other hand, JSON Array is an ordered collection of values. The main difference between JSON Object and JSON array is there representation. JSON object is started with left brace { and ends with right brace } and key values are separated using a colon (:) . On the other hand, JSON Array starts with left bracket [ and ends with right bracket ] and each value is separated by comma . By looking at structure, You can write your JSON parser to parse JSON object or array to Java object, but you don't ne...

How to disable submit button in HTML JavaScript to prevent multiple form submission

Avoiding multiple submission of HTML form or POST data is common requirement in Java web application. Thankfully, You can prevent multiple submission by disabling submit button in HTML and JavaScript itself, rather than handling it on server side. This is very common requirement while developing web application using Servlet and JSP or any other web technology. At same time there are lot of information and noise available in web and its very hard to find simple approach to disable submit button. When I search for simple way to disable submit button in HTML and JavaScript , I was overwhelmed by responses on forums and various online community. Those are good for intermediate HTML and JavaScript developer but a beginner might just get overwhelmed by amount of information presented and rather confused to use which approach will work, how exactly should I disable submit button to prevent multiple form submissions etc. That drives me to write this post and summarize the simplest possib...

5 ways to check if String is empty in Java - examples

String in Java is considered empty if its not null and it�s length is zero. By the way before checking length you should verify that String is not null because calling length() method on null String will result in java.lang.NullPointerException . Empty String is represented by String literal �� . Definition of empty String may be extended to those String as well which only contains white space but its an specific requirement and in general String with white space are not considered as empty String in Ja va. Since String is one of the most frequently used class and commonly used in method arguments, we often needs to check if String is empty or not. Thankfully there are multiple ways to find if String is empty in Java or not . You can also count number of characters in String, as String is represented as character array a nd decide if String is empty or not. If count of characters is zero than its an empty String. In this Java String tutorial we going to see 5 ways to find if any S...

How to check if a Number is Positive or Negative in Java - Interview Question

Write a Java program to check if a number is positive or negative is one of the popula r Java coding interview questions , it may look easy but programmers often fumble on this question. One of the tricky parts of this question is that Java has multiple data type to support numbers like byte , short , char , int , long , float and double, out of those all are signed except char, which can not represent negative numbers. Some solution work for int and long but may not work for floating point number e.g. float and double . This is also a tricky Java question , a nother tricky point is considering special cases like positive infinity, negative infinity or NaN in the case of checking floating point numbers. Things get more complicated when, as follow-up questions, interviewer put additional conditions such as you can not use relational operator etc. Nevertheless, Java provides several way to check if a number whether integer or floating point is positive or negative. In this Java tut...

Method and Constructor Overloading Best Practices in Java

You need to be careful while overloading a method in Java, especially after the introduction of autoboxing in Java 5. Poorly overloaded method not only adds confusion among developers who use that but also they are error prone and leaves your program on compiler's mercy to select proper method. One of the best examples of a poorly overloaded method is the remove method of ArrayList . There are two versions of remove, first, one which takes an Object as argument i.e. remove(Object element) and the second one, which takes an index as argument i.e. remove(int index) . It worked fine until Java 1.4 where there is clearly a distinction between primitive types and objects type but in Java 1.5, where you can pass an int primitive to a method which accepts an Integer object, creates some nasty problem. Read more �

How to compare Arrays in Java � Equals vs deepEquals Example

java.util.Arrays class provides equals() and deepEquals() method to compare two Arrays in Java. Both of these are overloaded method to compare primitive arrays e.g. int, long, float, double and Object arrays e.g. Arrays.equals(Object[] , Object[]). Arrays.equals() returns true if both Arrays which it is comparing are null If both arrays pointing to same Array Object or they must be of the same length and contains the same element in each index. In all other cases, it returns false. Arrays.equals() calls equals() method of each Object while comparing Object arrays. One of the tricky question in Java related to Array comparison is Difference between Arrays.equals() and Arrays.deepEquals() method. Since both equals and deepEquals is used for array comparison, what is the difference between them becomes important. The short answer of this questions is that, Array's equals() method does not perform deep comparison and fails logical comparison in case of nested Array, on o...

How to find middle element of LinkedList in Java in one pass

How do you find middle element of LinkedList in one pass is a programming question often asked Java and non-Java programmers in telephonic Interview. This question is similar to checking palindrome or calculating the factorial , where Interviewer sometimes also ask to write code. In order to answer this question candidate must be familiar with LinkedList data structure i.e. In the case of singly LinkedList, each node of Linked List contains data and pointer, which is the address of next Linked List and the last element of Singly Linked List points towards the null. Since in order to find middle element of Linked List you need to find the length of LinkedList, which is counting elements till end i.e. until you find the last element of Linked List. What makes this data structure Interview question interesting is that you need to find middle element of LinkedList in one pass and you don�t know the length of LinkedList. This is where candidates logical ability puts into the test, whet...

Recursion in Java with example � Programming Techniques Tutorial

Recursion is one of the tough programming technique to master. Many programmers working on both Java and other programming languages like C or C++ struggles to think recursively and figure out the recursive pattern in the problem statement, which makes it is one of the favorite topics of any programming interview . If you are new in Java or just started learning Java programming language and you are looking for some exercise to learn the concept of recursion than this tutorial is for you. In this programming tutorial, we will see a couple of example of recursion in Java programs and some programming exercise which will help you to write recursive code in Java e.g. calculating Factorial , reversing String and printing Fibonacci series using recursion technique. For those who are not familiar with recursion programming technique here is the short introduction: "Recursion is a programming technique on which a method call itself to calculate result". It's not as simple as i...

How to check if a number is a palindrome or not in Java - Example

How to check if a number is a palindrome or not is a variant of popular String interview question how to check if a String is a palindrome or not. A number is said to be a palindrome if number itself is equal to reverse of number e.g. 313 is a palindrome because reverse of this number is also 313. On the other hand 123 is not a palindrome because reverse of 123 is 321 which is not equal to 123, i.e. original number. In order to check if a number is a palindrome or not we can reuse the logic of How to reverse number in Java . Since in most of interview, you are supposed to solve this question without taking help from API i.e. only using basic programming construct e.g. loop, conditional statement, variables, operators and logic. I have also seen programmer solving this question by first converting integer to String and than reversing String using reverse() method of StringBuffer and than converting String back to Integer, which is not a correct way because you are using Java API. So...

Inner class and nested Static Class in Java with Example

Inner class and nested static class in Java both are classes declared inside another class, known as top level class in Java. In Java terminology, If you declare a nested class static, it will called nested static class in Java while non static nested class are simply referred as Inner Class. Inner classes are also a popular topic in Java interviews. One of the popular question is difference between inner class and nested static class , some time also refereed as difference between static and non static nested class in Java. One of the most important question related to nested classes are Where should you use nested class in Java? This is one of the tricky Java question, If you have read Effective Java from Joshua Bloch than in one chapter he has suggested that if a class can only be useful to one particular class, it make sense to keep that inside the class itself otherwise declare it as top level class. Nested class improves Encapsulation and help in maintenance. I actually look J...