Java67 - Java Program Example Tutorial Blog

Java67 - Java Program Example Tutorial Blog


How Constructor Chaining works in Java - Example

Posted: 31 Dec 2012 05:07 AM PST

How to call one constructor from other constructor in Java or What is Constructor Chaining in Java is one of the tricky questions in Java interviews. Well you can use this keyword to call one constructor from other constructor of same class, if you want to call constructor from based class or super class than you can use super keyword. Calling one constructor from other is called Constructor chaining in Java. Constructors can call each other automatically or explicitly using this() and super() keywords. this() denotes a no argument constructor of same class and super() denotes a no argument or default constructor of parent class. Also having multiple constructor in same class is known as constructor overloading in Java.
Read more »


1 comment

Post a Comment

javarevisited

javarevisited


Top 10 Oracle Interview Question and Answer - Database and SQL

Posted: 31 Dec 2012 02:58 AM PST

These are some interview question and answer asked during my recent interview. Oracle interview questions are very important during any programming job interview. Interviewer always want to check how comfortable we are with any database either we go for Java developer position or C, C++  programmer position .So here I have discussed some basic question related with oracle database. Apart from these questions which is very specific to Oracle database you may find some general questions related to database fundamentals and SQL e.g. Difference between correlated and noncorrelated subquery in database  or truncate vs delete in SQL etc. Some of the most important topics in Oracle Interview questions are SQL, date, inbuilt function, stored procedure and less used features like cursor, trigger and views. These questions also gives an idea about formats of questions asked during Oracle Interview.
Read more »


Post a Comment

Step by Step Video Tutorials on Java Frameworks

Step by Step Video Tutorials on Java Frameworks


The future of Learning is bright.

Posted: 31 Dec 2012 12:14 PM PST

There is a reason Movie stars make a lot more money than those in Theater. It is the same reason why we had software moguls like Bill Gates and Larry Ellison dominate the world's richest list for decades. You make it once and sell it multiple times unlike a car manufacturer who needs input of steel and labor for every car.

Great money attracts great talent. You may hate those on Wall Street, but having worked with them closely as a software developer, I can tell you those are the smartest people I have seen. They may screw up your money, but rarely themselves.
I believe most of the teachers, professors, trainers we come across are not good. The reason being the lack of monetary gain. You may be the best in your field, but you aren't becoming a millionaire teaching. The math works like the car manufacturer; you need to invest your time and resource every time to teach. Thankfully with the advent of digital age I believe this will change. Let's record the teacher and play it again and again.

I think a great training will foresee all questions and makes sure they are answered. Questions on alternatives and discussions can "Just be Googled"; every question has been asked and has been answered somewhere on the net and if not, ask it and it will be answered. This has a great advantage; you can get the best teachers from around the world, handling the subjects.
Flickr: US Army Corps
Think of all the teachers you had in school and college, you might have had just one or two who gave you a great experience. Imagine those kinds of teachers handling all your subjects. I believe Math is easy, but most children dread it because of the poor teachers. I still remember a day in eighth grade when I was dreading a Math test. I had failed the previous one and eighth grade math was getting too complex for me to handle. Out of desperation I approached my Dad who was pretty disappointed with my Math skills, but in a matter of few hours he trained me on all topics that were covered in the previous months. Needless to say, I scored a hundred the very next day. That single incident, proved to me one thing, that I am not stupid! (That was some relief) I have to be taught a certain way.

That incident may be the founding reason why I am a trainer today. I want to be my Dad to people like me. The ones who have a fine head, but need to be explained logically. That is the reason I made the now popular hibernate videos. Almost everyone who went through those videos, even if they had poor Java skills, where able to learn the Hibernate Framework.
I made the Java training videos at PatrickVideos.com for those who wrote to me and explained their difficulty in understanding Java. It is only 4 hrs long, but that is all is required to understand Java. Not those months of lectures. Once you have my foundation all the advanced topics will be easy.
Flickr: CECAR
I believe the future is going to be online learning. We will still have schools but they will be required as cheap babysitters. I think the future school teachers will act more like coordinators rather than teachers. The students will learn online sitting in their classrooms and they will have a choice of various teachers' prerecorded video presentations, depending on their style of learning. The colleges I believe will be more for internship.

We are not too far away from that future. TheNewBostonand KhanAcademy have trained more people than any teacher in history. I don't consider them the best, but they have sowed the seeds, the best are yet to come. The smartest brains follow the money.


Post a Comment

programming languages tutorials

programming languages tutorials


foreach statement in php

Posted: 31 Dec 2012 01:28 AM PST

foreach Statement:

The foreach statement is used to loop through arrays.
For every loop, the value of the current array element is assigned to $value (and the array pointer is moved by one) so on the next loop, you'll be looking at the next element.
Syntax
foreach (array as value)
{
code to be executed;
}

Example

<html>
<body>
<?php
$arr=array("one", "two", "three");
foreach ($arr as $value)
{
echo "Value: " . $value . "
";
}
?>
</body>
</html>

Output;

one
two 
three

for Statement in php

Posted: 31 Dec 2012 01:19 AM PST

for Statement
The for statement is used when you know how many times you want to execute a statement or a list of statements.
Syntax
for (initialization; condition; increment)
{
code to be executed;
}

Note:

The for statement has three parameters. The first parameter initializes variables, the second parameter holds the condition, and the third parameter contains the increments required to implement the loop. If more than one variable is included in the initialization or the increment parameter, they should be separated by commas. The condition must evaluate to true or false.
Example

<html>
<body>
<?php
for ($i=1; $i<=5; $i++)
 {
 echo "Hello World!";
}
?>

≤html>
Output
Hello World
Hello World
Hello World
Hello World
Hello World

do...while Statement in php

Posted: 31 Dec 2012 01:14 AM PST

The do...while Statement
The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true.
Syntax

do
{
code to be executed;
}
while (condition);



Example
The following example will increment the value of i at least once, and it will continue incrementing
the variable i as long as it has a value of less than 5:



<html>
<body>
<?php
$i=0;
do
{
$i++;
echo "The number is " . $i . " ";
}
while ($i<5)
</body>
</html>


Post a Comment

Java67 - Java Program Example Tutorial Blog

Java67 - Java Program Example Tutorial Blog


How Constructor Chaining works in Java - Example

Posted: 31 Dec 2012 05:07 AM PST

How to call one constructor from other constructor in Java or What is Constructor Chaining in Java is one of the tricky questions in Java interviews. Well you can use this keyword to call one constructor from other constructor of same class, if you want to call constructor from based class or super class than you can use super keyword. Calling one constructor from other is called Constructor chaining in Java. Constructors can call each other automatically or explicitly using this() and super() keywords. this() denotes a no argument constructor of same class and super() denotes a no argument or default constructor of parent class. Also having multiple constructor in same class is known as constructor overloading in Java.
Read more »


Post a Comment

javarevisited

javarevisited


How to compare Arrays in Java – Equals vs deepEquals Example

Posted: 30 Dec 2012 04:47 AM PST

java.util.Arrays class provides equals() and deepEquals() method to compare two Arrays in Java. Both of these are overloaded method to compare primitive arrays e.g. int, long, float, double and Object arrays e.g. Arrays.equals(Object[] , Object[]). Arrays.equals() returns true if both Arrays which it is comparing are null, If both array pointing to same Array Object or they must be of same length and contains same element in each index. In all other cases it returns false. Arrays.equals() calls equals() method of each Object while comparing Object arrays. One of the tricky question in Java related to Array comparison is Difference between Arrays.equals() and Arrays.deepEquals() method.  Since both equals and deepEquals is used for array comparison, what is difference between them becomes important. Short answer of this questions is that, Array's equals() method does not perform deep comparison and fails logical comparison in case of nested Array,  on other hand deepEquals() perform deep comparison and returns logical comparison in case of nested array.
Read more »

How to append text into File in Java – FileWriter Example

Posted: 29 Dec 2012 09:15 PM PST

Some times we need to append text into File in Java instead of creating new File. Thankfully Java File API is very rich and it provides several ways to append text into File in Java. Previously we have seen how to create file and directory in Java and how to read and write to text file in Java and in this Java IO tutorial we will see how to append text into file in Java. We are going to use standard FileWriter and  BufferedWriter approach to append text to File. One of the key point to remember while using FileWriter in Java is to initialize FileWriter to append text i.e. writing bytes at the end of File rather than writing on beginning of the File. In next section we will see complete Java program to append text into File in Java.  By the way you can also use FileOutputStream instead of FileWriter if you would like to write bytes, instead of text. Similar to FileWriter, FileOutputStream constructor also takes a boolean append argument to open connection to append bytes into File in Java.
Read more »


Post a Comment

Java67 - Java Program Example Tutorial Blog

Java67 - Java Program Example Tutorial Blog


Producer Consumer Problem with Wait and Notify Example

Posted: 30 Dec 2012 12:57 AM PST

Producer Consumer Problem is a classical concurrency problem and in fact it is one of the concurrency design pattern. In last article we have seen solving Producer Consumer problem in Java using blocking Queue but one of my reader emailed me and requested code example and explanation of solving Producer Consumer problem in Java  with wait and notify method as well, Since its often asked as one of the top coding question in Java. In this Java tutorial, I have put the code example of wait notify version of earlier producer consumer concurrency design pattern. You can see this is much longer code with explicit handling blocking conditions like when shared queue is full and when queue is empty. Since we have replaced BlockingQueue with Vector we need to implement blocking using wait and notify and that's why we have introduced produce(int i) and consume() method. If you see I have kept consumer thread little slow by allowing it to sleep for 50 Milli second to give an opportunity to producer to fill the queue, which helps to understand that Producer thread is also waiting when Queue is full.
Read more »


Post a Comment

While statement in PHP

The While Statement
The while statement will execute a block of code if and as long as a condition is true.

Syntax:
while (condition)
code to be executed;

Example
The following example demonstrates a loop that will continue to run as long as the variable i is less than, or equal to 5. i will increase by 1 each time the loop runs:
<?php
            $i=1;
            while($i<=5)
            {
                        echo "The number is " . $i . "
                        $i++;
            }
?>


Post a Comment

programming languages tutorials


programming languages tutorials


Posted: 30 Dec 2012 04:56 AM PST
The while Statement
The while statement will execute a block of code if and as long as a condition is true.
Syntax
while (condition)
code to be executed;
Example
The following example demonstrates a loop that will continue to run as long as the variable i is
less than, or equal to 5. i will increase by 1 each time the loop runs:

<html>
<body>
<?php
$i=1;
while($i<=5)
{
echo "The number is " . $i . "
$i++;
}
?>
Posted: 30 Dec 2012 04:51 AM PST
PHP Looping:

Looping statements in PHP are used to execute the same block of code a specified
number of times.
Looping Very often when you write code, you want the same block of code to run a number of times. You
can use looping statements in your code to perform this.

In PHP we have the following looping statements:

• while - loops through a block of code if and as long as a specified condition is true

• do...while - loops through a block of code once, and then repeats the loop as long as a
special condition is true

• for - loops through a block of code a specified number of times

• foreach - loops through a block of code for each element in an array
Posted: 30 Dec 2012 04:48 AM PST
Multidimensional Arrays
In a multidimensional array, each element in the main array can also be an array. And each
element in the sub-array can be an array, and so on.
Example
In this example we create a multidimensional array, with automatically assigned ID keys:

$families = array
(
"Griffin"=>array
(
"Peter",
"Lois",
"Megan"
),
"Quagmire"=>array
(
"Glenn"
),
"Brown"=>array
(
"Cleveland",
"Loretta",
"Junior"
)
);

The array above would look like this if written to the output:


Array
(
[Griffin] => Array
(
[0] => Peter
[1] => Lois
[2] => Megan
)
[Quagmire] => Array
(
[0] => Glenn
)
[Brown] => Array
(
[0] => Cleveland
[1] => Loretta
[2] => Junior
)
)



Post a Comment

Operators Precedence in C

Operators Precedence in C
Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator:

For example x = 7 + 3 * 2; Here x is assigned 13, not 20 because operator * has higher precedence than + so it first get multiplied with 3*2 and then adds into 7.

Here operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first.

Category  Operator Associativity 
Postfix () [] -> . ++ - -   Left to right 
Unary  + - ! ~ ++ - - (type)* & sizeof  Right to left 
Multiplicative   * / % Left to right 
Additive  + -  Left to right 
Shift   << >>  Left to right 
Relational  < <= > >=  Left to right 
Equality   == !=  Left to right 
Bitwise AND  Left to right 
Bitwise XOR  Left to right 
Bitwise OR  Left to right 
Logical AND &&  Left to right 
Logical OR  ||  Left to right 
Conditional ?:  Right to left 
Assignment  = += -= *= /= %=>>= <<= &= ^= |= Right to left 
Comma  Left to right 


Example
Try following example to understand the operator precedence available in C programming language:

#include <stdio.h>

main
()
{
int a = 20;
int b = 10;
int c = 15;
int d = 5;
int e;

e
= (a + b) * c / d; // ( 30 * 15 ) / 5
printf
("Value of (a + b) * c / d is : %d\n", e );

e
= ((a + b) * c) / d; // (30 * 15 ) / 5
printf
("Value of ((a + b) * c) / d is : %d\n" , e );

e
= (a + b) * (c / d); // (30) * (15/5)
printf
("Value of (a + b) * (c / d) is : %d\n", e );

e
= a + (b * c) / d; // 20 + (150/5)
printf
("Value of a + (b * c) / d is : %d\n" , e );

return 0;
}

When you compile and execute the above program it produces following result:

Value of (a + b) * c / d is : 90
Value of ((a + b) * c) / d is : 90
Value of (a + b) * (c / d) is : 90
Value of a + (b * c) / d is : 50


Post a Comment

Misc Operators ↦ sizeof & ternary

Misc Operators ↦ sizeof & ternary
There are few other important operators including sizeof and ? : supported by C Language.

OperatorDescriptionExample
sizeof()Returns the size of an variable.sizeof(a), where a is integer, will return 4.
&Returns the address of an variable.&a; will give actual address of the variable.
*Pointer to a variable.*a; will pointer to a variable.
? :Conditional ExpressionIf Condition is true ? Then value X : Otherwise value Y


Example
Try following example to understand all the miscellaneous operators available in C programming language:

#include <stdio.h>

main
()
{
int a = 4;
short b;
double c;
int* ptr;

/* example of sizeof operator */
printf
("Line 1 - Size of variable a = %d\n", sizeof(a) );
printf
("Line 2 - Size of variable b = %d\n", sizeof(b) );
printf
("Line 3 - Size of variable c= %d\n", sizeof(c) );

/* example of & and * operators */
ptr
= &a; /* 'ptr' now contains the address of 'a'*/
printf
("value of a is %d\n", a);
printf
("*ptr is %d.\n", *ptr);

/* example of ternary operator */
a
= 10;
b
= (a == 1) ? 20: 30;
printf
( "Value of b is %d\n", b );

b
= (a == 10) ? 20: 30;
printf
( "Value of b is %d\n", b );
}

When you compile and execute the above program it produces following result:

value of a is  4
*ptr is 4.
Value of b is 30
Value of b is 20


Post a Comment