పాస్కల్ తో పోలిక - 1

"హాయ్. నా పేరు లగా బిలాబో. నేను గ్రహాంతరవాసిని మరియు ఈ ఓడ వైద్యుడు. మనం మంచి స్నేహితులుగా ఉంటామని ఆశిస్తున్నాను."

"నేను కూడా."

"నా హోమ్ ప్లానెట్‌లో, మేము వెనుకబడిన జావా భాషకు బదులుగా అధునాతన పాస్కల్ ప్రోగ్రామింగ్ భాషను ఉపయోగిస్తాము. జావా మరియు పాస్కల్ కోడ్ యొక్క ఈ ప్రక్క ప్రక్క పోలికను చూడండి:"

జావా పాస్కల్
public class MyFirstClass
{
   public static void main(String[] args)
   {
      int a, b, c;
      String s1, s2;
      System.out.println("Enter two numbers");
      a = new Scanner(System.in).nextInt();
      b = new Scanner(System.in).nextInt();
      c = a + b;
      System.out.println("The sum is " + c);
   }
}
Program MyFirstProgram;
Var
   a, b, c: Integer;
   s1, s2: String;
Begin
   WriteLn("Enter two numbers");
   ReadLn(a);
   ReadLn(b);
   c := a + b;
   WriteLn("The sum is ", c);
End.

"ఇది రెండు వేర్వేరు భాషలలో వ్రాయబడిన ఒకే ప్రోగ్రామ్. మీరు చూడగలిగినట్లుగా, ఇది పాస్కల్‌లో తక్కువ లైన్‌లను కలిగి ఉంది, ఇది పాస్కల్ జావా కంటే ఉన్నతమైనదని రుజువు చేస్తుంది."

"మీరు ఇంతకు ముందు ఎప్పుడైనా పాస్కల్‌ని చూసినట్లయితే జావాను బాగా అర్థం చేసుకోవడంలో ఈ ఉదాహరణ మీకు సహాయపడుతుందని నేను అనుకున్నాను."

"లేదు, నేను చేయలేదు. ఇప్పటికీ, రెండు ప్రోగ్రామింగ్ భాషలను పోల్చడం ఆసక్తికరంగా ఉంది."

"తగినంత. నేను కొనసాగిస్తాను."

"పాస్కల్‌లో, మేము ప్రోగ్రామ్ బాడీ, ప్రొసీజర్‌లు లేదా ఫంక్షన్‌లలో కోడ్‌ను ఉంచుతాము. జావాలో, ఈ ప్రక్రియ సరళీకృతం చేయబడింది: ప్రోగ్రామ్ బాడీ, ప్రొసీజర్‌లు మరియు ఫంక్షన్‌లు అన్నీ మెథడ్స్ అని పిలువబడే ఫంక్షన్‌ల ద్వారా భర్తీ చేయబడతాయి."

జావా పాస్కల్
ప్రధాన పద్ధతి
public static void main(String[] args)
{
   System.out.println("Ho-ho-ho!");
}
ప్రోగ్రామ్ బాడీ
Begin
   WriteLn("Ho-ho-ho!");
End.
ఫంక్షన్/పద్ధతి
double sqr(double a)
{
   return a * a;
}
ఫంక్షన్
Function Sqr(a: Real): Real
Begin
   Sqr := a * a;
End;
శూన్యమైన రిటర్న్ రకంతో ఫంక్షన్
void doubleWrite(String s)
{
   System.out.println(s);
   System.out.println(s);
}
విధానము
Procedure DoubleWrite(s: String);
Begin
   WriteLn(s);
   WriteLn(s);
End;

"పాస్కల్ కాలమ్‌లో, నేను 'ప్రోగ్రామ్ బాడీ', 'ఫంక్షన్' మరియు 'ప్రొసీజర్' అనే పదాలను చూస్తున్నాను, కానీ జావాలో అవన్నీ పద్ధతులు అంటారు. అది కొంచెం విచిత్రంగా ఉంది."

"అవును, మేము గ్రహాంతరవాసులని చాలా విచిత్రంగా భావిస్తున్నాము. కానీ మానవులు ప్రతిదీ ఏకీకృతం చేయడానికి ఇష్టపడతారు."

"జావాలో, అన్ని కోడ్‌లు ఒక పద్ధతిలో భాగం, కాబట్టి మీరు ఒక పద్ధతిని ప్రకటించడానికి పాస్కల్‌లో వలె ఫంక్షన్ అనే పదాన్ని కూడా వ్రాయవలసిన అవసరం లేదు . "

"ఇదంతా చాలా సులభం. కోడ్ యొక్క లైన్ టైప్ + నేమ్ లాగా కనిపిస్తే , అది ఒక పద్ధతి లేదా వేరియబుల్ యొక్క డిక్లరేషన్. పేరును కుండలీకరణాలు అనుసరించినట్లయితే, అది కొత్త పద్ధతిగా డిక్లరేషన్ అవుతుంది. కుండలీకరణాలు లేకుంటే, అప్పుడు అది వేరియబుల్ యొక్క డిక్లరేషన్. "

"జావాలో వేరియబుల్స్ మరియు మెథడ్స్ డిక్లరేషన్‌లు చాలా పోలి ఉంటాయి. మీ కోసం చూడండి:"

కోడ్ వివరణ
String name;
వేరియబుల్ అని పిలవబడేది namea String.
String getName()
{
}
getNameరిటర్న్స్ a అనే పద్ధతి String.

"కానీ అంతే కాదు. జావాలో, పద్ధతులు ఒంటరిగా ఉండవు. అవి తరగతి లోపల ఉండాలి. కాబట్టి, మానవులు జావాలో ఒక చిన్న ప్రోగ్రామ్‌ను వ్రాయవలసి వచ్చినప్పుడు, వారు ముందుగా ఒక తరగతిని సృష్టించాలి, దానిలో ఒక ప్రధాన పద్ధతిని ప్రకటించాలి మరియు అప్పుడు మాత్రమే వారు తమ కోడ్‌ని పద్ధతిలో వ్రాయగలరు . ఈ భూలోకవాసులు చాలా విచిత్రంగా ఉన్నారు!"

"డియెగో ఈరోజు ముందుగానే పడిపోయాడు మరియు ఈ పనులను మీకు ఇవ్వమని నన్ను అడిగాడు. మీరు వాటిని ఇష్టపడతారని నేను ఆశిస్తున్నాను."

1
టాస్క్
Java Syntax,  స్థాయిపాఠం
లాక్ చేయబడింది
The great purge
Whoever wrote this program obviously did it in a hurry. Actually, that's not true: this program was written for educational purposes, and the author deliberately crammed in superfluous variables and simultaneously failed to declare necessary variables. We're going to correct this: Comment out the unnecessary variables, and declare the missing variables. Then the program will achieve universal harmony.
1
టాస్క్
Java Syntax,  స్థాయిపాఠం
లాక్ చేయబడింది
Don't feel like it? Do it anyway.
Laziness afflicts even the best programmers. And not only programmers. Nevertheless, people have managed to become professionals by teaching themselves. So, we suggest not being lazy. Instead, display this slogan on the screen: "If you feel like it, do the task. If you don't feel like it, do it anyway". And to really remember this, display it 16 times.
5
టాస్క్
Java Syntax,  స్థాయిపాఠం
లాక్ చేయబడింది
Square of a number
There are several ways to square a number. For example, some people write a number and then draw a square around it. This method is used by people who haven't studied anywhere. Everybody else has to multiply, remember the table of squares, ... or use a program. Your program should display the square of 5.
5
టాస్క్
Java Syntax,  స్థాయిపాఠం
లాక్ చేయబడింది
As simple as 2+2
In a Java application, all the actions are performed by functions. Or more accurately, methods. In our program, a kind mentor has already implemented a method (that is, written the method's code) that can calculate the sum of two numbers. All you need to do is call this method with the arguments 2 and 2. You need to do this in the main method.
1
టాస్క్
Java Syntax,  స్థాయిపాఠం
లాక్ చేయబడింది
Choose healthy food! Choose fruit!
Display the variables whose values are names of fruit. Display each variable on a new line.