Friday, 4 December 2020

In C programming V is used for

In C programming V is used for:

 In C programming V is used for vertical tab. This is a program that demonstrate the use of  \V.

// this is a C program to demonstrate V in c language

 #include <stdio.h>

int main()
{
    printf("Hello \n ");  

    printf("This  \v is  \v a  \v c-language \v program \v to \v demonstrated \v V. ");

    return 0;
}

 OUTPUT:



 Here are few escape characters:

 \b which is used for Backspace in C programming language 

\e   we use this for escape character  in C.

\n 
 This is used for new line character.
 
 \t 
   This is used for Horizontal tab
\\ 
  We use this in c-language  to display the backslash character.

 

Tuesday, 1 December 2020

How to Beautify xml code

 Beautify XML code:

 Online XML Beautifier beautifies ugly XML code and makes it more readable.
 These Online XML Beautifiers gives the code proper indentation, spaces,newlines etc. so that
 it becomes well-formatted code which is easy understandable by user.

Some of them are Notepad3, Code Browser, Kate, Bluefish, Text Editor Pro, Notepad++, XML Notepad 2007, Atom.
 

Friday, 27 November 2020

How to check url is http or https in java

 This is a java program to check protocol is http or not.

URLProtocolDemo.java    

 
import java.net.*;    
public class URLProtocolDemo{    
public static void main(String[] args){  
//String url="https://www.w3schools.com/html/";  
try{    
    URL url=new URL(url);    
     String protocol=   url.getProtocol();
     System.out.println("Protocol of given url is : "+protocol);
     if(protocol.equalsIgnoreCase("https")); 

     System.out.println("Protocol is a https protocol");    
       }

    else{

           if(protocol.equalsIgnoreCase("http")){
                   System.out.println("Protocol is a http protocol");    
              }

          else{
                   System.out.println("Protocol is neither http nor https protocol ");    
               }    
   }

catch(Exception e)  {
    System.out.println(e);
  }  
 }
}



Thursday, 26 November 2020

Printing diagonal elements of a given matrix in C language

Printing diagonal elements of a given matrix in language: 

In this we are going to display left and right diagonal elements of a given matrix in language.

#include <stdio.h>
void main(){
int matrix1[3][3],i, j;

 // reading the elements of first matrix
    printf(" enter elements of first matrix ");
    for( i=0; i<3 ;i++){
        for(j=0;j<3;j++){
            scanf( "%d", &matrix1[i][j]);
        }
    }

    // printing the resultant matrix  
    printf(" the matrix is  \n");
    for (i=0; i<3; i++){
        for( j=0; j<3; j++){
            printf(" %d ", matrix1[i][j]);
        }
        printf(" \n ");
    }
printf(" the left diagonal elements of this matrix are \n");

printf( "%d,   %d,   %d ",  matrix1[0][0],matrix1[1][1],matrix1[2][2]);

printf(" the right diagonal elements of this matrix are \n");

printf(" %d,   %d,   %d ",  matrix1[0][2],matrix1[1][1],matrix1[2][0]);
}

Sunday, 22 November 2020

What's the difference between comment line and code line?

What's the difference between comment line and code line?

  • Comment line:  

    Comment line is a that describes something about the code. But these lines wont get executed.
  •  Code line: 

    Code line  is a line that has the logic or our program. This line will get executed. Compiler will compile this line and output will be generated.
The similarity between comment line and code line is both will be there in the same file.But when we run code line will get executed and comment line wont get executed.

Tuesday, 17 November 2020

Elements features of Basic and C programming

Elements features of Basic and C programming:

BASIC Language Features:

BASIC a programming language which is abbreviated as Beginners All Purpose Symbolic Instruction Code,  is the Simplest and high level programming language.


 The language used in BASIC is very simple English, which can be easily programmed by anyone.
 
 BASIC a programming language designed in 1964, by John G. Kemeny and Thomas E. Kurtz  at Dartmouth College in the U.S. state of New Hampshire.
 This programming language is widely used because it is easy to learn  and it supported by most  operating systems.


 
It was the principal programming language during the 1970s taught to students,

As it is simple, BASIC language is used for a wide variety of business applications.
There is an ANSI standard for the BASIC programming language.

It allow multi features which are described below.
   

  1.     It is a general-purpose programming languages  
  2.     It is a high-level programming languages
  3.     It allow input from the keyboard.
  4.     It access Menu driven Application.
  5.     It is structured programming language.
  6.     BASIC programming language has Built in Functions.
  7.     BASIC allow User defined functions.
  8.     Subroutine features are available  BASIC language.
  9.     It allows us to  create Loops.
  10.     It contains several System commands.

 

Monday, 21 September 2020

How to get cdata value from xml in java

How to get cdata value from xml in java  | How to read cdata in xml using java


In this article, we are going to discuss XML CDATA which stands for Character Data. which is defined as blocks of text that will not be parsed by the xml parser.

 syntax of cdata in xml:


    <![CDATA[
        characters with markup
        ]]>


Java provides some of the options to parse XML documents. Some of the commonly used  XML parsers for java programming language are as follows:

  1.     DOM Parser  (Document Object Model)
  2.     SAX Parser
  3.     StAX Parser  (Streaming API for XML)
  4.     JAXB

    
let us consider the following xml file cdata.xml

cdata.xml


<?xml version="1.0" encoding="UTF-8"?>
<employee>
  <emp_info id="1">
    <emp_name>
      <first_name>abc</first_name>
      <last_name>xyz</last_name>
    </emp_name>
    <emp_contact_info>
      <address><![CDATA[
        This is the CDATA area.
        You can store special character that are recognize. Ex. '  " & / - < >
        you can specify company address also
        ]]>
      </address>
    </emp_contact_info>
  </emp_info>
</employee>

This is the java program.

XmlCData.java

import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

class XmlCData{
    public static String getCharacterDataFromElement(Element e) {
        NodeList list = e.getChildNodes();
        String data;

        for(int index = 0; index < list.getLength(); index++){
            if(list.item(index) instanceof CharacterData){
                CharacterData child = (CharacterData) list.item(index);
                data = child.getData();

            if(data != null && data.trim().length() > 0)
                return child.getData();
        }
    }
    return "";
  }
}


JavaXmlCdata .java


public class JavaXmlCdata {    
    public static void main(String[] args) throws Exception{
        File file = new File("D:\\cdata.xml");
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(file);
        
        NodeList nodes = doc.getElementsByTagName("emp_contact_info");
        
        for (int i = 0; i < nodes.getLength(); i++) {
      
            Element element = (Element) nodes.item(i);
            NodeList title = element.getElementsByTagName("address");
            Element line = (Element) title.item(0);
            System.out.println("Cdata is  " + XmlCData.getCharacterDataFromElement(line));
    }
  }
}