Scripting Languages I: Node. PHP, Python, Ruby (Sheet One)a side- by- side reference sheetsheet one: version ! In Python 3 / always performs float division.+ - * x. Math. floor(x / y)(int)(1. Infinity, Na. N, or - Infinity depending upon whether dividend is positive, zero, or negative. There are literals for Infinity and Na. N. returns FALSE with warningraises Zero. Division. Errorraises Zero. Division. Errorfloat division 1. Python 3: 1. 3 / 5. Save the file with the menu sequence File . Python program files should always be given a name ending in ”.py”, and you must enter the.py extension explicitly. Mac Save updates a file using its current name. Java uses Just-In-Time compiler to enable high performance. Just-In-Time compiler is a program that turns Java bytecode, which is a program that contains instructions that must be interpreted into instructions that can be sent directly to the processor.
I'm trying to research how to ensure the finally block is executed in my method that may throw an exception. Although the writers third quote have an unfortunate way of expressing themselves, they are right. Global variable How to declare and access a variable with global scope. A function must use the global keyword to. If invoked with new and return value not an object, returns thisreturn arg or NULLreturn arg or Nonereturn arg or last expression evaluatedmultiple return values nonefunctionfirst. Portions of the source file outside of such tags is not treated as executable code and is echoed to standard out. If short tags are enabled, then php code can also be placed inside < ? The block ends with the first line that is not indented further than the initial line. Python raises an Indentation. Error if the statements in the block that are not in a nested block are not all indented the same. Using tabs in Python source code is unrecommended and many editors replace them automatically with spaces. If the Python interpreter encounters a tab, it is treated as 8 spaces. The python repl switches from a > > > prompt to a . A blank line terminates the block. Colons are also used to separate keys from values in dictionary literals and in sequence slice notation. Curly brackets . A matched curly bracket pair can be replaced by the do and end keywords. By convention curly brackets are used for one line blocks. The end keyword also terminates blocks started by def, class, or module. Curly brackets are also used for hash literals, and the #. The following causes a parse error: < ? The following code is legal: < ?= $a = 1 ?>. Putting a newline in these strings results in a syntax error. There is however a multi- line string literal which starts and ends with three single quotes ''' or three double quotes: . Putting a newline before the comma or associator results in a syntax error. A newline that would normally terminate a statement can be escaped with a backslash. How to identify the character encoding for a source code file. Setting the source code encoding makes it possible to safely use non- ASCII characters in string literals and regular expression literals. How to create a comment that ends at the next newline. How to comment out multiple lines. The triple single quote ''' and triple double quote . If a variable with no previous reference is accessed, its value is NULL. A variable is created by assignment if one does not already exist. If the variable is inside a function or method, then its scope is the body of the function or method. Otherwise it is a global. Variables are created by assignment. If the variable does not have a dollar sign ($) or ampersand (@) as its first character then its scope is scope defining region which most immediately contains it. A lower case name can refer to a local variable or method. If both are defined, the local variable takes precedence. To invoke the method make the receiver explicit: e. However, outside of class and modules local variables hide functions because functions are private methods in the class Object. Assignment to name will create a local variable if one with that name does not exist, even if there is a method name. A list of regions which define a lexical scope for the local variables they contain. Local variables defined inside the region are only in scope while code within the region is executing. If the language does not have closures, then code outside the region has no access to local variables defined inside the region. If the language does have closures, then code inside the region can make local variables accessible to code outside the region by returning a reference. A region which is top level hides local variables in the scope which contains it from the code it contains. A region can also be top level if the syntax requirements of the language prohibit it from being placed inside another scope defining region. A region is nestable if it can be placed inside another scope defining region, and if code in the inner region can access local variables in the outer region. Only function bodies and method bodies define scope. Function definitions can be nested, but when this is done lexical variables in the outer function are not visible to code in the body of the inner function. Braces can be used to set off blocks of codes in a manner similar to the anonymous blocks of Perl. However, these braces do not define a scope. Local variables created inside the braces will be visible to subsequent code outside of the braces. Local variables cannot be created in class bodies. Only functions and methods define scope. Function definitions can be nested. When this is done, inner scopes have read access to variables defined in outer scopes. Attempting to write (i. Python trivia question: what would happen if the following code were executed? The keywords if, unless, case, while, and until each define a block which is terminated by an end keyword, but none of these blocks have their own scope. Anonymous functions can be created with the lambda keyword. Ruby anonymous blocks can be provided after a function invocation and are bounded by curly brackets . Both anonymous functions and anonymous blocks can have parameters which are specified at the start of the block within pipes. Here are some examples: id = lambda . Such variables are listed inside the parameter pipes, separated from the parameters by a semicolon: x = 3. A function must use the global keyword to access the global variable. A variable is global if it is defined at the top level of a file (i. Although the variable is global, it must be imported individually or be prefixed with the module name prefix to be accessed from another file. To be accessed from inside a function or method it must be declared with the global keyword. A variable is global if it starts with a dollar sign: $. How to declare a constant. A constant can be declared inside a class: class Math . By convention, constants are all caps and class/module names are camel case. The ruby interpreter does not prevent modification of constants, it only gives a warning. Capitalized variables are globally visible, but a full or relative namespace name must be used to reach them: e. Math: :PI. How to assign a value to a variable. If the variable on the left has not previously been defined in the current scope, then it is created. This may hide a variable in a containing scope. Assignment does not return a value and cannot be used in an expression. Thus, assignment cannot be used in a conditional test, removing the possibility of using assignment (=) when an equality test (==) was intended. Assignments can nevertheless be chained to assign a value to multiple variables: ruby: Assignment operators have right precedence and evaluate to the right argument, so they can be chained. If the variable on the left does not exist, then it is created. How to assign values to variables in parallel. The r- value can be a list or tuple: nums = . This assignment will set a to 1, b to 2, and c to 3: This assignment will raise a Type. Error: In Python 3 the splat operator * can be used to collect the remaining right side elements in a list: x, y, *z = 1, 2 # assigns . They return values and thus can be used in expressions. The prefix versions return the value in the variable after mutation, and the postfix version return the value before mutation. Incrementing a value two or more times in an expression makes the order of evaluation significant: x = 1. However, here is a Ruby expression which is dependent on order of evaluation: x = 1. The increment and decrement operators also work on strings. There are postfix versions of these operators which evaluate to the value before mutation: ruby: The Integer class defines succ, pred, and next, which is a synonym for succ. The String class defines succ, succ!, next, and next! In particular, the following comparisons are true: $v = NULL. NULL) . A ternary operator is an operator which takes three arguments. Similarly for FALSE. In general, PHP variable names are case- sensitive, but function names are case- insensitive. When converted to a string for display purposes, TRUE renders as . The equality tests TRUE == 1 and FALSE == . The operators === and !== do not perform this conversion, so 0 === . The following expressions evaluate to true: In general if Ai are expressions and opi are relational operators, then A1 op. A2 op. 2 A3 . Trigonometric functions are in radians unless otherwise noted. Logarithms are natural unless otherwise noted. Python also has math. To compute the log of x for base b, use: ruby: Ruby also has Math. Math. log. 10. To compute the log of x for base b, use. Constants for . The Ruby MRI interpreter uses the current time and process ID, for example. As a result there is usually no need to set the seed. Setting the seed to a hardcoded value yields a random but repeatable sequence of numbers. This can be used to ensure that unit tests which cover code using random numbers doesn't intermittently fail. The seed is global state. If multiple functions are generating random numbers then saving and restoring the seed may be necessary to produce a repeatable sequence. The bit operators for left shift, right shift, and, inclusive or, exclusive or, and negation. Binary, octal, and hex integer literals. How to convert integers to strings of digits of a given base. How to convert such strings into integers. Python has the functions bin, oct, and hex which take an integer and return a string encoding the integer in base 2, 8, and 1. The type or types using for strings. PHP assumes all strings have single byte characters. In Python 2. 7 the str type assumes single byte characters. A separate unicode type is available for working with Unicode strings. In Python 3 the str type supports multibtye characters and the unicode type has been removed. List out Java Keywords. Write about one of the SELECTION statements of Java. Write the usage of break and continue statements. List out Thread properties. List out some of the source of errors in. Explain data type conversion and. Ex: c: \programfiles\java\jdk. All language compilers translate. Java compilers also does. Java compiler produces an intermediate code known as byte code. JVM takes this byte code and exists only inside the computer. The machine code is generated by the java interpreter, which is acting. Explain for loop with an example. Ans: in looping statements or. Now the control variable is incremented using. Explain data type conversion and casting feature of java with an. It is possible to assign a value of. Java does the. conversion of the assigned value automatically this is known as automatic type. It is possible only if the destination type has enough space to. The process of assigning smaller. To store a value of one type into a. To store a value of one type into a. Syntax: datatype. Casting is necessary when a method returns. Four integer type(byte, short, int, long). Boolean. Casting into smaller type may. Boolean. Casting a floating point value to an integer value, gives. A commandline. argument is the information that directly follows the program name on the. String array passed to main() Public static void main(String args. It may or may not consists abstract. However, if it does not, the subclass. The birth is thread object’s creation and death is thread object’s. During the lifetime of a thread, there are many states it can enter. They include: 1. Born. Runnable state 3. Running state 4. Blocked state 5. Dead state. a thread is always in. It can move from one state to another state via a. It is also known as Visibility modifiers. Java provides 4 types of access. Private, protected, public, default. This is possible by simply declaring the variable or methods as. The variable on method declared as. The protected modifiers makes the fields. Non sub classes in other packages can not access. Private fields are the highest degree of protection they are accessible. A catch block defined by the keyword catch catches the exception. If any one statement generates an. The remaining statements in the block are skipped and execution. The input stream classes define methods for performing input. They are two kinds: 2. Only. difference in that those are used to write characters./* For stream classes hierarchy. For each of stream classes 2 marks: -. DIPLOMA EXAMINATION, (C- 0. DCME VI. SEMESTER EXAMINATIONTime : 3. Hours. List the different awt components in Java. Instructions: (1) Answer any five. How. does this pointer can be used in java program? Explain about how to create. Explain about the order of. Write a java program to. Explain about the creation. Explain about the usage of. This section shows you what literals. Consider the following code: types. Literals(values)1. Floating Point Literals. For example, a variable should be declared to use. To declare a variable in. Java, all that is needed is the data type followed by the variable name: int a; Declaring variables for other. Time; double Price; Initializing Variables. Before a variable can be used it must be given an initial value. If we try to use a variable without. It. is a keyword, which doesn’t contain a body and contains only a method. By default it contains abstract method. By using. interface we can achieve multiple inheritance in java. An interface is. written when all the features are implemented differently in different. It is the duty. of third party people to design implementation to interface methods in the. Ans: The CLASSPATH is an environment. CLASSPATH is. generally set to a directory (or) JAR files. The CLASSPATH option is preferred. Unwanted event that disturbs normal flow. Exception(1) separating error handling code. How does this. pointer can be used in java? Explain the concept of importing packages in java. Ehandler. javaimport Handling.*; import java. Myframe. 2 extends Frame. Explain about how to create a thread with example. We can create the Threads in two ways. Steps for creating Threads in java. Explain about the order of. Write a java program to illustrate the use of. String args. Explain about the creation. Explain about the usage of text field and text area in. A scrollable. text display object with one. Text. Field. Text is created by using a Text. Field. class. The Text field class implements a. Control. Text. Field. By using keys, cut and paste keys. Text field is a sub class of text. When the user indicates that text entry is complete (usually by. Enter), the text field fires an action event. If you need to obtain. To set. the text, call set text ( ). List the various types of inheritance. Write. various types of constructors. Write any siz. common(defined)java exceptions. List. the various types of inheritance. Ans: acquiring the resource from super class to. The different types of inheritance are. Multi- Level inheritance. Hierarchial inheritance. Abstract class. cannot be instantiated, you cannot create an object of an Abstract class. Another class can inherit an. If a class includes abstract methods, the class itself must be. When an abstract class is subclassed, the subclass usually. Unwanted event that disturbs normal flow of the program is. Exception(1). Separating error handling code from regular code(2). Grouping error types and error differentiation(3). Allows the fixing the errors(4). It prevents the abnormal termination. Applet. is a small java program for internet applications(web pages)A Java applet is an Applet. Java byte code. Java applets can run in a Web. Java Virtual Machine (JVM), or in Sun's Applet. Viewer, a. stand- alone tool for testing applets. Explain the features of java. Write. various types of constructors. Write any siz common(defined)java exceptions. An Exception is a condition that is. To. avoid the corrupted data we should create an exception object and throw it. Array. Index. Out. Of. Bounds. Exception. Array. Store. Exception. Explain the following: (a) try and. BOARD. DIPLOMA EXAMINATION, (C- 0. DCME. VI SEMESTER EXAMINATIONTime. Hours. Define method overloading. Write a program. using the concept of method overloading. Write the programs. Explain the following: (a) Try and catch. Throw (c) Finally. If a field is declared private, it cannot be accessed by anyone. For this reason. encapsulation is also referred to as data hiding. The main benefit of encapsulation is the. With this feature Encapsulation gives maintainability. The most common use of polymorphism in OOP. Lifetime of a variable defines the time for which the variable exist in. A block is begun with an opening curly brace and ended by a closing. A block defines a scope. Thus, each time you start a new block. A scope determines what objects are visible to. It also determines the lifetime of those objects. However, if. that method has parameters, they too are included within the method’s scope.- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4. Your class can implement more than one interface, so the implements keyword is followed. By. convention, the implements clause follows the extends clause, if there is. Java applets can. Web browser using a Java Virtual Machine (JVM), or in Sun's. Applet. Viewer, a stand- alone tool for testing applets.- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1. A short is 2 times smaller than an int. Default value is 0. Example : short s= 1. Int data type is a 3. Minimum value is - 2,1. Maximum value is 2,1. Int is generally used as the default data type for integral values unless there is a concern about memory. The default value is 0. Example : int a = 1. Long data type is a 6. Minimum value is - 9,2. Maximum value is 9,2. The statements break and continue in. Java alter the normal control flow of. The break and continue statements do not make sense. Without labels (see below), break and continue refer to the most. With labels the break. The continue statement immediately jumps to the. A continue statement does not. Java does not have a general goto. But the statements break and continue take the place of most of uses. Java does allow any statement to be labeled as in (b) Explain the separators used in Java Separators help define the structure of a. The separators used in Hello. World are parentheses, ( ), braces. The table lists the six Java separators. Encloses arguments in method. Selects a field or method from an. Example: public class A . Write a program using. In Java it is. possible to define two or more methods within the same class that share the. When this is. the case, the methods are said to be overloaded, and the process is. Method overloading is one of the ways. Java implements polymorphism. Overload. Demo . Write the programs for creating. A package is the Java. Addition. java. Public int add(int. Note : -d: \> javac –d. Import caliculator. Addition; Public class static void main(String args. Thread gets the ready- to- run state. The thread scheduler provides the CPU. In Java runtime system, preemptive scheduling algorithm is. If at the execution time a thread with a higher priority and all other. On the other hand, if two threads of the same priority. CPU then the round- robin. Here are the. lifecycle methods of an Applet: init(): This method is called to initialized an appletstart(): This method is called after the initialization of the applet. This method can be called. Applet. destroy(): This method is called. The init() method is called only one time in the life cycle on an. The init() method is basically called to read the PARAM tag in the html. The init () method retrieve the passed parameter through the PARAM tag of. Parameter() method All the initialization such as. After the initialization of the init() method user can. Applet and mostly. Start () method: The start method of an applet is called after the.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2016
Categories |