JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Implement stack using Linked List in java data structure and algorithm in data structure and algorithm

1:35 AM
Implement stack using Linked List in java data structure and algorithm in data structure and algorithm The stack is an abstract data type that demonstrates Last in first out (LIFO) behavior. We will implement the same behavior using Linked List. There are two most important operations of Stack: Push: We will push elements to the beginning of the linked list to demonstrate the push behavior of the stack. Pop: We will remove the first element of linked list to demonstrate the pop behavior of Stack. Java Program: Let's create a java program to create a stack using Linked List. package org.arpit.java2blog; public class LinkedListStack { private Node head; // the first node // nest class to define linkedlist node private class Node { int value; Node next; } public LinkedListStack() { head = null; } // Remove value from the beginning of the list for demonstrating behaviour of stack public int pop() throws LinkedListEmptyException { if (head

Stack implementation in java data structure and algorithm

1:16 AM
Stack is abstract data type which demonstrates Last in first out (LIFO) behavior. We will implement same behavior using Array. Although java provides implementation for all abstract data types such as Stack,Queue and LinkedList but it is always good idea to understand basic data structures and implement them yourself. Java Program to implement Stack using Array: package org.arpit.java2blog; /**  * @author java Gian  */ public class StackCustom { int size; int arr[]; int top; StackCustom(int size) { this.size = size; this.arr = new int[size]; this.top = -1; } public void push(int pushedElement) { if (!isFull()) { top++; arr[top] = pushedElement; System.out.println("Pushed element:" + pushedElement); } else { System.out.println("Stack is full !"); } } public int pop() { if (!isEmpty()) { int returnedTop = top; top--; System.out.println("Popped element :" + arr[returnedTop]);

Difference between Abstraction and Encapsulation in Java-OOPS

2:41 AM
Abstraction vs Encapsulation in Java; Difference between Abstraction and Encapsulation in Java. Here are some of the main differences between Abstraction vs Encapsulation in Java and OOPS(Object Oriented programming) concept. Abstraction and Encapsulation along with Inheritance and polymorphism form basis of Object-oriented programming in Java. 1) First difference between Abstraction and Encapsulation is that, Abstraction is implemented in Java using interface and abstract class while Encapsulation is implemented using private, package-private and protected access modifier. 2) Encapsulation is also called data hiding. 3) Design principles "programming for interface than implementation" is based on abstraction and "encapsulate whatever changes" is based upon Encapsulation.

What is method overloading in Java with Example

2:26 AM
What is method overloading in Java Method overloading in Java is a programming concept when programmer declares two methods of the same name but with different method signature, e.g. change in the argument list or change in the type of argument. method overloading is a powerful Java programming technique to declare a method which does a similar performance but with a different kind of input. One of the most popular examples of method overloading is System.out.println() method which is overloaded to accept all kinds of data types in Java. You have println() method which takes String, int, float,double or even char in output. All of those methods are collectively referred as an overloaded method in Java. The difference between method overloading and overriding is also a popular Java interview question. In next section, we will some important points about method overloading in Java and then a simple example of how to overload a method in Java. Properties of method overloading in

.