Stats

Wednesday, 6 June 2018

Building Java Project ant using build.xml

Building Java Project ant using build.xml


Create a build.xml for your project
Sample build.xml




****************************************************************************************
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." name="TS">
 <property environment="env" />
 <property name="debuglevel" value="source,lines,vars" />
 <property name="target" value="1.6" />
 <property name="source" value="1.6" />
 <path id="TS.classpath">
         <pathelement location="bin" />
  <!-- other external jar entries -->
 </path>
 <path id="run.TSExecutor.classpath">
         <path refid="TS.classpath" />
 </path>
 <target name="showprops"> </target>
 <target name="init"> </target>

 <target name="build-jar">
            <jar destfile="tsRunner.jar" basedir="bin">
            </jar>
 </target>

</project>
****************************************************************************************





Follow path Window -> Show View -> Other -> Search ant and select ant
Drag and drop build.xml by choosing from Project Explorer into Ant View selected above
Right Click on build.xml in ant editor and select run configurations
Set target as one of allowed targets (e.g. here init or showprops as in build.xml), build.xml location and jre , classpath in run configurations
Click run for running the specified targets

Monday, 21 May 2018

My JavaScript Work :


Generating Custom Java class using JavaScript with Underscore Template and JSON Data :
https://codepen.io/iamsagarbha/post/testpost
Jquery Tab Widget Trial
https://liveweave.com/M8unj6

Click on "Book" in Menu Items in second occurrence
https://liveweave.com/Qm8g1Y

Thursday, 8 March 2018

Adding Google Sign In to Your Web Application Code

<script src="https://apis.google.com/js/platform.js" async defer></script>

<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">

<div class="g-signin2" data-onsuccess="onSignIn"></div>

function onSignIn(googleUser) {
  var profile = googleUser.getBasicProfile();
  console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
  console.log('Name: ' + profile.getName());
  console.log('Image URL: ' + profile.getImageUrl());
  console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}

Friday, 4 August 2017

Java multithreading,serializable,

Why wait,notify,notifyall are part of object and not thread class?
How to create mutable class. A has B. A is immutable and B is mutable. So can we say A is immutable?
What is difference between synchronized method and synchronized block.Which one to use at what requirements?
S

Tuesday, 24 January 2017

Different methods to create THREADS in JAVA

Method 1:
By extending thread class and creating new object of child of thread and calling start() method

class Mythread extends Thread

Method 2:
By implementing Runnable interface by a class and passing it to thread class and calling start method

class Mythread2 implements Runnable {

run(){}
}

Thread t = new Thread(new Mythread2());

t.start();

Friday, 20 January 2017

Java environment variables

JAVA_HOME : Set to a location of jdk folder
JRE_HOME : Set to a location of jre folder inside jdk
Add %JAVA_HOME%/bin to path variable

Java environment variables

JAVA_HOME : Set to a location of jdk folder
JRE_HOME : Set to a location of jre folder inside jdk
Add %JAVA_HOME%/bin to path variable

Thursday, 3 March 2016

Architecture (folder structure) of Java Web Project .....

Architecture (folder structure) of Java Web Project  --- As below

Web Application Name --- MyWebApp

MyWebApp
        
         --- /src
                 |
                 ---/main
                        |
                        ----/java
                        |
                        ----/resources
                        |            |
                        |            ----/images
                        |            ----/css
                        ----/WebContent
                                     |
                                     ---- /WEB-INF
                                     |             |
                                     |             ---- web.xml
                                     |             ---- /lib
                                     |             ---- /classes
                                     ---- /META-INF
                                     |
                                     ---- *.jsp
                                     ---- *.html

Just explore on each component to get aware of java web project..

    

Monday, 22 February 2016

Environment variables : What it is? How to set it?


Java Bean

What is Java Bean?

Java bean is a simple java class with instance variables (all private) and each instance variable having getter and setter methods (public) for them.

Example :

 class Person {  
 private int id;  
 private String name;  
 private String address;  
 public int getId () { return id; }  
 public String getName () { return name; }  
 public String getAddress () { return address; }  
 public void setId (int id) { this.id = id; }  
 public void setName (String name) { this.name = name; }  
 public void setAddress (String address) { this.address = address; }  
 }  

Java and its Features in brief

What is Java?


Java is a Object Oriented Programming Language.
Main Features of Java are :
Class :- Template
Object :- Instance with Specific Values
Inheritance :- Creating new classes by extending the features of existing classes
Polymorphism :- A single variable of class type can take multiple forms i.e. a variable can be assigned to objects of different types along the class hierarchy

Class :

Definition of class
class <name>
{
variables;
constructors;
methods;
}

class X{
//variables
int x;
//constructors
X(int x) { this.x = x; } 
//methods
int getX() { //body }
void setX(int x) { //body}
}

Object :

Using keyword new we create an instance i.e. object of a class.
X temp = new X(5);

Inheritance :

Another class  Y
Class Y extends X{
//variables
int y;
//constructors
Y(int x,int y) { super(x); this.y = y; } 
//methods
int getY() { //body }
void setY(int y) { //body}
}

Here the method getX() and setX(int x) are inherited in class Y and can be called from class Y.

Polymorphism :

Another class Z instatiates X and Y classes.
class Z{
int z;
p.s.v.m.(){
X temp = new X(5);
System.out.println("X : " + temp.getX());
temp = new Y(5,10);
System.out.println("X : " + temp.getX()); // cannot call temp.getY() as temp is variable of type X which does
                                                              // not have method getY()
}
}
Same variable can take multiple forms i.e. it can be assigned an instance of X or Y. Hence same variable temp takes multiple forms.
This is polymorphism.


Tuesday, 16 June 2015

How to implement singleton class in java?

Hello All,

Hope you will enjoy this article.

How to implement singleton class in java?

Concept of Singleton : Singleton class is one for which only one instance i.e. object of it will be created.

To achieve this requirement it is important create first time the object for the class but afterwards whenever there is need for instance of that class .. reference for already created instance should be returned.

Following code will serve as an example for singleton class :

public class Singleton {

private static Singleton;
protected Singleton()                   //protected constructor
{
}

public static getInstance(){
{
           if(Singleton == null)
                      Singleton = new Singleton();
           return Singleton;
}
}

Java Code to find second highest number in an array in java

Hi ,

Please find below the code to find second highest number in an array in java.

Method 1:
public class SecondHighestNumber {

public static void main(String[] args) {

int [] arr = { 1,19,9,7,5,2,3,4,16,12};

int firstHighest , secondHighest , i;

if(arr[0] > arr[1])
{
            firstHighest = arr[0];
            secondHighest = arr[1];
}
else
{
            firstHighest = arr[1];
            secondHighest = arr[0];

}

for(i=2;i<arr.length();i++)
{
           if(arr[i] >= firstHighest)
           {
             secondHighest = firstHighest;
             firstHighest = arr[i];
           }
           else if(arr[i]>secondHighest)
           {
            secondHighest = arr[i];
           }
}

System.out.println(" The Second highest number in an array is "+secondHighest);

}

}

Tuesday, 30 December 2014

How to implement tree in java?

Steps
1. Create class Node with generic parameter T and having instance variables as
     1.1 data of type T i.e. T data;
     1.2 List of Node of Type T i.e. List<Node<T>> children;
     1.3 parent of type Node<T> i.e. Node<T> parent;
   & methods as
     Constuctors as
      public Node(T data)
     {
            this.data = data;
      }
      public Node(T data,Node<T> parent)
      {
           this.data = data;
           this.parent = parent;
       }
       Add methods to getChildren, addChild, setParent.
2. Create class Tree with instance variables as
     2.1 root with type Node<T> i.e. Node<T>root;
3. Create Class TestTree with main method.
    Create a local variable t of type Tree.
    Add root and other nodes inside the tree.

Thanks,
Sagar

Thursday, 18 December 2014

Java Interview Questions

Interview Question 1.
How to find first non repeated character in the String( Write Java Code)