Posts

Showing posts from June, 2016

Java program to check given number is prime number or not

Similar Questions: Prime Numbers Java Example Print prime numbers between 1 and given number using for loop //check to see if the number is prime boolean isPrime = true;                         for(int j=2; j < 10 ; j++){                                                                 if(10 % j == 0){                                         isPrime = false;                                         break;                                 }           ...

Binary search tree implementation using java

Image

Queue(FIFO) implementation using Java

Image
A queue is a collection that is based on the first-in-first-out (FIFO) policy. dequeue() - get an item from the queue. enqueue() - insert item into the queue.

Stack(LIFO) implementation in java (linkedlist)

Image
A stack is a collection that is based on the last-in-first-out (LIFO) policy. push() -  push an item into stack. pop() - get an item and remove it from the top.

Java program to reverse number

Java programming source code class ReverseNumber {    public static void main(String args[])    {       System.out.println("Enter the number to reverse");       int n=54321,       int reverse = 0;       while( n != 0 )       {           reverse = reverse * 10;           reverse = reverse + n%10;           n = n/10;       }       System.out.println("Reverse number is "+reverse);    } }

Tree Preorder Traversal using Java

Image
/* Node is defined as class Node {     int data;     Node left;     Node right; } */

Linked list java implementation

Image
Definition: A linked list is a recursive data structure that is either empty (null) or a reference to a node having a generic item and a reference to a linked list. Structure: Node record: class Node<Item> { Item item; Node next; }

Arithmetic expression evaluation in java

Computing the value of arithmetic expressions like this one:                                                ( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) Which means multiply 4 by 5, add 3 to 2, multiply the result, and then add 1, you get the value 101. But how does the Java system do this calculation? We can address the essential ideas by writing a Java program that can take a string as input (the expression) and produce the number represented by the expression as output. Dijkstra's Two stack Algorithm for Expression Evaluation public class ExpressionEvaluation { public static void main(String args[]){ Stack<String> ops = new Stack<String>(); Stack<Double> ops = new Stack<Double>();

Insert a node at the head of a linked list using Java

/*   Insert Node at the beginning of a linked list   head pointer input could be NULL as well for empty list */ /*   Node is defined as   class Node {      int data;      Node next;   } */ Node Insert(Node head,int x) {     Node node=new Node();     node.data=x;     node.next=head;     return node; }

Java program to check if a number is armstrong or Not

Similar Question:      Print List of Armstrong number. Solution: class armstrong { public static void main(String args[]) { int s=0,n=153,m,d; m=n; while(n>0)

notepad application in java

Similar Question: Notepad application using java source code TextEditor java program Complete Program: import java.awt.*; import java.awt.event.*; import java.awt.datatransfer.*; import java.applet.*; import java.io.*; import javax.swing.*; import javax.swing.undo.*; import java.util.Hashtable; class UndoableTextArea extends TextArea implements StateEditable  {

Java command line arguments importing from a file

Similar Question:        Exporting java output to a different file       How to write console output to a file Solution: Syntex:   

How to highlight a grid row or column in AngularJs

    columnDefs: [       { field: 'name',cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {            if (grid.getCellValue(row,col) === 'xyz') {             return 'blue';           }         }},       { field: 'address',         cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {           if (rowRenderIndex===3) {             return 'blue';           }         }       }     ]

GIT Commands Tutorial

Github Commands  How to get a local Copy                                (Branch                                  Name)               git clone -b master <git master url )>             (EXP-  git clone -b master  https://github.com/xxx/xxx.git)

Java program to get class path file by name

            URL resource = myClass.class.getResource("/PmlConfig.xml");            System.out.println((new File(resource.toURI())).getAbsolutePath()));

Arraylist vs Linked list time complexity

Image
Time complexity of Arraylist and  LinkedList  Time comparison of add(), get(), and remove();

How to download a file using a Java REST service ?

Image
Related Question:      How to zip a folder?      AngularJs / JavaScript to download a file using web service. Solution:  @GET     @Path("/report/download/file/{filename : .+}")     @Produces(MediaType.APPLICATION_OCTET_STREAM)     public Response downloadFilebyPath(@PathParam("filename")  String fileName) {

when to implement finalize method in java

Lot of time JVM takes care of all  garbage collector object. If your java program hold any system resources like (Calendar, File, Thread, Display properties many more) that time you should implement finalize method.

java restful web services @path regular expression

1          The following example shows how regular expression could be used with the @Path annotation.        @Path("users/{username: regular expression}")          Example:         @Path("users/{username: [a-zA-Z][a-zA-Z_0-9]}")         following URL:   http://example.com/users/hello 2                  The @PathParam annotation example         @Path("/users/{username}")         public class User {         @GET          @Produces("text/xml")          public String getUser(@PathParam("username") String              userName) {         System.out.println(userName);         }         }

Inserting a Node at the Tail of a Linked List

/*   Insert Node at the end of a linked list   head pointer input could be NULL as well for empty list   Node is defined as   class Node {      int data;      Node next;   } */

How to Iterating all the Elements of a Linked List in java

/*   Print elements of a linked list   class Node {      int data;      Node next;   }  */   void Print(Node head) {    while(head != null){        System.out.println(head.data);        head = head.next;     } }

Java program to Search sub array inside an array

Same Problems:        Java 2D array Grid Search        Search sub array inside a array        Grid Search        multidimensional array search Example:   m1 = 1 2  5  5 6 5 0            5 2 10 5 6 5 4            9 2 34 0 2 9 6            1 2  5   5 6 5 6            8 2 11 5 6 1 3            9 2 34 0 2 9 2 search array :                 m2 :  0 2 9                          5 6 5                          5 6 1 Solution:

Merging two Sorted Linked List using java

Merge two linked list that are aleady sorted and return a new sorted list. Implement this method : Node MergeLists(Node list1, Node list2){ // your code here } Solution:
java.lang.Exception: Error getting all Data! - No bean named 'transactionManager' is defined  com.Parameters(Resource.java:46)  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  java.lang.reflect.Method.invoke(Method.java:601)  org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)  org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)  org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:172)  org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherPr...