Search the Blog

Showing posts with label JS. Show all posts
Showing posts with label JS. Show all posts

Thursday, August 29, 2019

Palindrome number program in Pythan

In this post i will explain the palindome number program in python and also to expalin the same i also created a youtube video so you can check also complete step by step and also output in IDE. 

Palindrome number program in Pythan

Palindrome number program in Pythan


Palindrome No Program in Python-



num = int(input("enter a number: "))
temp = num
rev = 0while temp:
    rev = (rev * 10) + (temp % 10)
    temp = temp // 10if num == rev:
    print("No is palindrome")
else:
    print("No is not palindrome")



Output-
When entered Item is- 747
   No is Palindrome.

when entered Item is- 67
   No is notb Palindrome.


See Also-Pythan All type of program







Sunday, August 18, 2019

JAVA program to return product of array element

Implement a function in JAVA of given array of integers, returns a new array for which every index carries the value of the product of the remaining elements.



Given array [2,3,1,4,5] it would return [60,40,120,30,24]


JAVA program to return product of array element



public class Main {

   List<Integer> arrInput1[];
   static  List<Integer> arrOutput1[];
   static int n;
   public static void main(String[] ar)
   {
   System.out.println("Enter the array size");
   Scanner a_dizsweb= new Scanner(System.in);
   n=a_dizsweb.nextInt();
   ArrayList<Integer> arrInput1=new ArrayList<Integer>();
   ArrayList<Integer>    arrOutput1=new ArrayList<Integer>();
     System.out.println("Enter the array size  ");

    for (int i=0;i<n;i++)
    {
          arrInput1.add(i, new Scanner(System.in).nextInt());
    }

findSpecialProduct(arrInput1);

    }
    public static void findSpecialProduct(List<Integer> inputArray) {
   ArrayList<Integer> arrOutput1=new ArrayList<Integer>();
         for(int k=0; k<n;k++)
      {
          int indexvalue1=1;
          int index=k;
       for (int i =0; i<n;i++)
       {
           if (index==i)
           {
             indexvalue1=indexvalue1*1;
           }
           else
           {
            indexvalue1=indexvalue1*inputArray.get(i); 
           }
       }
       arrOutput1.add(indexvalue1);
      }
/*     
 for(Integer inta : arrOutput) {
            System.out.println(inta.get());
        }*/
        arrOutput1.forEach(System.out::println);
   
    }

}

Implement a function which, given an array of integers, returns a new array for which every index carries the vale of the product of the remaining elements.

Saturday, August 17, 2019

SQL Server Profiler Logout class Interpretation

Features of Logout Class-

 ApplicationName  (Data Types- nvarchar) (Column Id- 10)
         Name of the client application(Software which runs on user end) that created the connection to an instance of SQL Server. This column is populated with the values passed by the application(Every application have a unique code) rather than the displayed name of  the program.
SQL Server Profiler Application  Name


 ClientProcessID  (Data Types- int) (Column Id- 9)
           ID assigned by the host computer(Servefr) to the process (User application)where the client application is running. This data column(Value) is populated if the client process ID is provided by the client

 CPU  (Data Types- int) (Column Id- 18)
          Amount of CPU time (in milliseconds) used by the user during their connection(End User)

DatabaseID  (Data Types- int) (Column Id- 3)
          ID of the database(A Special ID is assigned) specified by the USE database statement or the default database if no USE database statement has been issued for a given instance (Session). SQL Server Profiler displays the name of the database(Main Database of application) if the ServerName data column is captured in the trace and the server is available.                
Determine the value for a database by using the DB_ID function(Special function to identify).

DatabaseName  (Data Types- nvarchar) (Column Id- 35)
          Name of the database(Session database) in which the user statement is running.

Duration  (Data Types- bigint) (Column Id- 13)
         Amount of time since the user logged in() Time of session (approximately).

EndTime  (Data Types- datetime) (Column Id- 15)
         End time of the logout() When the session Close.

EventClass  (Data Types- int) (Column Id- 27)
        Type of event = 15 ( Their are 15 types of event like logging , logout, etc).

EventSequence (Data Types- int) (Column Id- 51)
        The sequence of a given event within the request (this will show the details of event.

HostName (Data Types- nvarchar) (Column Id- 8)
        Name of the computer on which the client is running (End User). This data column is populated if the host                  name is provided by the client( End User). To determine the host name, use the HOST_NAME function (Function to know the host name).

IsSystem (Data Types- int) (Column Id- 60)
        Indicates whether the event occurred on a system process or a user process1 = system, 0 = user (This method will let to know is this an automatic or manual enent).

LoginName (Data Types- nvarchar) (Column Id- 11)
        Name of the login of the user (either the SQL Server security login or the Microsoft Windows login            credentials in the form of DOMAIN \ username).

LoginSid (Data Types- image) (Column Id- 41)
         Security identification number (S I D) of the logged-in user. You can find this information in                           the sys.server_principals catalog view. Each S I D is unique for each login in the server.

NTDomainName (Data Types- nvarchar) (Column Id- 7)
         Windows domain to which the user belongs.

NTUserName (Data Types- nvarchar) (Column Id- 6)
         Windows user name

Reads (Data Types- int) (Column Id- 16)
         Number of logical read I/Os issued by the user during the connection.

RequestID  (Data Types- int) (Column Id- 49)
         ID of the request containing the statement.

ServerName (Data Types- int) (Column Id- 26)
         Name of the instance of SQL Server being traced.

SessionLoginName (Data Types- int) (Column Id- 64)
         Login name of that user who originated the session. For example, if you connect to SQL Server using           Login1 and execute a statement as Login2, SessionLoginName shows Login1                                             and LoginName shows Login2. This column displays both SQL Server and Windows logins.

SPID (Data Types- int) (Column Id- 12)
         ID of the session on which the event occurred( Session unique ID).


StartTime(Data Types- datetime) (Column Id- 14)
         Time at which the event started, if available.

Success (Data Types- int) (Column Id- 23)
         1 = success. 0 = failure. For example, a value of 1 indicates success of that permission  check and a                 value of 0 indicates failure of that check.

Writes (Data Types- bigint) (Column Id- 17)
         Number of logical write Inputs/Outputs issued by the user during the connection.

GroupID(Data Types- int) (Column Id- 66)
     ID of the work load group(Main session) where the SQL Trace event fires.

Thursday, August 15, 2019

Json Parser Code for Android to JAVA MVC Project Uploading The Image

This Blog post have the complete Code for an Android Application which have database at cload and running on apache TOMCAT.


Json Parser Code for Android to JAVA MVC Project Uploading The Image

In this blog post you can get all information easily which is required to send a request from android application to server(cloud)  and receive and extract  the data in usable format.


This Code is used in School ERP Application for uploading The Image of Code



package com.example.sawan.onlineattendance; // Package Name of Project
import android.util.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * Created by sawan on 9/28/2016.
 */

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
static InputStream iStream = null;
static JSONArray jarray = null;

public JSONParser() {}
public JSONObject makeHttpRequest(String url2, String method, List < NameValuePair > params)\ {
try {
if (method == "POST") {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
else {
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}

}
catch(UnsupportedEncodingException e) {
System.out.println("UnsupportedEncodingException");
e.printStackTrace();
}
catch(ClientProtocolException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch(Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
}
catch(JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;

}
public JSONArray getJSONFromUrl(String url) {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
}
else {
Log.e("==>", "Failed to download file");
}
} catch(ClientProtocolException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
try {
jarray = new JSONArray(builder.toString());
} catch(JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jarray;
}

public JSONObject makeHttpRequest2(String url) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch(UnsupportedEncodingException e) {
e.printStackTrace();
} catch(ClientProtocolException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch(Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

try {
jObj = new JSONObject(json);
} catch(JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;

}
}


100+ JAVA Pattern Program






50+ Python Pattern Program



See Also-



Android Code for opening Multiple Screen from a single Activity

This Blog post have the complete Code for an Android Application about various activity opening from ia single screen 

Android Code for opening Multiple Screen from a single Activity



In this blog post you can get all information relatated activating new activity from previous activity with actual runnable code.


This code is part of Android application MVC Project of School ERP. If you are faminliar with java and also have some good hands on Anadroid then you can easilly understand the code and can use this code in your own project.


package com.example.sawan.onlineattendance;

import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;

public class HOD extends AppCompatActivity {
Button studentremark,
btn2,
notice,
drictorNotice,
hodNotice,
Defaulter,
Inforamtion,
teacherLogin,
teacherremak;
JSONParser jParser = new JSONParser();
JSONObject json;
String buttton;
static String button;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hod);
btn2 = (Button) findViewById(R.id.sdudent_lecture);
btn2.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Intent intent = new Intent(HOD.this, Student_subject_setting.class);
startActivity(intent);
}
});
studentremark = (Button) findViewById(R.id.studentNotification);
studentremark.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Intent intent = new Intent(HOD.this, HODStudentRemark.class);
startActivity(intent);
}
});
teacherremak = (Button) findViewById(R.id.HomeWork);
teacherremak.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Intent intent = new Intent(HOD.this, HomeWork.class);
startActivity(intent);
}
});
teacherLogin = (Button) findViewById(R.id.TeacherLogin);
teacherLogin.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Intent intent = new Intent(HOD.this, HODTeacherLogin.class);
startActivity(intent);
}
});
notice = (Button) findViewById(R.id.update);
notice.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Intent intent = new Intent(HOD.this, HODStudentNotification.class);
startActivity(intent);
}
});
hodNotice = (Button) findViewById(R.id.TecherNotification);

hodNotice.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Intent intent = new Intent(HOD.this, HODStaffNotice.class);
startActivity(intent);
}
});
Defaulter = (Button) findViewById(R.id.DefaulterStudent);
Defaulter.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Intent intent = new Intent(HOD.this, DefaulterCutOf.class);
startActivity(intent);
}
});
Inforamtion = (Button) findViewById(R.id.StudentDetail);
Inforamtion.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Intent intent = new Intent(HOD.this, DirectorStudentFinal.class);
startActivity(intent);
}
});
drictorNotice = (Button) findViewById(R.id.DirectorNotice);
drictorNotice.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
new Login().execute();
}

});

}
private class Login extends AsyncTask < String,
String,
String > {@SuppressWarnings("WrongThread")@Override
protected String doInBackground(String...strings) {
String table = Identification.TableName; {
String url_login2 = "http://192.168.43. 156:8081/OnlineAttendance/DirectorNoticeServlet";
List < NameValuePair > params_dizsweb = new ArrayList < NameValuePair > ();
params_dizsweb .add(new BasicNameValuePair("t", Identification.TableName));
params_dizsweb .add(new BasicNameValuePair("cutoff", "HODDrictor"));
params_dizsweb .add(new BasicNameValuePair("text", "faltu"));
json = jParser.makeHttpRequest(url_login2, "GET", params);
String s = null;
try {
if (json.getString("info").equals("success")) {
Identification.FacultyDrictorNotices = json.getString("name");
Intent login = new Intent(getApplicationContext(), HODDrictorNotice.class);
login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(login);
}
else {
Intent login = new Intent(getApplicationContext(), Error.class);
login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(login);
}
} catch(Exception e) {
e.printStackTrace();
}
}
return null;
}
}
}


Star Pattern Program JAVA

Sunday, July 28, 2019

MVC CODE FOR ANDROID REQUEST AND RESPONSE -Programming Logic and Code with Syntax Dizsweb

MVC CODE FOR ANDROID REQUEST AND RESPONSE -Programming Logic and Code with Syntax Dizsweb


package com.sawan;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
@WebServlet("/DirectorStudentList")
public class DirectorStudentList extends HttpServlet {
 private static final long serialVersionUID = 1L;
 Statement stmt = null; 
  
    public DirectorStudentList() {
        super();
        // TODO Auto-generated constructor stub
    }

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    JSONObject json = new JSONObject();  
    Enumeration paramNames = request.getParameterNames();
         String params[] = new String[3];
         int i = 0;
         while (paramNames.hasMoreElements())
         {
             String paramName = (String) paramNames.nextElement();
          System.out.println(".........params[]....................."+paramName);
             System.out.println(paramName);
             String[] paramValues = request.getParameterValues(paramName);
             params[i] = paramValues[0];
          System.out.println(".............+params[i]................."+params[i]);
          System.out.println(".............+params[i]................."+params[i]);
             System.out.println(params[i]);
             i++;
         }
         ResultSet rs=null;
         String table=params[1]; 
         String cutoff=params[0];
         DataBase  db=new DataBase();
         Connection con=db.getConnection();
         table=table;
         String Roll=params[0];
         int code=Integer.parseInt(params[0]);
         System.out.println("rOLL nO............"+Roll);
         String sql="SELECT * FROM Attendance."+table+"  WHERE STUDENTBRANCH ="+code+" AND STUDENTSECTION='"+params[2]+"'"; 
         System.out.println(sql);
         try {    stmt=con.createStatement();
         rs = stmt.executeQuery(sql); 
   } catch (SQLException e1) {

    e1.printStackTrace();
   }
         
         try {
          System.out.println("STEMENT EXECUTE..............");
          System.out.println("RESULT SET EXECUTR..............");
          int u=0;
          int s=0;
          
          while (rs.next()) {
               json.put("name"+s,rs.getString("STUDENTNAME"));
               json.put("roll"+s,rs.getString("STUDENTROLL"));
               json.put("info", "success"); 
              s++;
              json.put("row",s);
                  System.out.println("RESULT SET EXECUTR.......2.......");
                 u=1; 
              }
              if(u==0)
              {
                 json.put("info", "fail");
              }
          
              System.out.println("RESULT SET EXECUTR.........24.....");
         } catch (Exception e) {
             e.printStackTrace();
         }
      
         System.out.println(json);
         response.setContentType("application/json");
         response.setCharacterEncoding("UTF-8");
         response.getWriter().write(json.toString());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


}
}

Monday, July 15, 2019

Palindrome JAVA Code 2 Programming Logic and Code with Syntax

This is individual description list of program which is mentionmed in first page of JAVA, part of programming tutorial i will try to explanin more than 50 java * pattern program, Which are asked in interview and online exams and unveristy exam with diferrent logic for the same type of pattern


 Top 100+ Sql Server Interview Questions

A palindromic number is a number  that is the same when written forwards or backwards
 always be same, i.e., of the form 
. The first few palindromic numbersare therefore  are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121


class PalindromeExample
{  
 public static void main(String args[])
{  
  int r,sum=0,temp;    
  int n=555;//It is the number variable to be checked for palindrome  
  
  temp=n;    
  while(n>0)
{    
   r=n%10;  //getting remainder  
   sum=(sum*10)+r;    
   n=n/10;    
  }    
  if(temp==sum)    
   System.out.println("palindrome number ");    
  else    
   System.out.println("not palindrome");    
}  

Translate