Prolog is a logic programming language associated with artificial intelligence and computational linguistics.

It's my First day of Prolog and here is the Half Added login in Prolog. It is not a solution but it just works.
1
2
3
4
5
6
7
8
high(1).
low(0).

xor(X,Y,Sum) :- (((low(X) , low(Y)) ; (high(X) , high(Y))) , low(Sum)) ; (((low(X) , high(Y)) ; (high(X) , low(Y))) ,high(Sum)).

and(X,Y,Carry) :- (high(X), high(Y), high(Carry)) ; (((low(X) , low(Y)) ; (low(X) , high(Y)) ; (high(X) , low(Y))) , low(Carry)).

half_adder(X,Y,Sum,Carry):- xor(X,Y,Sum) , and(X,Y,Carry).

for Xor -> if [(X and Y is low or X and Y is high) and sum is low. ] OR [ (if X is low and Y is high or X is high and Y is low) and Sum is high]

for and -> if (X is high and Y is High And Carry is high) OR [(if X is low and Y is low or X is low and Y is high or X is high and Y is low)  and Carry is low]

low = 0 and high = 1

Output:
prolog task3.pl

The half adder adds two binary digits called as augend and addend and produces two outputs as sum and carry; XOR is applied to both inputs to produce sum and AND gate is applied to both inputs to produce carry. The full adder adds 3 one bit numbers, where two can be referred to as operands and one can be referred to as bit carried in. And produces 2-bit output, and these can be referred to as output carry and sum.


Half - Adder Truth Table
Thank you!
Hello here is a simple java program for file Handling. Here first we store the "java Programming" string into a file named "hi.txt" then we read the "hi.txt" and write it to another file "hello.txt" as well as display in the standard output. Then we read from Standard input and insert it into namaste.txt

Here is the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.io.*;
public class FileHandler {
	public static void main(String args[]) throws IOException{
		System.out.println("Here");

		FileReader reader = null;
		FileWriter writer = null;
		InputStreamReader input = null;

		String message = "Java Programming";
		try {
			writer = new FileWriter("hi.txt");
			int i = 0;
			for(i = 0; i<message.length(); i++) {
				//System.out.println(message.charAt(i));
				int charInt = (int) message.charAt(i);
				writer.write(charInt);
			}
		} catch(Exception e){
			//handle the exception
			e.printStackTrace();
		} finally {
			//Always close reader or writer
			if(writer != null) // prevent another exception
				writer.close();
		}
		try {
			reader = new FileReader("hi.txt");
			writer = new FileWriter("hello.txt");
			int c;
			while((c = reader.read()) != -1) {
				char intChar = (char) c;
				System.out.print(intChar);
				writer.write(c);
			}
			System.out.println();
		} finally {
			if(reader != null)
				reader.close();
			if(writer != null)
				writer.close();
		}
		try {
			input = new InputStreamReader(System.in);
			writer = new FileWriter("namaste.txt");// greeting
			char c;
			System.out.println("Enter q to quite.");
			do {
				c = (char) input.read();
				if (c != 'q') { // won't store q
					writer.write(c);
				}
			} while (c != 'q');
		} finally {
			if(input != null)
				input.close();
			if(writer != null)
				writer.close();
		}
	}
}

We need to declare the variables (6,7,8) outside the try catch block as we need to close them in the finally block if they are used.
We iterate through the String to get each char to write in file (line 14), message.charAt(2) will return the char at index 2 of that String.
(Line 24) we must close the opened file. check it is not null before closing so it won't generate another exception (no file opened to close)
(Line 32) Type casting from int to char.
(Line 49) input.read() waits till users enter a char in the Terminal.

Thank you! Have a good day!

The Static Keyword means that the variables or methods are shared between all instances of that class as it belongs to the type, not the actual objects themselves.

So you can access static method of a class without it's object. For non static methods, every methods are associated with a object so you should call those non static method using your object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class Test {
    private int countObj;
    public Test() {
        countObj++;
    }
    public static void main(String args[]) {
        System.out.println("Hello, I am static.");
        aStatic();
        System.out.println("Calling non Static Method Directly.");
        nonStatic(); // not allowed
        Test aTest = new Test;
        System.out.println("Calling non Static Method via from object");
        aTest.nonStatic(); // Allowed 
    }
    static void aStatic() {
        System.out.println("Inside aStatic");
    }
    void nonStatic() {
        System.out.println("This is non Static Method.")
    }
}

We can call static methods from any methods of type class with it's name only, where as we need to specify the class to call from other class methods. Test.aStatic();
the countObj is a static variable so it is same for all the instance of the class. It will count the object created.
Thank you!
database management system.
query language.
structured query blanguage.
database design, store, update retrive data.
DDL data defination language. define structure (tubular form). eg create
DML Data manupulation language. systex to manupalate data, insert delete update, truncate, alter
DCL DAta control language, access specification, grant, revoke.

Truncate only erase values, structure remain same. only for table.
delete individual element and tables.

Lab...
Oracal Database Express Eddition

only one comand at a time.


Some commands:
create table t(id int, name varchar);

insert into t values(1, "test");
or
insert into t(id, name) values(2, "test2");

select * from t;
select id,name from t;
select * from t where id = 1;
select id from t where id = 1;5:52 AM 12/23/2002
Java is a general purpose programming Language. James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. This was initially called "Oak", which was renamed as "Java" in 1995. The development motive of java was to make a platform independent language that can create create softwares that can be embedded in various consumer electronic devices.

General Purpose Programming Language

A general-purpose language is a computer language that is broadly applicable across application domains, and lacks specialized features for a particular domain. This is in contrast to a domain-specific language (DSL), which is specialized to a particular application domain.

Features of java

  • Simple
  • Object-Oriented
  • Robust
  • Multihreaded
  • Architecture-Neutral
  • interpreted and High Performance
  • Distributed
  • Dynamic
  • Secure
  • Portable
A Simple java Program:

class JavaFirst
{
    public static void main(String args[])
    {
        System.out.println("Hello World!");
    }
}

Java Keywords


abstract final public
assert finally return
boolean float short
break for static
byte goto strictfp
case if super
catch implements switch
char import synchronized
class instanceof this
const int throw
continue interface throws
default long transient
do native true
double new try
else null void
enum package volitile
extends private while
false protected

Enhanced For Loop in Java

Enhanced loop was introduced on java 5. It is used to loop through the Arrays.
class LoopTest
{
    public static void main(String args[])
    {
         int numbers[]={10,11,12,13,14};
         for (int i : numbers)
         {
              System.out.println(i);
          }
     }
}
The Output of the Loop will be:
10
11
12
13
14

Array Declaration in Java

int [] a, b, c;
will create 3 arrays a, b and c
int a[], b ,c[];
will create 2 arrays a and c, where as a int variable b.

If we use the [] in front it will create all the variables as array.

Strings

In java String are not simply an array of characters. String is defined as objects. String are used to declare String variables. String objects have many special features and attributes that make them powerful.
.toUpperCase()
.toLowerCase()
.compareTo()
.indexOf()
.charAt()

The Bitwise Operators

Java defines several bit-wise operators which  can be applied to the integers, long, short, char and byte. Bit-wise operator works on bits and perform bit by bit operations.
Where a = 60 and b = 13
a = 0011 1100
b = 0000 1101
(Binary AND) a&b = 0000 1100
(Binary OR) a|b = 0011 110.1
(Binary XOR) a^b = 0011 0001
(Binary NOT) ~a = 1100 0011

Argument Passing

Call by Value and Call by Reference
When a primitive type is passed to a method, it is done by use of call-by-value. Object are implicitly passed by use of call-by-reference. 
Hello here is java code to change Infix expression to PostFix expression. infix expression is the expression we understand and do algebraic manipulation using BODMAS rule. Compilers uses PostFix expression to do calculation. Here we would make use of the stack we discussed in the previous articles.

If you are beginner in Java. The block at 10 - 13 is a initialization block.
Using constructor we set the max Size and the size of array to of that maxSize.
The core of this code is the method inToPostFix() Here we could explain the Algorithm in words

  1. Initialize the empty stack.(astack[])
  2. Scan each character of the given infix expression from left to right. (theExpression.charAt(i))
  3. If the scanner Character is an Operand then add it to post fix string (theFinalExpression)
  4. If the scanned character is an operator then
    1. If the stack is empty, push the scanner operator int the stack.
    2. If the stack is not empty then compare the precedence of the operator at the top of the stack. If the precedence of scanned is less then or equal to the precedence of operator at TOS, then pop TOS and add it to postfix string and push the scanned operator into the TOS. If the precedence of the scanned operator is higher then the operator at TOS then push operator to the stack.
  5. If the scanned character is opening parenthesis then push it on to the stack and continue the above process steps until closing parenthesis is not scanned. When we get closed parenthesis then pop the operators from the stack until we reach opening parenthesis and then pop opening parenthesis from stack.
  6. The process is continued until all the characters of infix expression are scanned. and pop all the remaining operators from stack and add them in to the postfix string in the way they pop out.
Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import java.util.Scanner;
class InToPostFix
{
 int maxSize;
 char astack[];
 int TOS;
 String theFinalExpression;
 String theExpression;
 
 {
  TOS = -1;
  theFinalExpression = "";
 }
 
 InToPostFix(int maxSize, String theExpression)
 {
  this.maxSize = maxSize;
  this.astack = new char [maxSize];
  this.theExpression = theExpression;
 }

 void inToPostFix()
 {
  for(int i = 0; i< maxSize ;i++)
  {
   char element = theExpression.charAt(i);
   if(isOperand(element))
    theFinalExpression = theFinalExpression + element;
   else if(isOperator(element))
   {
    if(stackIsEmpty())
     push(element);
    else
    {
     int a;
     a = checkThePrecedence(element);
     if(a == 3) // element is of higher precedence:w
      push(element);
     else if(astack[TOS] != '(')
     {
      char operator = pop();
      theFinalExpression = theFinalExpression + operator;
      push (element);
     }
    }
   }
   else if(element == '(')
    push(element);
   else if(element == ')')
   {
    char temp;
    while(astack[TOS] != '(')
    {
     temp = pop();
     theFinalExpression = theFinalExpression + temp;
    }
    pop();// Remove the '(' from stack
   }
  }
  //while(!(stackisEmpty())):q
  while(TOS != -1)
  {
   char temp = pop();
   theFinalExpression = theFinalExpression + temp;
  }
 }

 char pop()
 {
  char item = astack[TOS];
  TOS -= 1;
  return item;
 }
 
 int checkThePrecedence(char element)
 {
  char item = astack[TOS];
  int assign, assign2;
  if (item == '$')
   assign = 3;
  else if (item == '*' || item == '/')
   assign = 2;
  else //(item == '+' || item == '-')
   assign = 1;
  if (element == '$')
   assign2 = 3;
  else if(element == '*' || element == '/')
   assign2 = 2;
  else //(element == '+' || element == '-')
   assign2 = 1;
  if(assign2 > assign)
   return 3; // element is of higher precedence
  else if(assign2 == assign)
   return 2; // element is in same as in stack
  else //(assign2 < assign)
   return 1; // element is of lower precedence
 }

 boolean stackIsFull()
 {
  if(TOS == maxSize - 1)
   return true;
  else
   return false;
 }

 boolean stackIsEmpty()
 {
  if(TOS == - 1)
   return true;
  else
   return false;
 }
 
 void push(char element)
 {
  TOS += 1;
  astack[TOS] = element;
 }
 
 static boolean isOperand(char element)
 {
  if((element >='a' && element <='z') || (element >='A' && element <='Z'))
   return true;
  else
   return false;
 }
 
        static boolean isOperator(char element)
        {
                if(element == '+' || element == '-' || element == '*' || element == '/' || element == '$')
                        return true;
                else
                        return false;
        }

 void displayFinal()
 {
  System.out.println("The Final Exptession is:-\n" + theFinalExpression);
 }

 public static void main(String []args)
 {
  Scanner input = new Scanner(System.in);
  Scanner input2 = new Scanner(System.in);
  System.out.println("Enter the InFix expression");
  String theExpression = input.nextLine();
  int maxSize = theExpression.length();
  InToPostFix inToPostFix = new InToPostFix(maxSize, theExpression);
  inToPostFix.inToPostFix();
  inToPostFix.displayFinal();
  int option;
  int next = 1;
  while(next == 1)
  {
   System.out.println("Option:- \tTo do:\n1\tConvert another expression\n2\tExit this program");
   option = input2.nextInt();
   switch(option)
   {
    case 1:
    {
     System.out.println("Enter the InFix expression");
     theExpression = input.nextLine();
     maxSize = theExpression.length();
     InToPostFix inToPostFixOb = new InToPostFix(maxSize, theExpression);
     inToPostFixOb.inToPostFix();
     inToPostFixOb.displayFinal();
     break;
    }
    case 2:
    {
     next = 0;
     System.out.println("Thank you:)");
     break;
    }
    default:
     System.out.println("Please Enter a valid option");
   }
  }
 }
}

Here we use $ for power operation. Power has the highest precedence. We use while loop in the main function and switch case to match the options you selected and call the selected methods. If I need to explain any of the code above I will always be available in the comment section. Thank you!
Hello here is Circular Queue. Here we create two separate file for the class and the main method. Everything is simple and common code here. I would like to introduce a new style to initialize a instance variables. The code block from line no 7 to line no 10 on CircularQueue.java is a Initialization Block. The benefit of creating any initializing block is that every constructors on the class would use the block to initialize variables. To initialize the static variables we just use static keyword before the block.

Here is CircularQueue.java file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class CircularQueue
{
 int maxSize;
 int rear;
 int front;
 int aQueue[];
 {
  rear = -1;
  front = -1;
 }
 CircularQueue(int maxSize)
 {
  this.maxSize = maxSize;
  this.aQueue = new int[maxSize];
 }
 void enQueue(int item)
 {
  if(((rear+1) % maxSize) == front)
  {
   System.out.println("Queue is Full");
  }
  else
  {
   if (rear == front && front == -1)
   {
    front += 1;
   }
   rear = (rear+1) % maxSize;
   aQueue[rear] = item;
  }
 }
 void deQueue()
 {
  if(rear == front && rear == -1)
  {
   System.out.println("Queue is Empty.");
  }
  else
  {
   int item = aQueue[front];
   if(rear == front)
   {
    rear = -1;
    front = -1;
   }
   else
   {
    front = (front + 1) % maxSize;
   }
   System.out.println(item + " is deQueued from the Queue");
  }
 }
 
 String elementOrElements()
 {
  String send = (rear == front)? (" ") :("s ");
  return send;
 }
  
 void display()
 {
  int tmpfront = front;
  if(rear == front && rear == -1)
                {
                        System.out.println("Queue is Empty.");
                }
                else
  {
   System.out.println("The element"+ elementOrElements() + "on the Queue are:- ");
   for(int i=0; i<maxSize ; i++)
   {
    if(tmpfront != rear)
    {
     System.out.println(aQueue[tmpfront]);
     tmpfront = (tmpfront + 1) % maxSize;
    }
    else
    {
     System.out.println(aQueue[rear]);
     break;
    }
   }
  }
 }
}

And Here is CircularQueueTest.java file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class CircularQueueTest
{
 public static void main(String []args)
 {
  Scanner input = new Scanner(System.in);
  System.out.print("Enter total no of elements to be in the queue:- ");
  int maxSize = input.nextInt();
  CircularQueue queue = new CircularQueue(maxSize);
  int select;
  int term = 0;
  while (term == 0)
  {
   System.out.print("\nOption:\tTo Do:\n1\tTo push element.\n2\tTo POP element.\n3\tTo Display the Queue elements.\n4\tTo Exit the Program.\nEnter your option:- ");
                 select = input.nextInt(); 
   switch(select)
   {
    case 1:
    {
     System.out.print("Enter element to insert in the Queue:- ");
     int ele = input.nextInt();
     queue.enQueue(ele); 
     break;
    }
    case 2:
    {
     queue.deQueue();
     break;
    }
    case 3:
    {
     queue.display();
     break;
    }
    case 4:
    {
     term = 1;
     System.out.println("Thank you!");
     break;
    }
    default:
     System.out.println("Enter a valid options");
   }
  }
 }
}

To fully understand this code you need to figure out what actually (front + 1) % maxSize do. Take your time and do some calculation. It would be better if calculate it and figure out it by yourself.

Hint:- (front + 1) % maxSize and (rear+1) % maxSize will always return 0 or < maxSize.
Hello Today we are here with a code of Stack Implementation using Array. We had already discussed about stack. Here we use 3 methods
1. To Push the elements
2. To POP the element
3. To display the elements on the stack.

This is no complex code. What we need to remember is that we should initialize TOS as -1 initially. Most beginner users could face error on the 6th and 11th line of code. Here at first we first create a reference variable at line 6 and  create required length array in line 11.
If we use int aarray = new int[MaxSize]; in the class, it will create a zero-length array. as int MaxSize; means int MaxSize = 0;

Other are really simple algorithms. we need to check if Stack is full while pushing and need to check if stack is empty while using pop.

We need to increment TOS everytime we push a element and decrement whenever we pop a element.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.Scanner;
class Stack
{
 int TOS = -1;
 int MaxSize;
 int aarray[];
 
 Stack(int Max1Size)
 {
  this.MaxSize = MaxSize;
  this.aarray = new int[MaxSize];
 }
 void push(int a)
 {
  if(TOS == MaxSize - 1)
  {
   System.out.println("Stack is Full");
  }
  else
  {
   TOS += 1;
   aarray[TOS] = a;
   System.out.println(a +" is inserted in the Stack");
  }
  return;
  
 }
 void pop()
 {
  if (TOS == -1)
  {
   System.out.println("Stack is Empty.");
  }
  else
  {
   int item = aarray[TOS];
   TOS -= 1;
   System.out.println(item +" is poped Out from the Stack");
  }
  return;
 }
 void display()
 {
  if (TOS == -1)
  {
   System.out.println("Stack is Empty.");
  }
  else
  {
   System.out.println("Elements in Stack are:- ");
   for(int i = TOS; i >= 0; i--)
   {
    System.out.println(aarray[i]);
   }
  }
  return;
 }
}
public class StackTest
{
 public static void main(String args[])
 {
  Scanner input = new Scanner(System.in);
  System.out.println("Enter Maximum size of array");
  int MaxSize = input.nextInt();
  Stack astack = new Stack(MaxSize);
  int next = 0;
  while( next == 0)
  {
   System.out.println("\nOption:- \t To Do\n1 \t Push to stack. \n2 \t Pop from stack\n3 \t Display stack \n4 \t Exit the program");
   int select = input.nextInt();
   switch(select)
   {
    case 1:
     {
      System.out.println("Enter the element to push in the stack");
      int element = input.nextInt();
      astack.push(element);
      break;
     }
    case 2:
     {
      astack.pop();
      break;
     }
    case 3:
     {
      astack.display();
      break;
     }
    case 4:
     {
      next = 1;
      System.out.println("Thank You! :)");
      break;
     }
    default:
     {
      System.out.println("Please Enter a valid OPtion.");
      break;
     }
   }
  }
 }
}

This one of the code I had written at college in practical of DSA. Thank you :)
Please Follow How to Create Facebook Friends Day Video.
Today is facebook 14th Birthday. On that occasion facebook allow users to share video with friends. Sharing what they think about them. You can also share the facebook friends day video. There are a lots of options (award) to give to friends All of them are predefined, Facebook will create a short video for your friends. You could publish it on his/her timeline or can send him/her a private message.


History of Facebook?

On February 4, 2004, Mark Zuckerberg launched “Thefacebook”, originally located at thefacebook.com. In 2005, the company dropped “the” from its name after purchasing the domain name facebook.com for US$200,000 The domain facebook.com belonged to AboutFace Corporation before the purchase.

Mark Zuckerberg mention that he had made a lots of mistakes during the development of facebook. He mention "I’ve made dozens of technical errors and bad deals.", He also "I’m proud of what we do and grateful to be a part of something so meaningful." Facebook said there are a lots of path to go and they will work on to Improve Facebook.

Make Facebook Friends Day Video

We had already published this on Time and Update but due to some Server Error we could not serve that page. The Title is How to Create Facebook Friends Day Video.

You can make Facebook Friends Day Video just by following this link. facebook.com/friendsday. Then click in the Create options, Now select a friend and award a option that suits best. Now you can Click in next and confirm whether to send via message or Publish on his Timeline. Conform the process. You can also follow this video Guide.
      

Now it would take some time (about 30 secs ) for your video to be prepared, Then your friend and you can access that video if it was sent of message. If you posted on friends Profile it would be available to public to view.

Most Selected Awards in Facebook Friends Day

Facebook announced that they also celebrate the friends day and they will update the most selected awards among the facebook. Here is the most selected awards till now. There may be alter in ranking of the most selected awards. You can always find that on the friends day page.

Please do comment which of the award you give to most of your friends. I would select the 3rd one to my Friends as they always have my back when I don't have.
Hello, welcome back we are here with the next article of Get Started with Java Programming. Here we would be talking about Data Type, Operations, Decision Statement and loops. Java supports boolean data types as a primitive data type.

Data Type

Data type specify the the size and type of the values to be stored in the variable. Java have lots of data types which allow programmers to select appropriate data type they needed. In Java we can categorise data types into "Primitive types" and "Derived types". We will be discussing about build-in types(Primitive).

Integer Types

Integer can hold whole numbers. Java supports four type of integers, bytes, short, int, long. The size of the values that can be stored in a variables depends upon the type of integer. In the table below we specify Types size and value range:-
Type Size Minimum Value Maximun value
bytes One byte -128 127
short Two bytes -32768 32767
int Four bytes -2147483648 2147483647
long Eight bytes -9223372036854775808 9223372036854775807

Floating Point Types

floating point types can hold number combination fractional numbers. In Java there are two types of floating point integer float and double. In the table below range and size of these two types are specified. Floating points supports a special value know as Not-a-Number(NaN). NaN is used to represent the result of operation as dividing by zero. Float are of 4 bytes whereas double are of 8 bytes.

Other Types:

char:- Char is used to store character value in Java program.  This type is of 2 bytes but can hold only one single character.
boolean: In Java boolean is accepted as a primitive data type. Whenever we have to test a condition during the execution of the program this can be used. There are only two possible values of boolean type:- true or false. This use only one bit of storage.

Operators

A operation is symbol that tells the computer to perform certain mathematical or logical operations. we can classified into a numbers of categories:-
Arithmetic:- Used to conduct mathematical expressions as in algebra. +, -, *, /, % We can use Arithmetic operations on any build in data type except boolean type.
Lets Learn more about % operator:- the % operator will gives the remainder of the number. a % b will give the remender number (the remember while dividing a by b). The symbol of the value of the % will be based on the numerator.
10 % 3 == 1
10 % -3 == 1
-10 % 3 == -1
-10 % -3 == -1

Logical Operator:- && (and), ||(Or), !(Not). Logical operator will yield a value either true or false.
Var1 Var1 Var1! Var1 && Var1 Var1 || Var1
ture ture false ture ture
ture false false false ture
false ture ture false ture
false false ture false false

Relational Operator:- > , < , >= , <= , != Relation operator is used to compare two quantities. We can use these operation on selecting some task whenever some condition is satisfied.
Assignments Operator:- = , -= , += , *= , /= , %=
a +=b is similar to a = a + b
Equality:- == To show that thow of them are equal.
Unary:- ++ , -- Used for increment or decrement A = A + 1 is similar to A++
Ternary (conditional):- ?: Used as in if else condition. (Expression)?(Do this if true):(else do this);

Decision Statements

Decision statement are to make decision the the basic of the condition whether it is true or false. Java supports two discussion statements.
1. if statement
2. switch statement

if statement

if statement is used in decision making during the execution of the program. The if statement take of the following form:
if (condition)
{
    statements;
}
If the condition is true the statement will be executed else it will be skipped. Depending upon the complexity of the program if can takes various form as below:
  • if statement
  • if .. else statement
  • nested if else statement
  • else if statements 

Switch Statements

In switch statement statements are executed upon the required case are true. Switch case takes the following form.
switch (case){
case 1:
statement1;
case2:
statement2;
}
The program will check for the value of the variable case if it matches 1 statement1 will be executed if 2 statement2. we can define the default option in switch case too in case non case satisfied the statement in the default will be executed.

We can use any data types in if statements and any expression are accepted in if statements. But we can only make equality comparison on switch and only accept integer, char and Strings (allowed by Java SE 7).

Looping in Java

Java supports all the three looping namely while, do while and for loop. Loops are used when we need to execute certain part of the program repitately. Whenever a loop check the condition while entering in the loop such loop is known as entry control loop. When a loop checks the condition at exit such looping is known as exit control loop. While and for loop are entry control loop where as do while is exit control loop. We can set certain number of turns or we can set till some conditions happens.
Stack is a data structure, which is not provided by any programming language as fundamentals data type. The last element inserted will be on top of the stack. Since deletion is done from same end, last element inserted will be the first element to be removed out from the stack and so on.

A stack is ordered collection of homogeneous data elements where the insertion and deletion operations only occurs at one end. The end is often known as Top Of the Stack (TOS).

As stack is not provided by any programming language we need to create our own stak. Use of control + Z (undo) is done through the use of Stack, Reversing of the string and checking the validation and matching the parentheses in programming language in compiler are done using programming language.

How Stack Works?

Stack is a one ended operation system. There are only two operations permitted in stack, Push and pop. Push to insert in the stack where as pop to delete the element form the stack. The TOS (Top Of the Stack) always point to the top position where the next can be popped off. We can add another element on the (TOS + 1).

When ever we try to push to the stack when the stack is full then we get the error which is known as Stack Overflow. Whenever we try to pop out from the empty stack then we get an error which is known as stack underflow.

When the stack is empty TOS = -1 When we insert the first element the TOS will be on 0. When we add another element again the TOS will be 1 and so on. So when new element is inserted the TOS will be incremented. When we pop the element the TOS will reduced by one. Let say TOS is on 5 now. when we pop a element, New TOS will be 4 then when we pop again the TOS will be 3 and so on. As we will get an error when we try push to the stack which is full and try to pop from the empty stack so we should always check whether we can pop and push or not.

Stack Implementation

we can implement stack using these two ways:
Static implementation: Using array
Dynamic Implementation: Using linked list

Static Implementation

Here we use array to realize the principle of stack. In array we can insert the data and access the data. Here we use the array in a such a way that we will insert the element in the TOS and access the element from TOS. So by default when the stack is empty TOS is -1. (As array begins with 0, we make TOS to -1 for easiness). Then we insert the element in the TOS+1 location of the array. So we pass element to be added, array and the TOS when ever we want to insert data in the Stack. And in the same way we will remove a data from the stack and reduce the TOS by one, thus we pass array and TOS during pop.

Algorithm:
#define MAX=5
push(s[MAX],element,TOS)
  if TOS == MAX - 1
    display "Stack is full"
  else
    TOS = TOS+1
    s[TOS] = element
  return;

pop(s[MAX],TOS)
  if TOS == -1
    display "Stack is Empty"
    return 0
  else
    element = s[TOS]
    TOS = TOS -1
    return element

Application of Stack

It is used in recursive function calling. Function calling and returing process are in reverse order.
It is used to reverse a string.
It is used to evalutate and check the correction ness of the mathematical operation.
Implementation by word processors to perform UNDO REDO operations.
Used in parenthesis matching by compilers.

Details of the examples

How Parenthesis matching by compiler using Stack?

In every programming language there must be even numbers of parenthesis in the program. Here we will discuss how stack helps on parenthesis matching. So when we open a parenthesis the program will save that on the stack and search for next parenthesis. If it find another opening parenthesis it will add that on the stack again. And again keep looking for the parenthesis. When a closing parenthesis is found it will remove the pair (Opening and Closing) together and keep looking for parenthesis. If at the end The stack is empty there is not error in parenthesis else of the stack is not empty, there must error in parenthesis.

Stack for UNDO and REDO

Every actions will be stored in stack. so when we undo it the last command will be removed. if undo again the second last command and third last and going on..... In the same way the poped commands will be stored in another stack in case of REDO. so when we press redo we will get the last undo and the undo then after and then after.
We will be discussing about data structure. You should have knowledge in basic programming. We will be using C and Java for some example programming. Here we would discuss about Array, Structure, Pointer and Class. These are the topics we will be using throughout this article series in Data Structures.

Array

Array is primitive data member provided by C programming. Array is the collection of similar data types. Memory allocation of the array is sequential. ie. Array are stored in contiguous block of memory. Array only supports similar data type. Strings are the array of character with \0 at the end. \0 = NULL

Structure

Structure is the collection of different type of data type. In C programming Structure is the only way to create complex data type. Structure is the heterogeneous collection of data. Theoretically it will not occupy any memory unless we create the variable of that Structure. Memory allocation  of structure is sequential. We can access members of array with dot operation(.) and Arrow operation(->). Dot operation is used to access memory of structure variables. and Arrow operation is used to access members from Pointer of the structure.

1
2
3
4
5
6
struct Person
{
    char name[30];
    int age;
    char address[40];
}

Self Referencial Structure

The structure that is pointing to self is called self referential structure. Ie a member of structure is pointer to that structure
struct list

1
2
3
4
5
struct List
{
    int age;
    struct List *next;
}

Union

It is similar as of the structure. The only difference is that union only occupy the memory of the largest member data. So we car use only one data of the union at a time. Can there be pointer to union? yes they can be :)

Courses to Complete During Software Engineering

Pointer

What is pointer in a word? A pointer is a variable. A pointer is a reference variable which store memory location. All the pointer occupy same memory bits. The pointer of the floating point data and the integer data. will occupy only 2 bits of memory. What is Void Pointer and null pointer? Void pointer is the pointer that can point to any kind of data type. This make use of type casting to to this job. Null pointer os the pointer which points to non or invalid address. Remember Structure pointer can only point to structure.

float data type is of 4 bit of memory, so when pointer points to the floating point it will point the base address of the variable. Points to the starting block of the memory for that variable.

Class

A class is data type. class is user defined variable that can be used to create objects. The difference between the structure and the class is that class have methods (Behaviour) which structure does not have. When ever the object are created the members are copied to the variables but not the methods. All the objects share the same methods. What is Abstract class? The class which have pure virtual function and cannot make any object.

Abstract means hiding the implementation details. We Drive the car but it is no concern to use how all the functions in the car works.
Java is a general-purpose, Object Oriented Programming Language high level programming language. It was developed by Sun Microsystem in 1991. Originally James Gosling, Mike Sheridian, Patrick Naughton start a project named "Green Project". They were developing special software for consumer electronic devices. They name this new programming language as "Oak". The World Wide Web appeared, then they develop a web browser called "HotJava" using the new programming language they developed, which demonstrate the Power the Programming language and it become popular among the internet. They Rename "Oak" into "Java" in 1995.

To run a java code in any machine we need JRE (Java Runtime Environment). JVM is a component of JRE. JVM(Java Virtual Machine). All programming language compilers translate source code into machine code for special computer. However Java first compile the java Source code into a bytecode for a the JVM. Then java interpreter generate the machine specific code. This is why java is Platform Independent. Any code written and compiled in Linux machine could be interpreted and run on Windows machine.

A java source file Hello.java is first compiled using compiler (Javac) which will generate a bytecode Hello.class then Java Interpret(Java) will gives the output. JDK(Java Development Kit)is used for java program development. JRE will be automatically installed when JDK is installed in the system. In Windows machine we need to set environmental variables to run Java or Javac command in Command Prompt. For that Right Click in My Computer and Click properties. Then Click in Environmental Variables. Add "path" as a name and <Location of java installation> in value field in System Variables. The location should be like "c:\program files\java\jdk\bin"

We set up the Environment verialbes now we are ready to go to Run our First Program

1
2
3
4
5
6
7
8
9
class Hello
{
        public static void main(String args[])
        {
                System.out.print("Hello ");
                System.out.println("Java ");
                System.out.println("Welcome to Java");
        }
}

Java contents Packages with any prederined functions and class to use while programming in java. Packages are those refered as Class Libararies in other programming language. While Defining Identifier. Always use UpperCase first character of class and every first Letter of next word without any space. for Functtion name use first lowercase and next word's first character as a UpperCase.
Identifier Examples:-
Class Name:- Hello, HelloJava, WelcomeToJavaProgramming
Method name:- display(), displayMessage(), displayNewMail()

In the above program we use String and System class from Package java.lang We should alway import the package name before using them in our program. But java.lang is a basic package which will be automaticlly inserted.

import java.lang.String will import only that class where as import java.lang.* will import all the classes in that Package. It is better to use .* while during studying purpose but for development we will impor individual package as required.

As java is purely object oriented programming language, we need to create at least one class to run the java program. The main function is automatically called when executing the program. ie the execution of the program starts from the main function. Main function is Public, can be accessed by outer function, Static because no object is created to call the main function. void as it do not return anything. The main function is called using the class name as Hello.main()

String args[] are known as Command line arguments. We could pass arguments to the main function from command line.
Check: Java, General-purpose Programming Language

Prerequisites:- Basic Knowledge of Object Oriented Programming.