Friday, February 28, 2014

Why Catching Throwable or Error is bad?

We often hear advice that catching Throwable or Error is bad practice and Java developer should avoid catching these, but have you thought Why? If language allows you to catch anything which is instance of java.lang.Throwable, then what is the problem of catching them or their subclass java.lang.Error? If they are bad, shouldn't Java itself has prohibited them from catching? Well this all looks good on theory, but not in real world programming. As I said before in Java Exception best practices post, Ideally you should never catch Throwable or in particular Error. There are several reasons why catching instance of java.lang.Throwable is bad idea, because in order to catch them you have to declare at your method signature e.g. public void doSomething() throws Throwable. When you do this, no body knows what kind of Error this method is going to throw, and until you know what is the problem, how can you resolve that. Main purpose of providing Exception handling mechanism is to handle error situation properly, but you can't a provide a solution which can solve all problems. That's why we have specific Exception classes e.g. FileNotFoundException, IllegalArgumentException, IOException and so on. So if you don't know how to resolve or handle error, there is no point catching Throwable, all it make your code hard to read and comprehend. Remember, each error handling code is driven by business/audit/reporting or quality requirement and catching Throwable just obscure those logics.
Read more �

Thursday, February 27, 2014

SQL Saturday #273 Recap

I attended and spoke at SQL Saturday #273 on February 22, 2014.








Selfie in @aboutsqlserver session



My presentation "SQL Server Security Easy Button" went off without a hitch. My presentation files can be found here.



This was the first time the event was held at the University of South Florida's College of Business Building on the main campus in Tampa, FL.  It was an excellent facility for a SQL Saturday. No crowding, no bottlenecks, great classrooms. The atrium in this building provided the perfect place for vendors to setup and for people to network. As usual, an excellent lunch was provided by Latam's. A college campus is the perfect venue for a SQL Saturday. They have well-equipped classrooms and it gives students a chance to interact with people who are working the real jobs for which they are studying. 



Our event provided another public service. We were able to thaw out several people from the Great White North. Tom LaRock, Allen White, Grant Fritchey to name only a few were successfully thawed. Thank you for coming. ;-)




The sessions I attended were:

"Eternal story on temporal objects" by Dmitri Korotkevitch.  Dmitri reviewed all the possible temporal objects that SQL Server used and demonstrated the best way to use them. Afterwards, Dmitri told me that his Twitter account gained 25 followers after myself and Grant Fritchey tweeted during his session. He said, he now has more followers than tweets! I told him that he had to be capable of one epic tweet per day. The pictures he used to illustrate tempdb amusingly demonstrated his talking points.














Allen White's "Managing SQL Server Efficiently with PowerShell Remoting". Allen did an excellent job demonstrating how remoting makes it much easier to manage multiple machines and describing the maturation of PowerShell. It's much easier to build and configure a new database instance on Windows Server 2012 with the V4 cmdlets.













Chris Skorlinkski's "Your Best Interview Ever"

I was familiar with most of the material that Chris covered. The main concept I took away from this session was to have an "elevator speech" ready to describe yourself to potential employers. I loved the example he used for it. It accomplishes all the goals of an elevator speech. Identify yourself, describe what you can do, and what your objective is.













Thank you to Pam Shaw, Leigh Freijo, sponsors, speakers, and volunteers for putting on a great event! I especially appreciated that the volunteers printed and cut up the SpeedPass for the speakers!



Also, thank you to Brian Mitchell and Jonathan Keyahias for answering some questions I had related to projects I have in progress at work.



Finally, the best juggler at SQL Saturday #273 was Eric Wisdahl.
























Exercices corrigés en Langage C : TP5

Exercices corrigés en Langage C :



Exercice 1 : 

Réécrire la fonction longueur (strln dans string.h) qui calcul la longueur d’une chaîne de caractères.
Prototype : int longueur(char *)

Correction exercice 1 :

int longueur(char *chaine) 

int i=0 ; 

 while(chaine[i] != ‘\0’) 
i++ ; 
return i ; 


Exercice 2 : 

En utilisant la précédence lexicographique écrire une fonction qui convertie les chaînes de
caractères minuscules en chaînes de caractères majuscules.
Prototype : void majuscule(char *)

Correction exercice 2 :

#include<stdio.h> 
void majuscule(char *) ; 
main() 

 char chaine[] = "Ceci est une chaine !" ; 
  majuscule(chaine) ; 

 printf("%s\n",chaine) ; 

void majuscule(char *chaine) 


 int i=0; 

 while(chaine[i] != '\0') 

if ((chaine[i] >= 'a') && (chaine[i] <= 'z')) 
chaine[i] += (int)'A' - (int)'a' ; 
i++ ; 



Exercice 3 :

Ecrire un programme qui lit deux chaînes de caractères, et qui indique leur précédence
lexicographique dans le code de caractères de la machine (ici: code ASCII). On écrira pour cela la
fonction precedence qui récupère les deux chaînes en paramètre et qui retourne 1 si la première
chaîne précède la deuxième, 2 si la deuxième précède la première, 0 si elle sont égale.
Prototype : int precedence(char *,char *)

Correction exercice 3 :

#include <stdio.h> 
int precedence(char *,char *) ; 
main() 


 /* Déclarations */ 
char CH1[50], CH2[50]; /* chaînes à comparer */ 
int r ; 

/* Saisie des données */

 printf("Entrez la première chaîne à comparer : "); 
gets(CH1); 
printf("Entrez la deuxième chaîne à comparer : "); 
gets(CH2); 
r = precedence (CH1,CH2) ; 
if(r==0) 
printf("\"%s\" est égal à \"%s\"\n", CH1, CH2); 
else if (r == 1) 
printf("\"%s\" précède \"%s\"\n", CH1, CH2); 
else 
printf("\"%s\" précède \"%s\"\n", CH2, CH1); 

int precedence (char *CH1,char *CH2) 

int I; /* indice courant */ 
int r ; 

for (I=0; (CH1[I]==CH2[I]) && CH1[I] && CH2[I]; I++) ; 

if (CH1[I]==CH2[I]) 

r = 0 ; 
else if (CH1[I]<CH2[I]) 
r = 1 ; 
else 
r = 2 ; 
return r; 


Exercice 4 : 

Ecrire une procédure qui lit une chaîne de caractères et l'interprète comme un entier positif dans la
base décimale. On écrira 2 fonctions :
La fonction chaine2entier qui récupère une chaîne de caractère et retourne un entier.
Prototype : int chaine2entier(char *)
La fonction estentier qui récupère un caractère et retourne 0 s’il ne correspond pas à un chiffre 1
s’il correspond à un chiffre.
Prototype : int estentier(char) ;

Correction exercice 4 :

#include<stdio.h> 
int estentier(char) ; 
int chaine2entier(char *) ; 

 main() 

 /* Déclarations */ 
char CH[100]; /* chaîne numérique à convertir */ 
long N; /* résultat numérique */ 

printf("Entrez un nombre entier et positif : "); 
gets(CH); 
printf("%s\n",CH) ; 

N = chaine2entier(CH) ; 
if(N<0) 
printf("%s ne représente pas correctement un entier positif.\n", CH); 
else 
printf("La chaine %s a pour valeur %d\n" ,CH,N) ; 

 int chaine2entier(char *CH) 

int I; 
int N = 0 ; 
int OK = 1; 

for (I=0; OK && CH[I]; I++) 
if (estentier(CH[I])) 
N = N*10 + (CH[I]-'0'); 
else 
OK=0; 
if (OK) 
return N ; 
else 
return -1 ; 


int estentier(char c) 

if ((c>='0')&&(c<='9')) 
return 1 ; 
else 
return 0 ; 


Wednesday, February 26, 2014

10 Example of Lambda Expressions and Streams in Java 8

Java 8 release is just a couple of weeks away, scheduled at 18th March 2014, and there is lot of buzz and excitement about this path breaking release in Java community. One of feature, which is synonymous to this release is lambda expressions, which will provide ability to pass behaviours to methods. Prior to Java 8, if you want to pass behaviour to a method, then your only option was Anonymous class, which will take 6 lines of code and most important line, which defines the behaviour is lost in between. Lambda expression replaces anonymous classes and removes all boiler plate, enabling you to write code in functional style, which is some time more readable and expression. This mix of bit of functional and full of object oriented capability is very exciting development in Java eco-system, which will further enable development and growth of parallel third party libraries to take advantage of multi-processor CPUs. Though industry will take its time to adopt Java 8, I don't think any serious Java developer can overlook key features of Java 8 release e.g. lambda expressions, functional interface, stream API, default methods and new Date and Time API. As a developer, I have found that best way to learn and master lambda expression is to try it out, do as many examples of lambda expressions as possible. Since biggest impact of Java 8 release will be on Java Collections framework its best to try examples of Stream API and lambda expression to extract, filter and sort data from Lists and Collections. I have been writing about Java 8 and have shared some useful resources to master Java 8 in past. In this post, I am going to share you 10 most useful ways to use lambda expressions in your code, these examples are simple, short and clear, which will help you to pick lambda expressions quickly.
Read more �

Tuesday, February 25, 2014

Exercices corrigés en Langage C : TP4

Exercices corrigés en Langage C :



Exercice 1 : 

Ecrire un programme qui lit les dimensions L et C d'un tableau T à deux dimensions du type int
(dimensions maximales: 50 lignes et 50 colonnes). Remplir le tableau par des valeurs entrées au
clavier et afficher le tableau ainsi que la somme de tous ses éléments.
Pour cela on écrira les fonctions suivantes :

void RemplirTableau(void)
void AfficherTableau(void)

Correction exercice 1 :

#include <stdio.h> 
void RemplirTableau(void) ; 
void AfficherTableau(void) ; 

 int T[50][50]; /* tableau donné */ 
int L, C; /* dimensions */ 

main() 

/* Déclarations */ 
long SOM; /* somme des éléments - type long */ 

/* Saisie des données */ 
printf("Nombre de lignes (max.50) : "); 
scanf("%d", &L ); 
printf("Nombre de colonnes (max.50) : "); 
scanf("%d", &C );

 RemplirTableau() ; 

 AfficherTableau() ; 

 /* Calcul de la somme */ 

for (SOM=0, I=0; I<L; I++) 
for (J=0; J<C; J++) 
SOM += T[I][J]; 

/* Edition du résultat */ 
printf("Somme des éléments : %ld\n", SOM); 
return 0; 


void RemplirTableau(void) 

int i,j ; 

for (i=0; i<L; i++) 
for (j=0; j<C; j++) 

 printf("Elément[%d][%d] : ",i,j); 
 scanf("%d", &T[i][j]); 



void AfficherTableau(void) 

int i,j ; 

printf("Tableau donné :\n"); 
for (i=0; i<L; i++) 

 for (j=0; j<C; j++) 
printf("%d\t", T[i][j]); 
printf("\n"); 



Exercice 2 : 

Ecrire un programme qui réalise l'addition de deux matrices A et B de même dimension N x M (N
et M sont saisies au clavier).

rappel :

| a | b | + | a’ | b’ | = | a + a’ | b + b’ |
| c | d |   | c’ | d’ |   | c + c‘ | d + d’ |

Correction exercice 2 :

#include <stdio.h> 
main() 


 /* Déclarations */ 
int A[50][50]; /* matrice donnée */ 
int B[50][50]; /* matrice donnée */ 
int C[50][50]; /* matrice résultat */ 
int N, M; /* dimensions des matrices */ 
int I, J; /* indices courants */ 

/* Saisie des données */ 
printf("Nombre de lignes (max.50) : "); 
scanf("%d", &N ); 

printf("Nombre de colonnes (max.50) : "); 
scanf("%d", &M ); 
printf("*** Matrice A ***\n"); 
for (I=0; I<N; I++) 

for (J=0; J<M; J++) 

printf("Elément[%d][%d] : ",I,J); 
scanf("%d", &A[I][J]); 

printf("*** Matrice B ***\n"); 
for (I=0; I<N; I++) 
for (J=0; J<M; J++) 

printf("Elément[%d][%d] : ",I,J); 
scanf("%d", &B[I][J]); 

 /* Affichage des matrices */ 
printf("Matrice donnée A :\n"); 
for (I=0; I<N; I++) 

for (J=0; J<M; J++) 
printf("%7d", A[I][J]); 
printf("\n"); 

printf("Matrice donnée B :\n"); 
for (I=0; I<N; I++) 

for (J=0; J<M; J++) 
printf("%7d", B[I][J]); 
printf("\n"); 

 /* Affectation du résultat de l'addition à C */ 
for (I=0; I<N; I++) 
for (J=0; J<M; J++) 
C[I][J] = A[I][J]+B[I][J]; 

/* Edition du résultat */ 
printf("Matrice résultat C :\n"); 
for (I=0; I<N; I++) 

for (J=0; J<M; J++) 
printf("%7d", C[I][J]); 
printf("\n"); 

return 0; 


Exercice 3 : 

Ecrire un programme qui réalise le produit de deux matrices carrées de même dimension.

rappel :

| a | b | * | a’ | b’ | = | a*a’ + b*c’ | a*b’ + b*d’ |
| c | d |   | c’ | d’ |   | c*a’ + d*c‘ | c*b’ + d*d’ |


Correction exercice 3 :

#include <stdio.h> 
main() 

 /* Déclarations */ 
int A[50][50]; /* matrice donnée */ 
int B[50][50]; /* matrice donnée */ 
int C[50][50]; /* matrice résultat */ 
int N ; /* dimension des matrices (les matrices sont carrées)*/ 
int i,j,k; /* indices courants */ 

/* Saisie des données */ 
printf("Nombre de lignes et de colonnes (max.50) : "); 
scanf("%d", &N ); 

printf("*** Matrice A ***\n"); 

for (i=0; i<N; i++) 
for (j=0; j<N; j++) 



printf("Elément[%d][%d] : ",i,j); 
scanf("%d", &A[i][j]); 


printf("*** Matrice B ***\n"); 
for (i=0; i<N; i++) 


for (j=0; j<N; j++) 


printf("Elément[%d][%d] : ",i,j); 
scanf("%d", &B[i][j]); 



 /* Affichage des matrices */ 
printf("Matrice donnée A :\n"); 
for (i=0; i<N; i++) 


for (j=0; j<N; j++) 
printf("%7d", A[i][j]); 

printf("\n"); 

printf("Matrice donnée B :\n"); 
for (i=0; i<N; i++) 



for (j=0; j<N; j++) 
printf("%7d", B[i][j]); 
printf("\n"); 



 /* Affectation du résultat du produit à C */ 
for (i=0; i<N; i++) 
for (j=0; j<N; j++) 


C[i][j] = 0 ; 
for(k = 0 ; k<N ; k++) 
C[i][j] += A[i][k]*B[k][j]; 



/* Edition du résultat */ 
printf("Matrice résultat C :\n"); 
for (i=0; i<N; i++) 


for (j=0; j<N; j++) 
printf("%7d", C[i][j]); 
printf("\n"); 



Monday, February 24, 2014

How to Format and Display Number to Currency in Java - Example Tutorial

Displaying financial amount in respective currency is common requirement in Java based E-commerce applications. For example if you are selling products on-line globally, you will show price of product in their local currency rather than USD or some other currency. Storing price in every currency is not a good option because of maintenance, and more realistically fluctuation in exchange rates. That's why many of these application prefer stores price of books, electronic goods or whatever product they are selling in USD, and responsibility of converting that price to local currency and displaying is left to client side code. If your client is Java based client e.g. Swing GUI , Java FX client, or a JSP web page, you can use java.text.NumberFormat class to format currency in Java. NumberFormat class allows you to display price in multiple currency depending upon Locale supported by your Java version. All you need to do is to get correct Currency Instance based upon Locale, for example to display amount in US dollar, call NumberFormat.getCurrencyInstance() method with Locale as Locale.US, similarly to display currency as UK pound sterling, pass Locale.UK and for displaying money in Japanese Yen, pass Locale.JAPAN. Once you get the correct instance of currency formatter, all you need to do is call their format() method by passing your number. We will see an example of converting one currency to other and displaying amount in multiple currency in Java. It's actually very much similar to formatting date in Java, so if you are familiar to that part, it would be easy to format currency as well.
Read more �

Saturday, February 22, 2014

What is Eoraptor revisited 1 - Outside Eusaurischia?

You all know the big Eoraptor monograph was finally published as Sereno et al. (2013) containing the first detailed description of the material.  It may have taken 22(!) years from discovery to publication, but it's an excellent paper.  I previously examined the evidence Martinez et al. (2011) provided for Eoraptor being a sauropodomorph when they announced the idea in their Eodromaeus paper.  I found numerous coding issues and errors, such as composite codings and miscodings, which when partially corrected recovered a theropod Eoraptor instead, and also noted few of the proposed theropod characters had been included in their matrix.

Since then, we have the new basal theropod Daemonosaurus, redescriptions of basal sauropodomorphs Chromogisaurus and Pantydraco, redescriptions of all heterodontosaurids, redescriptions of the near/basal-dinosaurs Saltopus and Nyasasaurus, a version of Yates' analysis finding Eoraptor to be a sauropodomorph and more characters from Nesbitt's and Ezcurra's analyses finding it to be a theropod closer to Avepoda than herrerasaurids.  So let's explore the suggested evidence for each position for Eoraptor.  I'll list all novel suggested characters from each analysis, bolding the ones that seem valid.

Outside Eusaurischia (Sauropodomorpha+Theropoda)

 Padian et al. (1999)
1. centra of posterior cervical vertebrae (6-8) subequal in length to those of anterior dorsal vertebrae (refined by Langer, 2004).  This is untrue in Eoraptor, as cervicals 6-8 are 18-23 mm and the anterior dorsals are 16-17 mm.
2. third finger of the manus longer than second finger.  As this is true in Eodromaeus and Tawa, the opposite condition in known sauropodomorphs and avepods is probably convergent.  Herrerasaurus  also has III longer than II, while Guaibasaurus is like sauropodomorphs and avepods.  Though Tianyulong has an avepod-like condition, Heterodontosaurus and derived ornithischians have III longest, so this was more likely the basal condition in Ornithischia.
3. metatarsal I contacts tarsus.  Since this is also true in Sauropodomorpha, the authors had no reason to list it.  It only excludes Eoraptor from Avepoda.

Langer (2004)
4. subnarial premaxillary process extends posteriorly to the external naris.  This is also true in Daemonosaurus, making the basal condition for Theropoda ambiguous.  As Herrerasaurus has this state as well, it's even worse if herrerasaurids are theropods.
5. radius more than 80% of humerus length.  This is untrue in Eoraptor, which has a ratio of 74%.
6. manual ungual I shorter than metacarpal I.  This is untrue in Eoraptor, which has a ratio of 100%.  Note even if the ratio is actually barely in agreement, Eodromaeus and Tawa have short unguals I too, so it would be another character convergent in avepods and sauropodomorphs.
7. metacarpal III longer than metacarpal II.  Another character also present in Eodromaeus and Tawa, again making sauropodomorphs and avepods convergent. As with the digit length comparison, Guaibasaurus has longer II while Herrerasaurus has longer III.  Also while heterodontosaurids have longer II, other ornithischians and Saltopus have longer III, suggesting the former is convergence.
8. distal end of ischium unexpanded. This is untrue in Eoraptor.
9. medial margin of distal tibia not broader than lateral margin. This is untrue in Eoraptor.

Smith et al. (2007)
10. maxillary tooth count 12-18. Eoraptor has 17, while basal theropods have (9/10)-11 and basal sauropodomorphs don't preserve the area or have unreported counts.  As Saturnalia and Panphagia have 17 and 23 dentary teeth respectively, their maxillary counts were probably within the 12-18 range or higher, not lower as in basal theropods. Thus there is no shared derived state to differ from.
EDIT: Ugh, how could I forget Pampadromaeus?!  It has at least twenty maxillary teeth, proving my point.
11. lateral surface of anterior end of nasal along the posterior margin of the external naris flat.  Pantydraco and Daemonosaurus also lack this narial fossa, though Panphagia has it.  This means Theropoda is basally ambiguous while Sauropodomorpha is barely basally derived in having the fossa, so the character is not an unambiguous eusaurischian synapomorphy.  For what it's worth, Herrerasaurus also lacks the fossa.
12. posteroventral dentary process far posterior to posterodorsal process.  This is true in basal sauropodomorphs  (Panphagia, Pantydraco) and basal theropods (Eodromaeus, Tawa).  It's not true in ornithischians (Tianyulong, Heterodontosaurus, Eocursor) though, making the condition in Saurischia's outgroup ambiguous (given Silesaurus having the opposite condition).  Again for what it's worth, Herrerasaurus has the same condition as ornithischians.
13. foramen in the ventral part of the splenial absent.  This is difficult to code as the anterior splenial is thin and often broken.  In Sauropodomorpha, Panphagia has a foramen, Lamplughsaura is illustrated without one (though by Chatterjee, whose drawings are often idealized), Plateosaurus is polymorphic, and Lufengosaurus and Adeopapposaurus have it.  In Theropoda, Liliensternus lacks one, Dilophosaurus is illustrated as lacking one but seems to be anteriorly incomplete, and Ceratosaurus has one.  Thus the basal condition in either saurischian clade is unclear though more probably present in sauropodomorphs.  Ornithischians lack the foramen, as does Staurikosaurus though the latter has a poorly preserved mandible.
14. iliac supraacetabular crest shelf-like and short, extending primarily laterally.  This is also true in basal sauropodmorphs (Panphagia, Pampadromaeus) and basal theropods (Eodromaeus, Tawa).
15. ridge on lateral side of tibia for connection with fibula absent. This is untrue in Eoraptor

Yates (2007)
16. relationship between posterolateral process of the premaxilla and the anteroventral process of the nasal a broad sutured contact.  This is untrue in Eoraptor.
17. size and position of subnarial foramen small (no larger than adjacent maxillary neurovascular foramina) and positioned outside of narial fossa.  Basal theropods (Tawa, coelophysids, Dilophosaurus) lack a subnarial foramen, as do outgroups (ornithischians, Silesaurus).  Thus there is no obvious ancestral condition for the subnarial foramen, nor evidence theropods ancestrally had one.  Herrerasaurus does have this condition.
18. pointed posterolateral process of the nasal overlapping the lacrimal absent. This is untrue in Eoraptor.
19. length of middle to posterior cervical centra (6-8) no more than the length of the axial centrum. This is unknown in Eoraptor, as the axis is fragmentary.
20. laminae bounding triangular infradiapophyseal fossae on dorsal neural arches absent. This is untrue in Eoraptor.
21. transverse width of the first distal carpal less than 120% of the transverse width of the second distal carpal. This is unknown or untrue in Eoraptor, as distal carpal I is either unpreserved or diagenetically fused to the radiale in the left carpus and ~192% the width of distal carpal II. Notably, the basal theropods Eodromaeus and Tawa and basal sauropodomorph Efraasia have a small distal carpal I though, so this is not a eusaurischian character, though Heterodontosaurus does have a large distal carpal I so that ornithischians have an ambiguous basal state. Herrerasaurus has a small distal carpal I.

Martinez and Alcober (2009)
22. no caudosacral.  This is also true in basal theropods (Eodromaeus and Tawa) and ambiguous in sauropodomorphs (true in Pampadromaeus but not Efraasia and more derived taxa).  Guaibasaurus, Sanjuansaurus and Herrerasaurus also lack a caudosacral, though Staurikosaurus may have one.  Ornithischians have a caudosacral.
23. width of metacarpal I shaft less than 35% of length. This is untrue in Eoraptor.

Bittencourt Rodrigues (2010) also placed Eoraptor basal to Eusaurischia, but this paper has yet to be translated.

What's that?  No characters were bolded?  These turned out particularly bad, with almost half (10-11) not even being present in Eoraptor.  The others are basically all also found in taxa agreed to be basal theropods (11) and/or sauropodomorphs (7).  The best character is the absent anterior splenial foramen, which depends on illustration inaccuracy of a poorly preserved and seldomly exposed element.

Next up- is it a sauropodomorph?

References- Padian, Hutchinson and Holtz, 1999. Phylogenetic definitions and nomenclature of the major taxonomic categories of the carnivorous dinosaurs Dinosauria (Theropoda). Journal of Vertebrate Paleontology. 19(1), 69-80.

Langer, 2004. Basal Saurischia. In Weishampel, Dodson and Osmolska. The Dinosauria Second Edition. University of California Press. 861 pp.

Smith, Makovicky, Hammer and Currie, 2007. Osteology of Cryolophosaurus ellioti (Dinosauria: Theropoda) from the Early Jurassic of Antarctica and implications for early theropod evolution. Zoological Journal of the Linnean Society. 151, 377-421.

Yates, 2007. Solving a dinosaurian puzzle: The identity of Aliwalia rex Galton. Historical Biology. 19(1), 93-123.

Martinez and Alcober, 2009. A basal sauropodomorph (Dinosauria: Saurischia) from the Ischigualasto Formation (Triassic, Carnian) and the early evolution of Sauropodomorpha. PLoS ONE. 4(2), e4397.

Bittencourt Rodrigues, 2010. Revisao filogenetica dos dinossauriformes basais: Implicacoes para a origem dod dinossauros. Unpublished Doctoral Thesis. Universidade de Sao Paulo. 288 pp.

Martinez, Sereno, Alcober, Columbi, Renne, Montanez and Currie, 2011. A basal dinosaur from the dawn of the dinosaur era in Southwestern Pangaea. Science. 331, 206-210.

Sereno, Martinez and Alcober, 2013. Osteology of Eoraptor lunensis (Dinosauria, Sauropodomorpha). Journal of Vertebrate Paleontology. 32(Supplement to 6), 83-179.

Exercices corrigés en Langage C : TP3

Exercices corrigés en Langage C :

exercices corrigés en langage c


Exercice 1 :

Ecrire un programme qui saisit la dimension N d’un tableau de int (le tableau est initialement
définit avec une taille maximum MAX que N ne doit pas excéder) remplit le tableau par des valeurs
entrées au clavier et l’affiche.

Le programme doit ensuite effacer toutes les occurrences de la valeur 0 dans le tableau, tasser les
éléments restants et afficher le tableau ainsi modifier.

Pour cela écrire les fonctions suivantes :

void SaisirTableau (int *Tab, int N) ;
void AfficherTableau(int *Tab, int N) ;
int TasserTableau(int *Tab , int N) ;

Correction exercice 1 :

#include <stdio.h> 
#define MAX 50 
void SaisirTableau(int *, int ) ; 
void AfficherTableau(int *, int) ; 
int TasserTableau(int *, int) ; 
main() 

 /* Déclarations */ 
int T[MAX]; /* tableau donné */ 
int N,M; /* dimension */ 

/* Saisie de la dimension */ 
do 

printf("Dimension du tableau (max.%d) : ",MAX); 
scanf("%d", &N ); 
}while(N>MAX) ; 

/* Saisie des données */ 
SaisirTableau(T,N) ; 

 /* Affichage du tableau */ 
AfficherTableau(T,N) ; 

/*Tasser les elements du tableau */ 
M = TasserTableau(T,N) ; 

/* Edition des résultats */ 

AfficherTableau(T ,M) ; 


void SaisirTableau(int *Tab, int N) 

int i ; 

for (i=0; i<N; i++) 

printf("Elément %d : ", i); 
scanf("%d", &Tab[i]); 



void AfficherTableau(int *Tab, int N) 


int i ; 
printf("Tableau donné : \n"); 
for (i=0; i<N; i++)

 printf("%d ", Tab[i]); 
printf("\n"); 


int TasserTableau(int * Tab, int N) 

int i,j ; 

/* Effacer les zéros et comprimer : */ 
/* Copier tous les éléments de i vers j et */ 
/* augmenter j pour les éléments non nuls. */ 

for (i=0, j=0 ; i<N ; i++) 

Tab[j] = Tab[i] ; 
if (Tab[i]) 
j++ ; 

 /* La nouvelle dimension du tableau est retournée */ 
return j ; 


Exercice 2 :

Ecrire un programme qui saisit la dimension N d’un tableau de int remplit le tableau par des
valeurs entrées au clavier et l’affiche.

Copier ensuite toutes les composantes strictement positives dans un deuxième tableau Tpos et
toutes les valeurs strictement négatives dans un tableau Tneg. Afficher Tpos et Tneg.

Ecrire la fonction suivante :

int TrierTableau(int *, int *, int *,int)

Correction exercice 2 :

#include <stdio.h> 
#define MAX 50 
main() 

 /* Déclarations */

 /* Les tableaux et leurs dimensions */ 
int T[MAX], TPOS[MAX], TNEG[MAX]; 
int N,M, Npos, NNEG; 
int I; /* indice courant */ 

/* Saisie de la dimension */ 
do 

printf("Dimension du tableau (max.%d) : ",MAX); 
scanf("%d", &N ); 

}while(N>MAX) ; 

/* Saisie des données */ 

SaisirTableau(T,N) ; 

 /* Affichage du tableau */ 
AfficherTableau(T,N) ; 

/*Tasser les elements du tableau */ 
M = TasserTableau(T,N) ; 

/* Trier le tableau */ 
Npos = TrierTableau(T,TPOS,TNEG,M) ; 

/* Edition des resultats */ 
printf(”Elements positifs : \n”) ; 
AfficherTableau(TPOS,Npos) ; 
printf(”Elements négatifs : \n”) ; 
AfficherTableau(TNEG,N-Npos) ; 


int TrierTableau(int *T, int *TPOS, int *TNEG, int N) 


 int npos=0, nneg=0; 
int i ; 


 /* Transfert des données */ 

for (i=0; i<N; i++) 

if (T[i]>0) 

TPOS[npos]=T[i]; 
npos++; 

if (T[i]<0) 

TNEG[nneg]=T[i]; 
nneg++; 


return npos ; 


Exercice 3 :

Ecrire un programme qui calcul le produit scalaire de deux vecteurs d’entiers U et V de même
dimension.

Ecrire la fonction suivante :

long ProduitScalaire(int *U,int *V, int dimension)

Correction exercice 3 :

#include <stdio.h> 
#define MAX 50 
long ProduitScalaire(int *,int *, int) ; 
main() 

 /* Déclarations */ 
int U[MAX], V[MAX]; /* tableaux donnés */ 
int N; /* dimension */ 
int I; /* indice courant */ 
long PS; /* produit scalaire */ 

/* Saisie des données */ 
do 

printf("Dimension du tableau (max.%d) : ",MAX); 
scanf("%d", &N ); 
}while(N>MAX) ; 
printf("** Premier tableau **\n"); 
for (I=0; I<N; I++) 

 printf("Elément %d : ", I); 

 scanf("%d", &U[I]); 

printf("** Deuxième tableau **\n"); 
for (I=0; I<N; I++) 

 printf("Elément %d : ", I); 
 scanf("%d", &V[I]); 


 /* Calcul du produit scalaire */ 

PS = ProduitScalaire(U,V,N) ; 

/* Edition du résultat */ 
printf("Produit scalaire : %ld\n", PS); 


long ProduitScalaire(int *U, int *V,int N) 


long ps ; 
int i ; 

for (ps=0, i=0; i<N; i++) 
ps += (long)U[i]*V[i]; 
Return ps ; 


Friday, February 21, 2014

Fixing java.net.BindException: Cannot assign requested address: JVM_Bind in Tomcat, Jetty

Some of the most dreaded error in Java based client server based application is networking related error, e.g. java.net.BindException: Cannot assign requested address: JVM_Bind. I have faced this issue, while working with web servers like Tomcat, Jetty, and Weblogic before, but yesterday it came again, when one of my colleague faced this issue in Windows. As soon as Java programmers sees java.net.BindException, they come to conclusion that it's issue with two process listening on same port, and often mistook it for Java.net.BindException: Address already in use: JVM_Bind:8080, which is slightly different than this. If you look Java documentation for java.net.BindExcpetion, you will find this "Signals that an error occurred while attempting to bind a socket to a local address and port. Typically, the port is in use, or the requested local address could not be assigned." It's the second part, which is more interesting in case of java.net.BindException: Cannot assign requested address: JVM_Bind.
Read more �

Exercices corrigés en langage C: TP2

Exercices corrigés en Langage C :

langage C


Exercice 1 : 

Calculez la somme des N premiers termes de la série harmonique : 1 + 1/2 + 1/3 + ... + 1/N

Correction exercice 1 :

#include <stdio.h> 
main() 

int N; /* nombre de termes à calculer */ 

int I; /* compteur pour la boucle */ 
float SOM; /* Type float à cause de la précision du résultat. */ 

do 

printf ("Nombre de termes: "); 
scanf ("%d", &N); 
}while (N<1); 

for (SOM=0.0, I=1 ; I<=N ; I++) 
SOM += (float)1/I; 
printf("La somme des %d premiers termes est %f \n", N, SOM); 
return 0; 


Exercice 2 : 

Affichez un triangle isocèle formé d'étoiles de N lignes (N est fourni au clavier).

Correction exercice 2 :

#include <stdio.h> 
main() 

int LIG; /* nombre de lignes */ 
int L; /* compteur des lignes */ 
int ESP; /* nombre d'espaces */ 
int I; /* compteur des caractères */ 

do 

printf("Nombres de lignes : "); 
scanf("%d", &LIG); 
}while (LIG<1 || LIG>20); 
for (L=0 ; L<LIG ; L++) 

ESP = LIG-L-1; 
for (I=0 ; I<ESP ; I++) 
putchar(' '); 
for (I=0 ; I<2*L+1 ; I++) 
putchar('*'); 
putchar('\n'); 

return 0; 


Exercice 3 : 

a) Calculez la racine carrée X d'un nombre réel positif A par approximations successives en
utilisant la relation de récurrence suivante:

XJ+1 = (XJ + A/XJ) / 2 X1 = A

La précision du calcul J est à entrer par l'utilisateur.

b) Assurez-vous lors de l'introduction des données que la valeur pour A est un réel positif et que J
est un entier naturel positif, plus petit que 50.

c) Affichez lors du calcul toutes les approximations calculées :

 La 1ère approximation de la racine carrée de ... est ...
 La 2e approximation de la racine carrée de ... est ...
 La 3e approximation de la racine carrée de ... est ...
 . . .

Correction exercice 3 :

#include <stdio.h> 
main() 

double A; /* donnée */ 
double X; /* approximation de la racine carrée de A */ 
int N; /* degré/précision de l'approximation */ 
int J; /* degré de l'approximation courante */ 

do 

printf("Entrer le réel positif A : "); 
scanf("%lf", &A); 

}while(A<0); 
do 

printf("Entrer le degré de l'approximation : "); 
scanf("%d", &N); 

while(N<=0 || N>=50); 

 for(X=A, J=1 ; J<=N ; J++)

 { 
X = (X + A/X) / 2; 
printf("La %2d%s approximation de la racine carrée" 

" de %.2f est %.2f\n", J, (J==1)?"ère":"e", A, X); 

return 0; 


Exercice 4 :

Affiche la table des produits pour N variant de 1 à 10 :

X*Y I 0  1    2     3    4    5   6   7    8    9     10
0      I 0   0    0    0    0    0    0   0    0    0      0
1      I 0   1    2    3    4    5    6   7    8    9     10
2      I 0   2    4    6    8  10  12  14  16  18    20
3      I 0   3    6    9  12  15  18  21  24  27    30
4      I 0   4    8  12  16  20  24  28  32  36    40
5      I 0   5  10  15  20  25  30  35  40  45    50
6      I 0   6  12  18  24  30  36  42  48  54    60
7      I 0   7  14  21  28  35  42  49  56  63    70
8      I 0   8  16  24  32  40  48  56  64  72    80
9      I 0   9  18  27  36  45  54  63  72  81    90
10    I 0 10  20  30  40  50  60  70  80  90  100

Correction exercice 4 :

#include <stdio.h> 
main() 

 const int MAX = 10; /* nombre de lignes et de colonnes */ 

 int I; /* compteur des lignes */ 
 int J; /* compteur des colonnes */ 


 /* Affichage de l'en-tête */ 
printf(" X*Y I"); 
for (J=0 ; J<=MAX ; J++)


 printf("%4d", J); 
printf("\n"); 
printf("------"); 
for (J=0 ; J<=MAX ; J++)

 printf("----"); 
printf("\n");

 /* Affichage du tableau */ 
for (I=0 ; I<=MAX ; I++)

 { 
printf("%3d I", I); 
for (J=0 ; J<=MAX ; J++) 


printf("%4d", I*J); 
printf("\n"); 

 return 0; 

Thursday, February 20, 2014

Exercices corrigés en langage C: TP1

Exercices corrigés en Langage C :

langage c


Exercice 1 : 

Ecrire un programme qui lit un caractère au clavier et affiche le caractère ainsi que son code
numérique en employant getchar et printf,

Correction exercice 1 :

#include <stdio.h> 
main() 

 int C ; 

printf("introduire un caractère suivi de 'Enter'\n"); 
C = getchar(); 
printf("Le caractère %c a le code ASCII %d\n", C, C); 
return 0; 


Exercice 2 : 

Ecrire un programme qui calcule et affiche la distance DIST (type double) entre deux points A et B
du plan dont les coordonnées (XA, YA) et (XB, YB) sont entrées au clavier comme entiers.

Correction exercice 2 :

#include <stdio.h> 
#include <math.h> 
main() 



int XA, YA, XB, YB; 
double DIST;


 /* Attention: La chaîne de format que nous utilisons */ 
/* s'attend à ce que les données soient séparées par */ 
/* une virgule lors de l'entrée. */ 

printf("Entrez les coordonnées du point A : XA,YA "); 
scanf("%d,%d", &XA, &YA); 
printf("Entrez les coordonnées du point B : XB,YB "); 
scanf("%d,%d", &XB, &YB); 
DIST=sqrt(pow(XA-XB,2)+pow(YA-YB,2)); 
printf("La distance entre A(%d,% d) et B(%d, %d) est %.2f\n",XA, YA, XB, YB, DIST); 
return 0; 


Exercice 3 : 

Ecrivez un programme qui calcule les solutions réelles d'une équation du second degré
ax2+bx+c = 0 en discutant la formule.

Utilisez une variable d'aide D pour la valeur du discriminant b2-4ac et décidez à l'aide de D, si
l'équation a une, deux ou aucune solution réelle. Utilisez des variables du type int pour A, B et C.

Considérez aussi les cas où l'utilisateur entre des valeurs nulles pour A; pour A et B; pour A, B et

C. Affichez les résultats et les messages nécessaires sur l'écran.
Modifier le programme afin de considérer le cas des solutions complexes.

Correction exercice 3 :

#include <stdio.h> 
#include <math.h> 
main() 


/* Calcul des solutions réelles et complexes d'une équation du second degré */ 
int A, B, C; 
double D; /* Discriminant */ 

printf("Calcul des solutions réelles et complexes d'une équation du second \n"); 
printf("degré de la forme ax^2 + bx + c = 0 \n\n"); 
printf("Introduisez les valeurs pour a, b, et c : "); 
scanf("%i %i %i", &A, &B, &C);

 /* Calcul du discriminant b^2-4ac */ 
D = pow(B,2) - 4.0*A*C; 

/* Distinction des différents cas */ 
if (A==0 && B==0 && C==0) /* 0x = 0 */ 
printf("Tout réel est une solution de cette équation.\n"); 
else if (A==0 && B==0) /* Contradiction: c # 0 et c = 0 */ 
printf("Cette équation ne possède pas de solutions.\n"); 
else if (A==0) /* bx + c = 0 */ 

printf("La solution de cette équation du premier degré est :\n"); 
printf(" x = %.4f\n", (double)C/B); 

else if (D<0) /* b^2-4ac < 0 */ 

printf("Les solutions complexes de cette équation sont les suivantes :\n"); 
printf(”x1 = %.4f + i%.4f\n”, (double)(-B),(double)(sqrt(-D)/(2*A))) ; 
printf(”x2 = %.4f + i%.4f\n”, (double)(-B),(double)(-sqrt(-D)/(2*A))) ;

 } 
else if (D==0) /* b^2-4ac = 0 */ 

printf("Cette équation a une seule solution réelle :\n"); 
printf(" x = %.4f\n", (double)-B/(2*A)); 

else /* b^2-4ac > 0 */ 

printf("Les solutions réelles de cette équation sont :\n"); 
printf(" x1 = %.4f\n", (double)(-B+sqrt(D))/(2*A)); 
printf(" x2 = %.4f\n", (double)(-B-sqrt(D))/(2*A)); 
}
return 0; 

Wednesday, February 19, 2014

Top 30 Java Phone Interview Questions Answers for Freshers, 1 to 2 Years Experienced

In this article, I am sharing 30 core Java technical questions, from screening and phone round of interviews. In telephonic interviews, questions are short, fact based and Interviewer expects some keyword in answers. Accordingly, I have given very short answers to these question, only main points; just to make this as revision post. I am expecting every Java programmer to know answers of all these Java technical questions, if he has more than 4 to 5 years experience. it's only freshers, and junior developers who needs to do bit of research to understand topics well. I have tried to include all classical and hugely popular, frequently asked questions from different topics like String, multi-threading, collection, design pattern, object oriented design, garbage collection, generics and advanced Java concurrency questions. Since core Java interviewer's normally don't ask questions on JSP, Servlets and other JEE technologies, I have not included them into this list. Sole purpose of this list is to given freshers and less experienced developers an idea of what kind of core Java technical questions are asked on phone interviews. For curious ones, I have also included links for more detail answers and discussions.
Read more �

Monday, February 17, 2014

How to Create Tabs UI using HTML, CSS, jQuery, JSP and JavaScript

JSP is still a popular technology for developing view part of Struts and Spring based Java application, but unfortunately it doesn't have rich UI support available in GWT, or any other library. On other day, we had a requirement to display HTML tables inside tabs, basically we had two tables of different data set and we need to display them in their own tabs. User can navigate from one tab to other, and CSS should take care of which tab is currently selected, by highlighting active tab. Like many Java developers, our hands on HTML, CSS and JavaScript is little bit tight than a web guy, and since our application is not using any UI framework, we had to rely on JSP to do this job. Since display tag is my favourite, I had no problem to dealing with tabular data, our only concern was how we will develop tabbed UI by just using HTML, CSS, JavaScript or may be jQuery. It looks everything is possible with these technology, we eventually able to develop our JSP page, which can show data in tabs. So if you need to create tabs in JSP page, you can use this code sample, all you need to ensure is you have required libraries e.g. display tag library, JSTL core tag library and jQuery. I will explain you step by step how to create tabs in html or jsp page.
Read more �

Zhongornis probably isn't scansoriopterygid, contra O'Connor and Sullivan (2014)

Hi everyone.  Today we're looking at O'Connor and Sullivan's (2014) paper reinterpreting Zhongornis.  As the abstract says "The recently described maniraptoran theropod Zhongornis haoae, known from a single juvenile specimen, was originally identified as a bird. However, morphological re-evaluation reveals striking resemblances to both Oviraptorosauria and Scansoriopterygidae."  Well, does it?

No.

This is one of those papers that got worse and worse as I read more of it.  It seems to be written to reach a certain conclusion, but finds a different conclusion that is basically unacknowledged.  There are only a few actual reinterpretations of anatomy, namely the sacrum as having less vertebrae (5-6 instead of 6-7), the tail as having more vertebrae (~20 instead of 13-14), a less elongate coracoid and an ischium without a proximodorsal process (reinterpreted as the ilial peduncle).  Are these better than Gao et al.'s (2008) original interpretations?  It's impossible to tell, since the figures are terribly compressed jpegs that show artifacts even in the line drawings.  I've requested better versions from O'Connor but have yet to receive a reply.  Regardless, let's look at the evidence Zhongornis is closely related to scansoriopterygids and/or oviraptorosaurs.

The stated similarities to scansoriopterygids are as follows-

1. Short and deep skull.  Expected in any juvenile.
2. Short humerus (humerofemoral ratio 104% compared to scansoriopterygids' 98-112%).  Also expected in younger specimens, and a similar distance from adult Confuciusornis (114-127%) as the juvenile Liaoxiornis (108%) is from the adult Cathayornis (117%).
3. Weakly curved manual unguals with low flexor tubercles.  The curvature is actually similar to confuciusornithids and other basal birds.  O'Connor and Sullivan have a simplistic idea of basal birds and deinonychosaurs having more strongly curved manual unguals than oviraptorosaurs or scansoriopterygids, but there is a lot of variation in each. Also Scansoriopteryx and Epidexipteryx actually have large flexor tubercles.
4. Reduced number of caudal vertebrae (~20).  This is only true in Epidexipteryx (16) and admitted to be absent in Scansoriopteryx (~30-35).  This is also true in pygostylians of course (e.g. juvenile Dalingheornis with unfused caudals has ~20).
5. No distinct transition point or elongated distal caudals.  This is untrue in scansoriopterygids, where the distal vertebrae are elongate with reduced neural spines and transverse processes.  It can't really be evaluated in pygostylians with a pygostyle, though juveniles lacking a pygostyle like Dalingheornis are similar to Zhongornis and Epidexipteryx.
6. 'Incipient' pygostyle.  This phrase is used incessantly throughout this paper, but is never defined sufficiently.  The distal caudals in Zhongornis and Epidexipteryx are unfused (Scansoriopteryx's are unpreserved), so are not strictly pygostyles.  O'Connor and Sullivan cite Persons et al. (in  press) as attributing an incipient pygostyle to Caudipteryx, because "the last five vertebrae appear to be tightly integrated into an inflexible unit." But this is true of any coelurosaur, as the last caudals generally have flat articular surfaces and often elongate zygapophyses. Any pygostyle development is at least as true in pygostylians as it is in Epidexipteryx.
7. No obturator process.  Also true in Pygostylia, Jeholornithidae and Omnivoropterygidae.
8. Penultimate pedal phalanges longest.  This is not true in Scansoriopteryx, which has III-3 equal to III-1 and IV-4 equal to IV-1.  It is unpreserved in Epidexipteryx.  II-2 is longer than II-1 in most basal avialans as well, including confuciusornithids.
9. Manual phalanx I-1 longer than metacarpal II.  This is untrue in Zhongornis (94%) and scansoriopterygids (91% in Scansoriopteryx), and is similar to basal avialans (91% in Balaur; ~92% in Confuciusornis) and basal oviraptorosaurs (~93% in Similicaudipteryx; 89-93% in Caudipteryx).
10. Lack of proximodorsal ischial process.  This would be similar to scansoriopterygids, but the poor preservation proximally and great simiarity in shape to taxa with such processes (e.g. juvenile enantiornithine GMV-2158) make this equivocal at least.

Left ischia in lateral view of Zhongornis (top; after O'Connor and Sullivan, 2014), juvenile enantiornithine GMV-2158 (middle; after Chiappe et al., 2007), Scansoriopteryx holotype (bottom ; after Czerkas and Yuan, 2002).  Note the similarity between Zhongornis and GMV-2158, suggesting the process on the upper right is the proximodorsal process and not the iliac peduncle.
So we have no good scansoriopterygid characters in Zhongornis

How about oviraptorosaurian ones?

1. Low number of sacrals.  This could easily be ontogenetic, as juveniles often have less sacral vertebrae than adults.  The enantiornithine GMV-2158 has six sacrals for instance, when adult enantiornithines have seven or eight.  So if O'Connor and Sullivan are right that Zhongornis has 5-6, that would work if the adult had seven sacrals like confuciusornithids.
2. 'Incipient' pygostyle.  The argument used above works here- incipiency is a vague descriptor and any pygostyles are present in pygostylians as well.
3. Concave anterior narial margin formed by premaxilla.  This is true in the vast majority of theropods, pygostylians included.
4. Long frontals.  This is a confusing character to list here, since oviraptorosaurs usually have shorter frontals than most coelurosaurs due to their longer parietals.  Thus frontal length doesn't provide evidence Zhongornis is an oviraptorosaur.
5. Frontals narrow anteriorly and greatly expanded posteriorly.  Another confusing character, since oviraptorosaurs generally have less triangular frontals than most coelurosaurs.
6. Short and robust tail.  The tail is about equally short in juvenile pygostylians (e.g. length 1.59 times femoral length in Dalingheornis), Zhongornis (1.54) and basal oviraptorosaurs (~1.5 in Caudipteryx, 1.36 in Similicaudipteryx).  Oviraptorosaurs' tails are robust due to long chevrons (unpreserved in Zhongornis) and transverse processes (short in Zhongornis).  Thus there is no evidence Zhongornis has a tail that is robust for its length.
7. Robust furcula.  Basal oviraptorosaurs like Protarchaeopteryx, Similicaudipteryx and Caudipteryx actually have gracile furculae, and basal avialans like confuciusornithids have robust furculae.
8. Pointed epicleidia on furcula.  This is similar to some oviraptorids (Oviraptor, Citipati), though lacking in others (Khaan, Conchoraptor, "Ingenia", Jiangxisaurus, Heyuannia).  Unfortunately, other oviraptorosaurs do not preserve epicleidia in anterior/posterior view.
9. Metacarpal I 33% of metacarpal II length.  While shorter in many basal avialans, this is even stated by the authors to be present in Confuciusornis, and is even longer in Changchengornis and Balaur.  
10. Metacarpal I wider than metacarpal II.  Again, this is present in confuciusornithids and Balaur.
11. Manual phalanx I-1 subequal in length to metacarpal II.  As discussed in scansoriopterygid-like character 9 above, this is similar in Zhongornis, Confuciusornis and Balaur.
12. Weakly curved manual unguals.  As noted above, there is a lot of variation in oviraptorosaurs, with e.g. Protarchaeopteryx having more strongly curved unguals than Caudipteryx.  The curvature in Zhongornis isn't more similar to oviraptorosaurs' than pygostylians'.
13. Long nasals.  Another confusing character, since oviraptorosaurs have shorter nasals than most coelurosaurs.
13. ~20 caudal vertebrae.  This is not different from basal pygostylians as e.g. the juvenile Dalingheornis holotype has about 20 caudal vertebrae while lacking a pygostyle.
14. Reduced manual digit III of three phalanges. This may not be true (a short III-1 may be hidden), but the similarity to Caudipteryx's two phalanges noted by O'Connor and Sullivan is problematic for two reasons. First, as they state, Sapeornis has less than four phalanges on digit III (also true in Balaur). More importantly, the authors are not proposing a caudipterid identification for Zhongornis, and more basal oviraptorosaurs like Protarchaeopteryx and Similicaudipteryx have an unreduced digit III.

Only the narrowly pointed epicleidia are more similar to some oviraptorosaurs than to basal pygostylians.  O'Connor and Sullivan go on to compare scansoriopterygids with oviraptorosaurs, listing supposedly shared characters, and stating "We suggest that accumulating morphological information regarding both scansoriopterygids and basal oviraptorosaurs may eventually demonstrate that the former clade is either on the oviraptorosaurian stem or nested within basal Oviraptorosauria (Fig. 3), and convergently evolved �avian characteristics� as a result of adaptation to an arboreal lifestyle."

Analysis and unjustified conclusions

Of course just listing characters isn't that useful, and O'Connor and Sullivan proceed to add Zhongornis to the Xiaotingia version of Senter's TWG matrix.  They recover it as the most basal avialan, followed by Scansoriopterygidae, Jeholornis and Avebrevicauda.  Deinonychosaurs (including archaeopterygids) are sister to Avialae, with oviraptorosaurs and therizinosaurs more basal.  So hypotheses unsupported, right?  You'd think so, but the authors go on as if the opposite had occured.

Strict consensus tree of O'Connor and Sullivan (2014).  Note Aves should either be within Ornithuromorpha or at the Paraves node, depending on the definition used.  Is it suspicious the Paraves clades are flipped so that Zhongornis and scansoriopterygids are next to oviraptorosaurs?
 "Scansoriopterygidae is recovered as the sister taxon to Aves, with the two together forming the clade Avialae."

Since when is Jeholornis+Avebrevicauda Aves?  Aves is either crown birds, or Archaeopteryx plus crown birds, which would be Eumaniraptora here.

"Zhongornis is resolved as sister taxon to Avialae (Scansoriopterygidae + Aves) supporting our hypothesis that Zhongornis is closely related to scansoriopterygids."

First, the scansoriopterygid+jeholornithid+avebrevicaudan clade doesn't correspond to any proposed definition of Avialae.  Either Zhongornis is an avialan because it's closer to Aves than dromaeosaurids and/or troodontids (Gauthier, 1986), because it has wings for powered flight homologous to Aves (Gauthier and de Queiroz, 2001) (moreso than scansoriopterygids seem to at least) or because it's in the Archaeopteryx+Aves clade (Gauthier and Wagner, 2001).
Second, it's only closely related in the Petersian sense of being sister to a clade including scansoriopterygids and another branch.  You could just as validly say Zhongornis is closely related to Jeholornis+avebrevicaudans.

"A relationship between Zhongornis and Scansoriopterygidae is supported by six characters (101, 103, 166, 273, 317, and 325); however, scorings for most of these characters are ambiguous in Zhongornis because of missing data. The only one whose presence can be confirmed in Zhongornis, namely the fact that the minor digit is shorter than the major digit, is absent in Epidendrosaurus."

Er.... a relationship can't be supported by characters that are unknown in one of the two taxa.   Having a supporting character lacking in one taxon is even less sensical.  Obviously character 325 (manual digit III longer than II) can't support this clade if it is absent in Zhongornis.  I'm honestly not sure what this list is supposed to be.  I'd say it's a list of Avialae characters in ACCTRAN (where traits are optimized as evolving as early as possible, so that the basalmost avialan Zhongornis is modeled as having characters unknown for it but present in more derived birds), except 325 should just be a scansoriopterygid character and the actual list of avialan characters should include e.g. obturator process absent.  Alas, O'Connor and Zhou don't include their matrix, so we can't know for now.

We get numerous proclamations such as-
"This study reveals new morphological information that strongly suggests the holotype of Zhongornis is a juvenile scansoriopterygid or close scansoriopterygid relative."
"Based on new morphological data and comparisons with other avian and non-avian taxa, we suggest that the Early Cretaceous �bird� Zhongornis haoae may in fact be either a member or a close relative of the Scansoriopterygidae"
"Revised anatomical interpretation of the tail and more detailed comparisons with non-avian dinosaurs strongly suggest that Zhongornis haoae is not a bird but a member or close relative of the enigmatic maniraptoran clade Scansoriopterygidae."

The analysis didn't even suggest Zhongornis is a scansoriopterygid, let alone strongly suggest it.  Again the authors ignore the equally strong suggestion from their analysis that Zhongornis is a close relative of more derived avialans.

"The apparent scansoriopterygid affinities of Zhongornis would suggest the clade persisted from the Mid-Late Jurassic Daohugou times into Early Cretaceous Jehol times."

Whoah whoah... now the placement of Zhongornis in Scansoriopterygidae is apparent?  

"Zhongornis also bears some similarity to basal oviraptorosaurs, supporting the hypothesis that the Jurassic scansoriopterygids may be stem-group relatives of the Cretaceous Oviraptorosauria."

Apparently it didn't, since scansoriopterygids are avialans in their tree, while oviraptorosaurs are further removed than deinonychosaurs.  And I'm sure Mike Keesey is wondering what the crown-group oviraptorosaurs are. ;)
And tying both MIA hypotheses together...

"The relatively short forelimbs and short hallux in Zhongornis may suggest this taxon is a basal scansoriopterygid, close to the divergence of this clade from basal oviraptorosaurs, although this is inconsistent with its occurrence in the Yixian."

Well, IF Zhongornis were a scansoriopterygid and IF scansoriopterygids were oviraptorosaurs, that might be true.  Though Zhongornis actually has longer forelimbs (84% of hindlimb length, excluding phalanges) than scansoriopterygids (70-81%), and an equally long hallux (I-1 23% of metatarsal II).  So even this doubly hypothetical scenario then doesn't match with the evidence.

Sadly, this paper reminds me most of something from Feduccia or Martin.  O'Connor and Sullivan start with a relationship in mind and list characters to support it, but these are generally incorrect or equally correct for the opposing hypothesis.  They also often compare characters to different taxa in a group, so Zhongornis is like oviraptorids but not Caudipteryx in A and B, and like Caudipteryx but not oviraptorids in X and Y, so therefore is like oviraptorosaurs.  Phylogenetic terms are misapplied, and the result of any analysis is only important in the ways that it agrees with their ideas, not in the ways it disagrees.  One gets the impression the original draft never even included an analysis, as the discussion doesn't take it into account and the authors seem not to know how to evaluate their ideas with that dataset.  What they should have done is constrain scansoriopterygid and oviraptorosaurian Zhongornis to see how unparsimonious those hypotheses are, then constrain oviraptorosaurian scansoriopterygids including or excluding Zhongornis.  I've done that in the Lori analysis, and will say the results are much closer to their cladogram than their written ideas.

References- Czerkas and Yuan, 2002. An arboreal maniraptoran from Northeast China. Feathered Dinosaurs and the Origin of Flight. The Dinosaur Museum Journal. 1, 63-95.

Chiappe, Ji ans Ji, 2007. Juvenile birds from the Early Cretaceous of China: Implications for enantiornithine ontogeny. American Museum Novitates. 3594, 46 pp.

Gao, Chiappe, Meng, O'Conner, Wang, Cheng and Liu, 2008. A new basal lineage of Early Cretaceous birds from China and its implications on the evolution of the avian tail. Palaeontology. 51(4), 775-791.

O'Connor and Sullivan, 2014. Reinterpretation of the Early Cretaceous maniraptoran (Dinosauria: Theropoda) Zhongornis haoae as a scansoriopterygid-like non-avian, and morphological resemblances between scansoriopterygids and basal oviraptorosaurs. Vertebrata PalAsiatica. 52(1), 3-30. 

Persons, Currie and Norell, in press. Oviraptorosaur tail forms and functions. Acta Palaeontologica Polonica. doi: http://dx.doi.org/10.4202/app.2012.0093

Sunday, February 16, 2014

Exercices corrigés java : série 2 de 10 exercices

Exercices corrigés en java :

EXERCICE 1: (tirer un nombre au hasard dans un intervalle précis)

Ecrire un programme qui affiche au hasard un nombre entier compris entre 0 et 50. Puis le programme affiche au hasard un nombre compris entre 11 et 25. Puis le programma affiche un nombre au hasard entre - 10 et + 25.

Correction exercice 1 :

class Q1
{
public static void main( String args [])
throws Exception
{
double hasard= Math.random() * 51;
System.out.println ("Nombre entier entre 0 et 50 est : " + (int)hasard);
hasard=11+ Math.random() * 15;
System.out.println ("Nombre entier entre 11 et 25 est : " + (int)hasard);
hasard=-10+ Math.random() * 36;
System.out.println ("Nombre entier entre -10 et +25 est : " + (int)hasard );
}
}

EXERCICE 2 : (tirer 2 nombres au hasard )

Ecrire un programme qui affiche deux nombres entiers pris au hasard entre 0 et 50 avec la condition que l’un doit forcément être le double de l’autre.

Correction exercice 2 :

class Q2
{
public static void main( String args [])
throws Exception
{
double nbre1,nbre2;
int n1,n2; 
do
{
nbre1= Math.random() ;
nbre2= Math.random();
n1=(int)nbre1* 51;
n2=(int)nbre2 * 51;
System.out.println (n1 + " ? " + n2 );

}while(n1!=2*n2||(n1!=(n2)/2));
}
}

EXERCICE 3 : (Nombre secret)
Ecrire un programme qui tire au hasard un nombre entier compris entre 1 et 10. Ce nombre (secret) n’est pas affiché. Puis le programme demande à l’utilisateur d’entrer un nombre entier au hasard entre 1 et 10. Si le nombre de l’utilisateur est supérieur au nombre secret, le programme lui indique en lui demandant d’entrer un nouveau nombre. De même si le nombre est inférieur. Puis, lorsque l’utilisateur le trouve, le programme lui dit qu'il a gagné en lui indiquant le nombre de fois qu'il lui a fallu pour trouver le nombre.

Correction exercice 3 :

import java.util.Scanner;
class Q3
{
public static void main( String args [])
throws Exception
{
double sec=Math.random()*11;
int secret=(int)sec;
int nbreessai=0,essai; 
do
{
nbreessai++;
System.out.println ("Entrez un essai : ");
Scanner sc = new Scanner(System.in);
essai=sc.nextInt();
if (essai < secret)
{
System.out.println ("Désolé c'est plus grand");
}
if(essai > secret)
{
System.out.println ("Désolé c'est plus petit");
}
if(essai == secret)
{
System.out.println ("Bravo, vous avez gagné");
System.out.println ("Vous essayé " + nbreessai + " fois");
break;
}
}while(true);
}
}

EXERCICE 4: (résoudre une équation du second degré à une inconnue)

Ecrire un programme qui permet de résoudre une équation de 2nd degré à une inconnue: ax² + bx + c. L’utilisateur entre les trois paramètres de l’équation : a, b et c. Puis le programme affiche la solution.

Correction exercice 4 :

import java.util.Scanner;
class Q4
{
public static void main( String args [])
throws Exception
{
Scanner sc = new Scanner (System.in);
double a , b, c, d;
System.out.println ("Resolution des equations de 2eme degre ax² + bx +c =0");
System.out.println ("Entrez le 1er parametre");
a= sc.nextDouble();
System.out.println ("Entrez le 2er parametre");
b= sc.nextDouble();
System.out.println ("Entrez le 3er parametre");
c= sc.nextDouble();
d= b*b - 4 *a*c;

if (d<0)
{
System.out.println ("Aucune solution dans R");
}

if (d==0)
{
System.out.println ("l'unique solution est ");System.out.println (-b/(2*a));
}
if (d>0)
{
System.out.println ("Deux solutions x1= ");System.out.println ((-b-Math.sqrt(d))/(2*a));
System.out.println ("x2= ");System.out.println ((-b+Math.sqrt(d))/(2*a));
}
}
}


EXERCICE 5 : (Nombre de jours dans un mois)

Ecrire un programme qui demande à l’utilisateur de saisir le mois et l’année. Puis le programme affiche le nombre de jours de ce mois. Rappel : Janvier, Mars, Mai, Juillet, Août, Octobre et Décembre ont toujours 31 jours quelque soit l’année. Avril, Juin, Septembre et Novembre ont toujours 30 jours quelque soit l’année Le nombre de jours de février est égal à 28. Sauf les années bissextiles. Une année est bissextile lorsqu' elle est divisible par 4 et non par 100. Ou alors, elle est divisible par 400.

Correction exercice 5 :

import java.util.Scanner;
class Q5
{
public static void main( String args [])
throws Exception
{
Scanner sc = new Scanner (System.in);
System.out.println ("Entrez l'année :");
int annee=sc.nextInt();
System.out.println ("Entrez le mois :");
int mois=sc.nextInt();
switch (mois)
{
case 1 : case 3 : case 5 :case 7 : case 8 : case 10 : case 12 :
System.out.println("Le nombre de jour de ce mois est 31");
break;
case 4 : case 6 : case 9 :case 11 :
System.out.println("Le nombre de jour de ce mois est 30");
break;
case 2:
if (annee%4 !=0)
{
System.out.println("Le nombre de jour de ce mois est 28");
}
else
{
System.out.println("Le nombre de jour de ce mois est 29");
}
break;
default:
System.out.println ("Erreur de saisie");
break;
}
}
}


EXERCICE 6 : (Présence d’un caractère dans une chaine)

Ecrire un programme qui demande à l'utilisateur de saisir un caractère. Puis le programme affiche le nombre de fois où l’on trouve ce caractère dans une chaine préenregistrée.

Correction exercice 6 :

import java.io.*;
class Q6
{
public static void main (String [] args)
throws IOException
{
BufferedReader clavier = new BufferedReader(new InputStreamReader(System.in));
String chaine = "Je suis en vacances, oubliez moi un peu cameleon.";
int nombreDEfois = 0;
System.out.print("Entrez un caractere : ");
char c = clavier.readLine().charAt(0);
for(int i = 0; i < chaine.length(); i++)
{
if(chaine.charAt(i) == c)
nombreDEfois++;
}
System.out.println("On trouve " + c + ", " + nombreDEfois + " fois dans : " + "\" " +chaine + "\" ");
}
}


EXERCICE 7 : (Somme des n premiers nombres entiers)

Ecrire un programme qui demande à l’utilisateur de saisir un nombre entier n, positif et non nul. Puis le programme affiche la somme des n premiers nombres entiers positifs non nuls. Exemple : on saisit 4 et le programme affiche 1 + 2 + 3 + 4 = 10.

Correction exercice 7 :

import java.util.Scanner;
class Q7
{
public static void main( String args [])
throws Exception
{
Scanner sc = new Scanner (System.in);
int nbre, somme=0;
do
{
System.out.println("Entrez un nombre positif non null");
nbre=sc.nextInt();
}while(nbre<=0);

while (nbre!=0)
{
somme=somme+nbre;
nbre--;
}
System.out.println ("La somme est : " + somme);
}
}


EXERCICE 8 : (produit des n premiers nombres entiers)

Ecrire un programme qui demande à l’utilisateur de saisir un nombre entier n positif et non nul. Puis le programme affiche le produit des n premiers nombres entiers positifs non nuls. 

Exemple : on saisit 4 et le programme affiche 24. Car 1 * 2 * 3 * 4 = 24.

Correction exercice 8 :

import java.util.Scanner;
class Q8
{
public static void main( String args [])
throws Exception
{
Scanner sc = new Scanner (System.in);
int nbre, fact=1;
do
{
System.out.println("Entrez un nombre positif non null");
nbre=sc.nextInt();
}while(nbre<=0);

for(int i=1; i<=nbre;i++)
{
fact=fact*i;
}
System.out.println ("Le produit des " + nbre + " premiers nombres est : " + fact);
}
}


EXERCICE 9 : (factoriel d’un entier positif non nul)

Ecrire un programme qui demande à l’utilisateur de saisir un nombre entier positif non nul. Puis le programme affiche la valeur du factoriel de ce nombre.

Correction exercice 9 :

import java.util.Scanner;
class Q9
{
public static void main( String args [])
throws Exception
{
Scanner sc = new Scanner (System.in);
int nbre, fact=1;
do
{
System.out.println("Entrez un nombre positif non null");
nbre=sc.nextInt();
}while(nbre<=0);
Q19 q= new Q19();
System.out.println ("Le factoriel de " + nbre + " est : " + q.fact(nbre));
}

int fact(int nbre)
{
int fact=1;
for(int i=1;i<=nbre;i++)
{
fact=fact*i;
}
return fact;
}
}


EXERCICE 10 : (combinaison de p dans n )

Ecrire un programme qui demande à l’utilisateur de saisir deux entiers positifs non nuls
p et n. p étant bien sûr inférieur à n. Puis le programme affiche la combinaison de p dans n.

Rappel : combinaison de p dans n = factoriel de n divisé par (factoriel de p multiplié par factoriel de n moins p) = n!/p! * (n-p)!

Correction exercice 10 :

import java.util.Scanner;
class Q10
{
public static void main( String args [])
throws Exception
{
Scanner sc = new Scanner(System.in);
int p, n,combinaison, factn=1, factp=1,factpn=1;
do
{
System.out.println("Entrez n un nombre positif non null");
n=sc.nextInt();
}while(n<=0);

do
{
System.out.println("Entrez p un nombre positif non null et inférieur à n :");
p=sc.nextInt();
}while(p<=0 || p>n);

for(int i=1; i<=n;i++)
{
factn=factn*i;
}
for(int i=1; i<=p;i++)
{
factp=factp*i;
}
for(int i=1; i<=(n-p);i++)
{
factpn=factpn*i;
}
combinaison = factn/(factp*factpn);
System.out.println ("La combinaison de p dans n est : " + combinaison);
}
}