Showing posts with label vigyan code. Show all posts
Showing posts with label vigyan code. Show all posts

Sunday

रेनल्ट डस्टर में आया नया एएमटी वैरियंट, 7.99 लाख से शुरू

देश के बेस्ट सेलिंग एसयूवी में शामिल रेनल्ट डस्टर में कुछ नए अपडेट शामिल किए हैं। रेनो ने डस्टर के डीजल वैरियंट में ऑटोमैटिक ट्रांसमिशन का ऑप्शन लॉन्च किया है। डस्टर अब केवल तीन वैरियंट में ही मिलेगी। डस्टर का मुकाबला हुंडई क्रेटा और मारुति एस क्रॉस से है। डस्टर पेट्रोल पेट्रोल की कीमत 7.99 लाख रुपए से शुरू होती है, जबकि टॉप डीजल की कीमत 110पीएस RXZ AWD वैरियंट की कीमत 13.09 लाख रुपए है।




रेनो ने कॉम्पैक्ट एसयूवी डस्टर के वैरियंट लाइनअप में फेरबदल किया है। अब डस्टर के पेट्रोल वर्जन में केवल तीन ही वैरियंट RxE, RxS और RxZ मिलेंगे, वहीं डीजल में 6 वैरियंट रहेंगे। डस्टर ने पेट्रोल वर्जन में RxL वैरियंट को खत्म कर दिया है। माना जा रहा है कि रेनो ने यह फेरबदल अगले साल अप्रैल 2020 में लागू होने वाली नए बीएस-6 मानकों के चलते उठाया है और रेनो उससे पहले ही डस्टर का वर्तमान स्टॉक खत्म करना चाहती है।

वहीं रेनो डस्टर के डीजल वैरियंट पर 65 हजार रुपए तक के ऑफर पेश कर रही है। जिसमें सभी वैरियंट्स पर पहले साल में 1 रुपए इंश्योरेंस और 20 हजार रुपए का कैश डिस्काउंट शामिल है। वहीं पेट्रोल वैरियंट्स पर केवल 20 हजार रुपए के ऑफर मिलेंगे। साथ ही 5 हजार रुपए का कारपोरेट बोनस भी मिलेगा। रेनो के मुताबिक ये डिस्काउंट केवल 2019 के सभी वैरियंट्स पर मिलेंगे।

Wednesday

URLs to Local Files






The URL class can also be used to access files in the local file system. Thus the URL class can be a handy way to open a file, if you need your code to not know whether the file came from the network or local file system.

Here is an example of how to open a file in the local file system using the URL class: URL url = new URL("file:/c:/data/test.txt");

URLConnection urlConnection = url.openConnection();
InputStream input = urlConnection.getInputStream();

int data = input.read();
while(data != -1){
System.out.print((char) data);
data = input.read();
}
input.close();


Notice how the only difference from accessing a file on a web server via HTTP is the the URL: "file:/c:/data/test.txt".

Tuesday

HTTP GET and POST



By default the URLConnection sends an HTTP GET request to the webserver. If you want to send an HTTP POST request instead, call the URLConnection.setDoOutput(true) method, like this:
URL url = new URL("https://vigyancode.blogspot.com/");
 
URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
Once you have set called setDoOutput(true) you can open the URLConnection's OutputStream like this:
OutputStream output = urlConnection.getOutputStream();
Using this OutputStream you can write any data you want in the body of the HTTP request.  
Remember to close the OutputStream when you are done writing data to it.

Monday

Difference between TCP and UDP



TCP
UDP
Reliability: TCP is connection-oriented protocol. When a file or message send it will get delivered unless connections fails. If connection lost, the server will request the lost part. There is no corruption while transferring a message.
Reliability: UDP is connectionless protocol. When you a send a data or message, you don’t know if it’ll get there, it could get lost on the way. There may be corruption while transferring a message.
Ordered: If you send two messages along a connection, one after the other, you know the first message will get there first. You don’t have to worry about data arriving in the wrong order.
Ordered: If you send two messages out, you don’t know what order they’ll arrive in i.e. no ordered
Heavyweight: – when the low level parts of the TCP “stream” arrive in the wrong order, resend requests have to be sent, and all the out of sequence parts have to be put back together, so requires a bit of work to piece together.
Lightweight: No ordering of messages, no tracking connections, etc. It’s just fire and forget! This means it’s a lot quicker, and the network card / OS have to do very little work to translate the data back from the packets.
Streaming: Data is read as a “stream,” with nothing distinguishing where one packet ends and another begins. There may be multiple packets per read call.
Datagrams: Packets are sent individually and are guaranteed to be whole if they arrive. One packet per one read call.
Examples: World Wide Web (Apache TCP port 80), e-mail (SMTP TCP port 25 Postfix MTA), File Transfer Protocol (FTP port 21) and Secure Shell (OpenSSH port 22) etc.
Examples: Domain Name System (DNS UDP port 53), streaming media applications such as IPTV or movies, Voice over IP (VoIP), Trivial File Transfer Protocol (TFTP) and online multiplayer games etc


Thursday

Traversing in Linear Array


 Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms.
Traverse − print all the array elements one by one.or process the each element one by one .
Let A be a collection of data elements stored in the memory of the computer. Suppose we want to print the content of each element of A or suppose we want to count the number of elements of A with given property. This can be accomplished by traversing A, that is, by accessing and processing (frequently called visiting) each element of An exactly once.

Algorithm 

Step 1 :    [Initialization]  Set I = LB

Step 2 :      Repeat Step 3 and Step 4 while I  < = UB

step 3 :       [ processing ] Process the A[I] element

Step 4 :      [ Increment the counter ] I = I + 1
                   [ End of the loop of step 2 ] 

Step 5:       Exit 

(Here LB is  lower Bound and UB is Upper Bound  A[ ] is linear array )

Saturday

TCP/IP Server example in Java


The ServerSocket class is used to create servers. Typically we create the ServerSocket instance with the port number to be published for client connections. ServerSocket has the accept() method which waits for client connections. In the example below we use a ClientHandler thread which simply reads the message from client and writes back a message to client.
package com.netparam.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class JavaServer {

  private static class ClientHandler extends Thread {

    private Socket socket;
   
    ClientHandler(Socket socket) {
      System.out.println("Client connected");
      this.socket = socket;
    }
   
    @Override
    public void run() {
     
      try {
        // Reader and writer
        BufferedReader reader = new BufferedReader
            (new InputStreamReader(socket.getInputStream()));
        PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
       
        // Read message from client
        System.out.println(reader.readLine());
       
        // Write a message back to client
        writer.println("Hello from server");
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        try {
          socket.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
   
  }
 
  public static void main ( String[] args ) {
    final int port = 8888;
   
    try ( ServerSocket ss = new ServerSocket(port) ) {
      System.out.println("Listening ...");
      while ( true ) {
        Socket socket = ss.accept();
        new ClientHandler(socket).start();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Sunday

Console Class Or System Class


System class
The System class provides facilities such as the standard input, output and error streams. It also provides means to access properties associated with the Java runtime system and various environment properties such as version, path, vendor and so on. Fields of this class are in, out and err which represent the standard input, output and error respectively.
Java Console Class
The Java Console class is be used to get input from console. Console class comes under Java.io.Console class
Let's see the code to get the instance of Console class.
Console c=System.console();  
Console Example
import java.io.Console;  
class ReadStringTest{    
public static void main(String args[]){    
Console c=System.console();    
System.out.println("Enter your name: ");    
String n=c.readLine();    
System.out.println("Welcome  to "+n);    
}    
}  
Output
Enter your name: Cdac Jaipur
Welcome to Cdac Jaipur



Inner Class in Java


If one class is existing within another class is known as inner class or nested class
Syntax
class  Outerclass_name
{
.....
.....

class  Innerclass_name1
{
.....
.....
}
class  Innerclass_name1
{
.....
.....
}
.....
}
The main purpose of using inner class
·         To provide more security by making those inner class properties specific to only outer class but not for external classes.
·         To make more than one property of classes private properties.
Private is a keyword in java language, it is preceded by any variable that property can be access only within the class but not outside of it (provides more security).
If more than one property of class wants to make as private properties than all can capped under private inner class.
Syntax
class  Outerclass_name
{
private  class Innerclass_name
{
.....
.....   //private properties
}
}
Note:No outer class made as private class otherwise this is not available for JVM at the time of execution.
Rules to access properties of inner classes
·         Inner class properties can be accessed in the outer class with the object reference but not directly.
·         Outer class properties can be access directly within the inner class.
·         Inner class properties can't be accessed directly or by creating directly object.
NoteIn special situation inner class property can be accessed in the external class by creating special objects with the reference of its outer class.
Example
class   A //outer class
{
void  fun1()
{
System.out.println("Hello fun1()"); // inner class properties should be access using   
                                //object reference in outer class.
B  ob=new  B();
    ob.x=10
System.out.println("x= "+ob.x);
ob.fun2();
}
void fun3()   // outer class fun3()
{
System.out.println("Hello fun3()");
}
class  B  // inner class
{
int  x;  // inner class variable
void fun2()        //inner class fun2()
{
System.out.println("Hello fun2()");
fun3(); //outer class properties can be access directly
}
}
}

class  C // external class
{
void fun3()
{
System.out.println("Hello fun3()");
}
}

class IncDemo
{
public static void main(String args[])
{
A  oa=new  A();
oa.fun1();
C   oc=new   C();
oc.fun3();
}
}
Output
Hello fun1()
X=10
Hello fun2()
Hello fun3()
Accessing inner class properties in the external class
1. If inner class in non static the object can be created with the following syntax
Syntax
class  Outer_class
{
class  Inner_class
{
.....
.....
}
.....
.....
}
class  External_class
{
Outer_class.Inner_Class objectrefernce=new Outer_Class.External_Class();
}
2. If inner class is static the object reference can be created with the following syntax
Syntax
class  Outer_class
{
static class Inner_Class
{
.....
.....
}
}
class  External_Class
{
Outer_class.Inner_Class objectrefernce=new Outer_Class.External_Class();
}
}
Example
class A               //Outer class
{
class B               // non-static  inner class
{
int x;   //inner class variable
void fun1()        //inner class fun1()
{
System.out.println("Hello fun1()");
}
}
static class C     //static inner class
{
int  y=20;  // inner class variable
void fun2()
{
System.out.println("Hello fun2()");
}
}
}

class IncDemo
{
public static void main(String args[])
{
A.B  ob=new  A().new.B();
System.out.println(ob.x);
ob.fun1();
A.C  oc=new  A.C();
System.out.println(oc.y);
oc.fun2();
}
}