Trending ▼   ResFinder  

notes of computer application

3 pages, 6 questions, 0 questions with responses, 0 total responses,    0    0
Namratha Simha
Shantiniketan Trust School, Bangalore
+Fave Message
 Home > namratha_simha123 >

Formatting page ...

Notes for 10th notes : Java compilation : The java compilation takes place in 2 steps. First, the source code is compiled by the java compiler into byte code. The byte code is an intermediate code, which looks similar to the machine code, and it is the same on every platform, which helps in making java platformindependent. In the second step, this byte code is interpreted by the Java Virtual Machine (JVM), which is different for different platforms. Thus, the byte code together with JVM makes java platform independent. compiled interpreted Source code java byte code Machine language (a.java) (compiler) (a.class) (JVM) Call by Value and Call by Reference : In call by value, the calling function passes the values of variables to the called method, which makes copies of the actual parameters. It works on the formal parameters, so any change of the formal parameter values does not affect the actual parameters. The primitive data types are passed by value. In call by Reference, the calling function passes the reference of the values (i.e. object) to the called method. So the formal parameters also refer to the original variables. Thus any changes made in the called method is reflected back in the original values. Input/Output Streams : (the following is a general note, use whichever part is necessary according to the question.) A source of input data (data accepted into the computer) is called and input stream and a source of output data (data displayed on the output device) is called output stream. Inputting data is called reading data and outputting data is called writing data. System is a class of the java.lang package. System.in is an object of the abstract class Inputstream and System.out is an object of the abstract class PrintStream. Both these abstract classes are part of the java.io package. System.in object is automatically created and connected to the keyboard by the System class and is available for the user to use. So both the java.io and java.lang should be part of the program. Java.lang is automatically imported into a program, but java.io has to be imported by the programmer. The PrintStream class has several methods like print(), println(), write() to output data. Similarly the System.in.read() is a method of the InputStream class, used read a single character. The streams can be classified according their manner of input/output of data. They are: 1.ByteOriented : They input/output one byte (8 bits) of data at a time. 2.Character oriented : They input/output one character of data at a time. Since java uses Unicode character set, each character occupies 2 bytes. The input / output streams of ByteOriented are DataInput and DataOutput. The most commonly used character oriented IO streams used in java programs are : System.in, System.out and System.err Variable scope / Block scope : Variable scope is the program-region whithin which a variable is accessible. It is accesible within the block of code in which it is declared. It is also called block scope. The accebility of a variable can be controlled by using the different access specifiers private, protected, public and default. default is not a keyword, it refers to the absence of any access specifier. Getter (Accessor) and Setter (Mutator) methods : An accessor method is a member method of a class, which returns the value of a member variable of a class. This is mostly used for private member variables. The name of the method will be get+Name of the member variable, beginning with a capital letter. For ex.: for a member variable int cost, the accessor method will be public int getCost() { return cost; } They are declared public in order to access the private variables from another class and will have the data type of the variable as the return type. They are also called getter method according to the job they do. A mutator method is a member method of a class, that is used to set or assign a value to a member variable of a class, mostly private members. The name of the method will be set+Name of the member variable, beginning with a capital letter. For ex.: for a member variable int cost, the mutator method will be public void getCost(int newCost) { cost=newCost; } They are declared public in order to access the private variables from another classand will take a parameter of the same data type as the member variable, whose value is used to update the member variable. They are also called setter methods according to the job they do. String and StringBuffer : String and StringBuffer are both object types and are separate classes. Both of them store string type of data. But the difference between them is that String objects are immutable, i.e. the value cannot be changed and StringBuffer objects are mutable. Ex. String s="Beautiful"; The above statement instantiates an object having the data "Beautiful" and stores it's reference in object variable s. s="Yellow flower"; This statement instantiates a new object containing the data "Yellow flower" and assigns it's reference in s. So now s is pointing to Yellow flower. So in String, every time a change is made a new object is created. It is immutable. Now the object "Beautiful" is redundant and is eventually cleared from the memory. StringBuffer is immutable. Ex.StringBuffer sb=new StringBuffer( Beautiful ); The above statement instantiates an object having the data "Beautiful" and stores it's reference in object variable sb. sb= Yellow flower ; This statement only changes the value of sb from Beautiful to Yellow flower . It does not create a new object. Thus it is mutable.

Formatting page ...

Formatting page ...

 

  Print intermediate debugging step

Show debugging info


 

 

© 2010 - 2025 ResPaper. Terms of ServiceContact Us Advertise with us

 

namratha_simha123 chat