CCS0023 OBJECT ORIENTED PROGRAMMING Past Paper PDF

Summary

This document is a past exam paper for a module on Object-Oriented Programming (OOP) using Java. It contains questions and answers. The paper covers foundational concepts in Java, including the Java Virtual Machine, and the structure of Java programs.

Full Transcript

CCS0023 – MODULE 1 SUBTOPIC 1 OBJECT ORIENTED PROGRAMMING Oak What was Java originally called? James Gosling; Who developed Java and at what company did they work in which is now a subsidiary of Sun Microsystems oracle corporation? 1995 Java...

CCS0023 – MODULE 1 SUBTOPIC 1 OBJECT ORIENTED PROGRAMMING Oak What was Java originally called? James Gosling; Who developed Java and at what company did they work in which is now a subsidiary of Sun Microsystems oracle corporation? 1995 Java was released in ______ as a core component of Sun Microsystems' Java platform. It has derived much of its syntax from C and C++ but has a simpler object model and fewer Java low-level facilities. _______ is a general-purpose, concurrent, class-based, object oriented language that is Java specifically designed to have as few implementation dependencies as possible The Java source code files (files with.java extension) are compiled into a format called Java interpreter bytecode (files with.class extension), which can be executed by a ___________..java What is the file extension of Java programs? bytecode (.class) What do you call the compiled format of java? What is its extension? Java was intended for use in ____’s project research to work on a programming software to Sun’s control electronic devices World Wide Web Java was modified to take advantage of the ______________. WebRunner The _______, later named as _______, was the very first web browser created in Java. HotJava Netscape Navigator In 1995, the ________ internet browser was also developed to support Java The 5 Features of Java Include: 1. Simple, object-oriented, and familiar NONE 2. Robust and secure 3. Architecture neutral and portable 4. High performance 5. Interpreted, threaded, and dynamic Java programming language include a simple language that can be programmed without Simple, object- extensive programmer training while being attuned to current software practices. The oriented, and familiar fundamental concepts of Java technology are grasped quickly; programmers can be productive from the very beginning. A feature of java that provides extensive compile-time checking, followed by a second level Robust and Secure of run-time checking. Architecture neutral A feature of java that means Java technology is designed to support applications that will be and portable deployed into heterogeneous network environments The Java platform achieves superior performance by adopting a scheme by which the interpreter can run at full speed without needing to check the run-time environment. In High performance general, users perceive that interactive applications respond quickly even though they're interpreted. The Java interpreter can execute Java bytecodes directly on any machine to which the Interpreted, threaded, interpreter and run-time system have been ported. In an interpreted platform such as Java and dynamic technology-based system, the link phase of a program is simple, incremental, and lightweight. Java 2 Standard Java Edition J2SE stands for? Edition Java 2 Enterprise Java Edition J2EE stands for? Edition Java 2 Micro Edition Java Edition J2ME stands for? Java; ______ is a portable language that could run on any platform. It was able to do this by virtual machine generating intermediate code for a hypothetical computer called a ________. The __________ is a program that runs on all computers. The ____ creates a software Java Virtual Machine simulation of a CPU and memory and handles all communication between the Java program (JVM) and the underlying operating system and hardware. The Java source code (.java file) is normally compiled to produce the bytecode file (.class file) Java Virtual Machine which is normally interpreted by the ____________. Source Code to “javac” to Byte Code to byte code to Java Virtual Machine to machine code Java “Write once, run anywhere.” Java 2 Software Development Kit Java, Javac, Javadoc, others The J2SDK (JDK) or ________ contains four things which are? Java the loader for Java applications is called? Javac the compiler is called? javadoc the documentation generator is called? Steps in Creating a Java Application: Create Compile 1. _______ the source code. Run 2. _______ the source code. 3. _______ the program. Steps 1: Creating the source code Text Editor Create the source code using any _________..java Save the file with a “._____” extension. (Example: HelloJava.java) Steps 2: Compiling the source code javac Compile the source code to create the byte code using ______ tool from the J2SDK. Open an _______ console, browse for the directory where you saved the source code MS-DOS Type the command _______ HelloJava.java and press ENTER. Verify that the HelloJava.class has been created. Steps 3 : Running the Program java To execute the program, type the command: ____ HelloJava and press ENTER. Integrated An ___________ is a computer software to help computer programmers develop software Development code efficiently. Environment (IDE) ____ Leaders Include NetBeans, Microsoft Visual Studio, and Eclipse. Integrated Development What does IDE stand for? Environment 1. Source code Editor. 2. Compiler and/or interpreter. What does IDE consist of? Give 3. 3. Build- automation tools. 1. Debugger. 2. Version control What are the 3 optional tools of IDE? system. 3. Various tools to simplify the construction of a GUI 1. Object inspector. 2. Class Browser. What are the 3 tools for object oriented design? 3. Class hierarchy diagram. _________ abstracts the configuration necessary to piece together various utilities in one IDE unit, which could ease the learning of a language, and increases developer productivity. Most IDEs today have _____ modeling utilities that simplify the development of UIs, which is GUI critical for commercial software today. Xelfi It all started as a student project called _________. Delphi The Goal was to write a _______- like Java IDE in Java for the first time. network-enabled The original plan was to develop ___________ components, hens the name. but coming out JavaBeans of the spec for enterprise changed the plans. Sun ______ decided it needs a more powerful Java development tool, and the rest is history. NetBeans It is a fast fully-featured Integrated Development Environment (IDE) with support for Java. NetBeans It is a compliant applications for accelerating development across all major OS platforms. It provides an open source, high performance, modular, extensible, multi-platform Java IDE NetBeans for GUI, mobile tools, Web, and Desktop applications. NetBeans It is written in java and therefore runs on every operating system that supports Java VM. The __________ represents a free and open-source development environment, tooling Apache NetBeans IDE platform, and application framework. It comes with a user-friendly interface with powerful features such as source-code Apache NetBeans IDE highlighting, code templates, and project creation wizards, which can simplify your code design. NetBeans Features: Environment: easily configured user interface and a modular architecture extensible with additional plugins. Project System: support for multiple source roots, easy management of libraries, easily ported to other environments, all based on Apache Ant. Web Development: Web Application project type, Supports the J2EE 1.3 and 1.4 standards with web application build support based on Apache Ant. Enterprise Java Beans (EJB) Development: easy to create and deploy and import java beans. Web Services Development: wizards for creating web services and web services clients, providing the basic (java/wsdl) code needed, and easy to use testing tools of existing web services. NONE Java 2 Platform, Micro Edition (J2ME) MIDP development: visual design editor with end-to- end support for enterprise applications. Code Editor: Syntax highlighting for Java, XML, HTML, CSS, JSP and IDL, full support of new JDK 1.5 features, live parsing/error marking, popup javadoc, code completion, and fast class importing. Refactoring: renaming, changing and moving of various objects, field encapsulation and usage finding. Award Winning Debugger: Language independent debugger core, variable modification and watches, various breakpoints and “Fix and Continue” mechanism. GUI Builder: fully WYSIWYG designer with "Test Form" feature, extensible Component Palette pre-installed Swing and AWT components, showing a components tree and properties, automatic code generation and full JavaBeans support. Version control Support: supports command lined vcs, supplying merging and diff tools and containing a built- in CVS client. XML: XML, DTD and CSS Text Editor and XML Productivity Tools Wizards to help user generate codes. NetBeans _______: provides information about the runtime behavior of applications. Allows Profiler developers to monitor the thread state, CPU performance, and memory usage of their applications. makes it easy to track down performance problems and memory leaks NetBeans ______: provides the services common to almost all large desktop applications Platform such as: window, menu, settings management and storage, file access and more. NetBeans _________: used to write, test, and debug applications for the Java Micro Edition platform (J2ME) technology-enabled mobile devices. It integrates support for the Mobile Mobility Pack Information Device Profile (MIDP) 2.0, the Connected, Limited Device Configuration (CLDC) 1.1. On-Phone The mobility pack allows for the unique “_________” debugging mode. NetBeans Matisse: The biggest improvement from the previous version and the feature with the biggest impact is the new GUI- Builder, Matisse. The Goal: to take the best features from OSX and VS designers and allow the same possibilities for Java Programmers. In order to reach that goal there was a need to develop a new layout manager to support NONE all the needed functionalities. Matisse provides a simple and intuitive layout of GUIs without having to understand the complexities of Swing layout managers. As you drag and drop components into a form, the IDE automatically suggests alignment, spacing, and resizing constraints. By simply right clicking a UI Object you can add an event handler with a method waiting to be implemented without knowing too much about the surrounding of this object. (watch example clip in the site) NetBeans Matisse – Advantages: For the first time, there’s an intelligent way to build GUI for Java (unlike eclipse), that can NONE actually compete with the Visual Studio Gui builder. Supports internationalization, and industrial look-and-feel rules, which is very important for large scale application meant to be spread world wide. Builds also GUI web applications, HTML, JSP, etc NetBeans Matisse – Disadvantages: NONE No built-in support for Drag-n-Drop or double-click events. Matisse’s code is protected so customizing is not very easy and not always possible. Not all applications are easily built. For instance, an MDI Project is not that trivial to build CCS0023 – MODULE 2 SUBTOPIC 1 OBJECT ORIENTED PROGRAMMING class HelloWorld defines a class class HelloWorld a template for an object of derived type HelloWorld public access specifier/modifier the main method is declared _______ so that it is accessible as part of the public interface of public the program. static state of the method static it is _______ because it must be called before the class that hosts the method is instantiated It returns _______ because the Java interpreter does not expect to receive or process any void output from the class. main the name of a method where the program starts executing. String args[] is an array of strings that can be used to pass command-line arguments to the program. System.out.println( ): The println method is one of dozens of methods in the _________. System class System.out.println( ): Application The System class is a part of the core Java language package of the __________. Programming Interface (API) System.out.println( ): a command that tells Java to print text to the console (the screen). Identifiers, Keywords, Comments, and Data What are the four (4) Java Language Fundamentals? types are names that are given by the programmer as name of variables, methods or functions, Identifiers classes etc. [T/F] When naming an identifier, each character is either a digit, letter, underscore or True currency symbol. True [T/F] When naming an identifier, first character cannot be a digit. True [T/F] When naming an identifier, the identifier name must not be a reserved word. // A single-line comment starting with? A multi-line comment enclosed within? A documentation or javadoc comment is enclosed between A documentation or javadoc comment can be used to generate HTML documents using the Javadoc _______ utility, which is part of Java language comment. Primitive Data Type: ________ Width in byte: 1 byte Min Value: -128 Max Value: 127 Primitive Data Type: ________ Width in byte: 2 short Min Value: -32768 Max Value: 32767 Primitive Data Type: ________ int Width in byte: 4 Min Value: -2147483648 Max Value: 21474833647 Primitive Data Type: ________ Width in byte: 8 long Min Value: Long.MIN_VALUE Max Value: Long.MAX_VALUE Primitive Data Type: ________ Width in byte: 4 float Min Value: Float.MIN_VALUE Max Value: Float.MAX_VALUE Primitive Data Type: ________ Width in byte: 8 double Min Value: Double.MIN_VALUE Max Value: Double.MIN_VALUE Primitive Data Type: ________ Width in byte: 1 bit boolean Min Value: true Max Value: false Primitive Data Type: ________ Width in byte: 2 unsigned char Min Value: ‘\u0000’ Max Value: ‘\uFFFF' _____ data types do not store the actual data value directly; instead, they store a reference Derived Data Types (or address) to the memory location where the actual data is stored. What type of data type are these? String Date Integer Double Long Float (Me thinks mali ppt Derived Data Types since primitive sila int, double, long and float. Sabi rin ni google) are used in converting one data type (such as a String) into another data type (such as int or Java Wrapper Classes double). Java Wrapper Classes It is also used in wrapping a primitive value into an object. NONE Wrapper Data Type = Primitive Data Type but in Capital Letter Syntax: ; [= value;] Example: Variable Declaration - String name; - int age; - double price = 55.66; Syntax: = value; Example: Assigning a value - name = “Maria Blanco”; - age = 22; - price = 200.50; System.out.println(); System.out.print(); In Java, you can simply use 3 for printing which are? System.out.printf(); System is a class out Is a public field out It accepts output data Java uses various methods to print or display data to the ________ (output) or to other Console or Streams _______ (files, etc.). System.out The most common way to output data in Java is through the ________ object System.out.print(); It prints string inside the quotes. System.out.print(); prints text without moving to the next line. It prints string inside the quotes similar like print() method. Then the cursor moves to the System.out.println(); beginning of the next line System.out.println(); prints text and then moves to the next line (adds a line break). System.out.printf(); It provides string formatting (similar to printf in C++) System.out.printf(); prints formatted text, similar to printf in C/C++. %d Which format specifier is used for decimal integer (base 10)? %f Which format specifier is used for floating-point number? %c Which format specifier is used for single character? %s Which format specifier is used for string? %x Which format specifier is used for hexadecimal integer (base 16)? %% Which format specifier is used for literal % character? %n Which format specifier is used for platform-specific line separator? Scanner Class; The _____ class is used to get user input, and it is found in the _________ package. java.util Scanner The ________ class allows us to read input from the user through the console Steps for Taking Input: 1. Importing the Scanner Class ─ import java.util.Scanner; 2. Creating a Scanner Object NOTE CODES!! ─ Scanner input = new Scanner(System.in); 3. Reading Input ─ int age = input.nextInt(); ─ String name = input.nextLine(); nextBoolean() Scanner Input Type that reads a boolean value from the user nextByte() Scanner Input Type that reads a byte value from the user nextDouble() Scanner Input Type that reads a double value from the user nextFloat () Scanner Input Type that reads a float value from the user nextInt() Scanner Input Type that reads a int value from the user nextLine () Scanner Input Type that reads a String value from the user nextLong() Scanner Input Type that reads a long value from the user nextShort() Scanner Input Type that reads a short value from the user BufferedReader is a Java class that reads text from a character-input stream, such as a file or the console. It reads characters from the input stream into a buffer, which improves efficiency by BufferedReader reducing the number of system calls to read individual characters. CCS0023 – MODULE 3 SUBTOPIC 1 OBJECT ORIENTED PROGRAMMING Unary Arithmetic are operators that operate on a single operand to perform specific operations. Operators Unary Plus (+) Indicates a positive value (often redundant). Unary Minus (-) Negates the value, turning positive into negative or vice versa. Increment (++) Increases the value by 1. Can be used in prefix or postfix form. Decrement (--) Decreases the value by 1. Can be used in prefix or postfix form postfix and prefix Increment and decrement operators have two formats which are? Binary Arithmetic These operators are fundamental in Java for performing mathematical calculations and are Operators commonly used in expressions, loops, and other control structures Addition (+) Adds two values together. Subtraction (-) Subtracts the second value from the first. Multiplication (*) Multiplies two values together. Division (/) Divides the first value by the second. Modulus (%) Returns the remainder of the division. There are some general guidelines to consider when creating and evaluating arithmetic NONE expressions: parentheses Use __________ to alter precedence Size Consider the _____ of resulting values and possible loss of precision */%+- Apply arithmetic operators’ precedence level which is? When using negative numbers with modulus calculation, drop the negative signs from either left operand and calculate the result. The sign of the _______ operand is the sign of the result. + The ___ operator can be used to add numbers and String objects. throwing of Dividing integer by zero results in the __________. ArithmeticException Bitwise operators works on integer values, by manipulating its bit-pattern equivalent. Bitwise operators operate on binary representations of integers (i.e., their bits). ~ (~Op) Bitwise inversion (unary) | (Op1 | Op2) Bitwise OR & (Op1 & Op2) Bitwise AND ^ (Op1 ^ Op2) Bitwise EX-OR Shift Operators performs bit manipulation on data by shifting the bits of its first operand right or left >> (op1 >> op2) shift bits of op1 right by distance op2 > (op1 >>> op2) shift bits of op1 right by distance op2 (unsigned) Relational Operators compares two values and determines the relationship between them. > op1 is greater than op2 >= op1 is greater than or equal to op2 < op1 is less than op2 Internal Invariants Many programmers use comments to indicate programming assumptions. if (i % 3 == 0) {... } else if (i % 3 == 1) {... } When To Use else { // We know (i % 3 == 2) Assertions... } Now we can use assertions to guarantee the behavior. if (i % 3 == 0) {... } else if (i % 3 == 1) {... } else { assert i % 3 == 2 : i;... } > Control Flow If a program should never reach a point, then a constant false assertion may be used. void foo() { for (...) { When To Use if (...) Assertions return; } assert false; // Execution should never get here } import java.util.*; import java.util.Scanner; public class AssertionExample{ public static void main( String args[] ){ Scanner scanner = new Scanner( System.in ); System.out.print( "Enter a number between 0 and 20: " ); int value = scanner.nextInt(); AssertionExample.java assert( value >= 0 && value Interfaces and its implementations, i.e., classes > Algorithm The java.util package contains all the classes and interfaces for the Collection framework. Hierarchy of Collection Framework Methods of Collection Interface where: public boolean add(E e) - It is used to insert an element in this collection. public boolean addAll Methods of Collection Interface where: (Collection c) - It is used to delete all the elements of the specified collection from the invoking collection. default boolean Methods of Collection Interface where: removeIf(Predicate - It is used to delete all the elements of invoking collection except the specified collection. c) Methods of Collection Interface where: public int size() - It returns the total number of elements in the collection. Methods of Collection Interface where: public void clear() - It removes the total number of elements from the collection. public boolean Methods of Collection Interface where: contains(Object - It is used to search an element. element) public boolean Methods of Collection Interface where: contains All - It is used to search the specified collection in the collection. (Collection c) public Iterator Methods of Collection Interface where: iterator() - It returns an iterator. public Object[] Methods of Collection Interface where: toArray() - It converts collection into array. Methods of Collection Interface where: public T[] - It converts collection into array. Here, the runtime type of the returned array is that of the toArray(T[] a) specified array. public boolean Methods of Collection Interface where: isEmpty() - It checks if collection is empty. default Stream Methods of Collection Interface where: parallelStream() - It returns a possibly parallel Stream with the collection as its source. default Stream Methods of Collection Interface where: stream() - It returns a sequential Stream with the collection as its source. default Spliterator Methods of Collection Interface where: spliterator() - It generates a Spliterator over the specified elements in the collection. public boolean Methods of Collection Interface where: equals(Object - It matches two collections. element) Methods of Collection Interface where: public int hashCode() - It returns the hash code number of the collection. Iterable Interface is the root interface for all the collection classes. The Collection interface extends the Iterable interface and therefore all the subclasses of Iterable Interface Collection interface also implement the _______ interface. Iterable Interface It contains only one abstract method. i.e. Iterator iterator() It returns the iterator over the elements of type T. Collection interface is the interface which is implemented by all the classes in the collection framework. Collection interface It declares the methods that every collection will have. In other words, we can say that the _________ builds the foundation on which the collection Collection interface framework depends. Some of the methods of ________ are Boolean add ( Object obj), Boolean addAll ( Collection Collection interface c), void clear(), etc. which are implemented by all the subclasses of __________. 1 answer List interface is the child interface of Collection interface. List interface It inhibits a list type data structure in which we can store the ordered collection of objects. List interface It can have duplicate values. List interface is implemented by the classes ArrayList, LinkedList, Vector, and Stack. To instantiate the List interface, we must use: List list1 = new ArrayList(); List interface List list2 = new LinkedList(); List list3 = new Vector(); List list4 = new Stack(); There are various methods in __________ that can be used to insert, delete, and access the List interface elements from the list ArrayList The ________ class implements the List interface. ArrayList It uses a dynamic array to store the duplicate element of different data types. ArrayList The __________ class maintains the insertion order and is non-synchronized. ArrayList The elements stored in the ___________ class can be randomly accessed. LinkedList ___________ implements the Collection interface. LinkedList It uses a doubly linked list internally to store the elements. LinkedList It can store the duplicate elements. LinkedList It maintains the insertion order and is not synchronized. LinkedList In ______________, the manipulation is fast because no shifting is required. Vector _________ uses a dynamic array to store the data elements. It is similar to ArrayList. However, It is synchronized and contains many methods that are not Vector the part of Collection framework. Stack The ________ is the subclass of Vector. Stack It implements the last-in-first-out data structure, i.e., Stack. The ___________ contains all of the methods of Vector class and also provides its methods Stack like boolean push(), boolean peek(), boolean push(object o), which defines its properties Queue Queue interface maintains the first-in-first-out order. It can be defined as an ordered list that is used to hold the elements which are about to be Queue processed. There are various classes like PriorityQueue, Deque, and ArrayDeque which implements the Queue __________ interface. Queue interface can be instantiated as: Queue Queue q1 = new PriorityQueue(); Queue q2 = new ArrayDeque(); PriorityQueue The ____________ class implements the Queue interface. PriorityQueue It holds the elements or objects which are to be processed by their priorities. PriorityQueue _____________ doesn't allow null values to be stored in the queue. Deque Interface Deque interface extends the Queue interface. Deque Interface In ___________, we can remove and add the elements from both the side. ___________, stands for a double-ended queue which enables us to perform the operations Deque Interface at both the ends. Deque can be instantiated as: Deque Interface Deque d = new ArrayDeque(); ArrayDeque _____________ class implements the Deque interface. It facilitates us to use the Deque. Unlike queue, we can add or delete the elements from ArrayDeque both the ends. ArrayDeque _________ is faster than ArrayList and Stack and has no capacity restrictions. Set Interface _________ Interface in Java is present in java.util package. Set Interface It extends the Collection interface. It represents the unordered set of elements which doesn't allow us to store the duplicate Set Interface items. Set Interface We can store at most one null value in _________. Set Interface _________ is implemented by HashSet, LinkedHashSet, and TreeSet. Set can be instantiated as: Set s1 = new HashSet(); Set Interface Set s2 = new LinkedHashSet(); Set s3 = new TreeSet(); _________ class implements Set Interface. It represents the collection that uses a hash table Hashset for storage. Hashset Hashing is used to store the elements in the _________. Hashset It contains unique items. Linked Hashset _________ class represents the LinkedList implementation of Set Interface. Linked Hashset It extends the HashSet class and implements Set interface. Linked Hashset Like HashSet, It also contains unique elements. It maintains the insertion order and permits null elements. SortedSet Interface _________ is the alternate of Set interface that provides a total ordering on its elements. The elements of the _________ are arranged in the increasing (ascending) order. The _________ provides the additional methods that inhibit the natural ordering of the SortedSet Interface elements. The SortedSet can be instantiated as: SortedSet Interface SortedSet set = new TreeSet(); TreeSet Java _________ class implements the Set interface that uses a tree for storage. TreeSet Like HashSet, _________ also contains unique elements. TreeSet However, the access and retrieval time of _________ is quite fast. TreeSet The elements in _________ stored in ascending order. CCS0023 – MODULE 10 SUBTOPIC 1 OBJECT ORIENTED PROGRAMMING Java I/O (Input and is used to process the input and produce the output. Output) Stream Java uses the concept of a ______ to make I/O operation fast java.io The __________ package contains all the classes required for input and output operations. Java I/O API We can perform file handling in Java by ___________. Stream is a sequence of data. Stream In Java, a _________ is composed of bytes. Stream It's called a _________ because it is like a stream of water that continues to flow. In Java, ________ streams are created for us automatically. All these streams are attached Three (3) with the console. System.out This automatically created stream is the standard output stream. System.in This automatically created stream is the standard input stream. System.err This automatically created stream is the standard error stream. Java application uses an output stream to write data to a destination; it may be a file, an OutputStream array, peripheral device or socket. Java application uses an input stream to read data from a source; it may be a file, an array, InputStream peripheral device or socket OutputStream Class is an abstract class. It is the superclass of all classes representing an output stream of bytes. output stream An ____________ accepts output bytes and sends them to some sink. public void Useful methods of OutputStream Class: write(int)throws - is used to write a byte to the current output stream. IOException public void Useful methods of OutputStream Class: write(byte[]) throws - is used to write an array of byte to the current output stream. IOException public void flush() Useful methods of OutputStream Class: throws IOException - flushes the current output stream. public void close() Useful methods of OutputStream Class: throws IOException - is used to close the current output stream. OutputStream Hierarchy InputStream Class is an abstract class. It is the superclass of all classes representing an input stream of bytes. public abstract int Useful methods of InputStream Class: read() throws - reads the next byte of data from the input stream. It returns -1 at the end of the file. IOException public int available() Useful methods of InputStream Class: throws IOException - returns an estimate of the number of bytes that can be read from the current input stream. public void close() Useful methods of InputStream Class: throws IOException - is used to close the current input stream. InputStream Hierarchy FileOutputStream is an output stream used for writing data to a file. FileOutputStream If you have to write primitive values into a file, use ___________ class. FileOutputStream You can write byte-oriented as well as character-oriented data through ____________ class. FileOutputStream But, for character-oriented data, it is preferred to use FileWriter than ______________. public class FileOutputStream FileOutputStream class declaration for Java.io.FileOutputStream class: extends OutputStream protected void FileOutputStream class methods finalize() - It is used to clean up the connection with the file output stream. FileOutputStream class methods void write(byte[] ary) - It is used to write ary.length bytes from the byte array to the file output stream. FileOutputStream class methods void write(byte[] ary, - It is used to write len bytes from the byte array starting at offset off to the file output int off, int len) stream. FileOutputStream class methods void write(int b) - It is used to write the specified byte to the file output stream. FileChannel FileOutputStream class methods getChannel() - It is used to return the file channel object associated with the file output stream. FileOutputStream class methods FileDescriptor getFD() - It is used to return the file descriptor associated with the stream. FileOutputStream class methods void close() - It is used to closes the file output stream. FileInputStream _____________ class obtains input bytes from a file. It is used for reading byte-oriented data (streams of raw bytes) such as image data, audio, FileInputStream video etc. FileInputStream You can also read character-stream data. FileReader But, for reading streams of characters, it is recommended to use _________ class. public class FileInputStream FileInputStream class declaration for Java.io.FileInputStream class: extends InputStream Java FileInputStream class methods int available() - It is used to return the estimated number of bytes that can be read from the input stream. Java FileInputStream class methods int read() - It is used to read the byte of data from the input stream. int read(byte[] b) Java FileInputStream class methods - It is used to read up to b.length bytes of data from the input stream. int read(byte[] b, int Java FileInputStream class methods off, int len) - It is used to read up to len bytes of data from the input stream. long skip(long x) Java FileInputStream class methods - It is used to skip over and discards x bytes of data from the input stream. FileChannel Java FileInputStream class methods getChannel() - It is used to return the unique FileChannel object associated with the file input stream. FileDescriptor getFD() Java FileInputStream class methods - It is used to return the FileDescriptor object. protected void Java FileInputStream class methods finalize() - It is used to ensure that the close method is call when there is no more reference to the file input stream. void close() Java FileInputStream class methods - It is used to closes the stream. Java FileWriter class is used to write character-oriented data to a file. Java FileWriter class It is character-oriented class which is used for file handling in java. Unlike FileOutputStream class, you don't need to convert string into byte array because it Java FileWriter class provides method to write string directly. public class FileWriter extends Java.io.FileWriter OutputStreamWriter Constructors of FileWriter class: FileWriter(String file) - Creates a new file. It gets file name in string. Constructors of FileWriter class: FileWriter(File file) - Creates a new file. It gets file name in File object. Methods of FileWriter class: void write(String text) - It is used to write the string into FileWriter. Methods of FileWriter class: void write(String text) - It is used to write the char into FileWriter. Methods of FileWriter class: void write(char[] c) - It is used to write char array into FileWriter. Methods of FileWriter class: void flush() - It is used to flushes the data of FileWriter. Methods of FileWriter class: void close() - It is used to close the FileWriter. Java FileReader class is used to read data from the file. Java FileReader class It returns data in byte format like FileInputStream class Java FileReader class It is character-oriented class which is used for file handling in java public class FileReader extends Java.io.FileReader InputStreamReader Constructors of FileReader class: FileReader(String file) - It gets filename in string. It opens the given file in read mode. If file doesn't exist, it throws FileNotFoundException. Constructors of FileReader class: FileReader(File file) - It gets filename in file instance. It opens the given file in read mode. If file doesn't exist, it throws FileNotFoundException. Methods of FileReader class: int read() - It is used to return a character in ASCII form. It returns -1 at the end of file. Methods of FileReader class: void close() - It is used to close the FileReader class. CCS0023 – FORMA ASSESSMENT 1 OBJECT ORIENTED PROGRAMMING Sun Microsystems James Gosling works for what company when they developed java? True An IDE may have Various tools to simplify the construction of a GUI. Enterprise Edition A java edition that is the standard in community-driven enterprise software False A documentation or javadoc comment is enclosed between What is the name of the class in this program: class HelloWorld{ HelloWorld public static void main(String args[ ]){ System.out.println(“Hello World”); } } True integer data type is for whole numbers only. What is the name of the class in this program: class Rectangle{ Rectangle public static void main(String args[ ]){ System.out.println(“This is a Rectangle”); } } A method that prints string inside the quotes then the cursor moves to the beginning of the Println() next line FALSE Most IDEs today doesn't have GUI modeling utilities that simplify the development of UIs. JAVA SOURCE CODE A file that is compiled to produce bytecode file TRUE "\t" is an escape character for tab. TRUE Scanner class used to get user input. FALSE boolean data type has two or more values Architecture neutral A feature of java that means Java technology is designed to support applications that will be and portable deployed into heterogeneous network environments TRUE The JVM creates a software simulation of a CPU and memory and handles all communication between the Java program and the underlying operating system and hardware. TRUE nextLong () reads a long value from the user. TRUE println belongs to the System class. both option1 and A valid Identifier or name in Java language can start with which character? option2 TRUE IDE stands for Integrated Development Environment FALSE In 1996, the java release as a core component of Sun Microsystems' Java platform? TRUE Netbeans started as a student project called Xelfi TRUE Scanner class is found on java.util package. FALSE An IDE doesn't have Compiler and/or interpreter. TRUE static is a state of a method TRUE double data type has a width of 8 in bytes. FALSE out keyword accepts input data TRUE out keyword accepts output data.class Java Bytecode File Extension name. The __________ creates a software simulation of a CPU and memory and handles all JVM communication between the Java program and the underlying operating system and hardware. True %d is for used for decimal All of the Choices (?) It is a fast fully-featured Integrated Development Environment (IDE) with support for Java. javac HelloWorld.java Correct command for compiling a text file named "HelloWorld.java" using console False Java Primitive data types are used in converting one data type into another data type. The goal in developing netbeans was to write a python- like Java IDE in Java for the first False time. 1995 In what year was java release as a core component of Sun Microsystems' Java platform? True IDE is a computer software to help computer programmers develop software. True double and float data types are used for numbers with decimal places False Scanner class is found on java.io package. True Every statement in Java language should end with ";"? False println()provides string formatting. False A single-line comment starts with /* True short has a value that ranges from -32768 to 32767 A feature of java that provides extensive compile-time checking, followed by a second level Robust and Secure of run-time checking. The main method is declared private so that it is accessible as part of the private interface of false the program. True byte has a maximum value of 127 False File extension name of a java file is.javac. Both Options 1 and 2 What is the need to mention "static" before main method? main method is int because the Java interpreter does not expect to receive or process any False output from the class. Member A function in C language is similar to what in Java language? To call the main method outside of What is the use of Access modifier "public" in Java language? Class or Package by JVM Java is a portable language that could run on any platform. The language was able to do this True by generating intermediate code for a hypothetical computer called a virtual machine. False static is a not the state of a method The main method is non-static because it must be called before the class that hosts the False method is instantiated False API stands for Application Programmable Interface Void What is the default return type of a method in Java language? Passing arguments at String args[] in main method are used for? public static void main(String args[]) { // } run time True integer data type is for whole numbers only. False, two only boolean data type has two or more values \n Escape character for printing '\'. True Netscape Navigator was developed in 1995 to support Java. True One of the tools for Object oriented design includes object inspector javac The command to compile a java source code Class or interface All methods and variables in Java language are kept inside a? CCS0023 – FORMA ASSESSMENT 2 OBJECT ORIENTED PROGRAMMING Consider the following codes: int x=4; 4 System.out.println(x--); What will be the EXACT output? int[] img; Which of the following declares an array of int named img? What will be the output of the following program? public class AllDimensionArrays { public static void main(String[] args) { Compilation Error or int[] a1d = {}; Runtime Error for some int[] b1d = {1, 3}; other reason. int[][] a2d = {}; int[][] b2d = {{}}; Or int[][] c2d = {{1, 2}, {5}}; System.out.print(a1d.length + " " + b1d.length + " "); ArrayIndexOutOfBounds System.out.print(a2d.length + " " + a2d.length + " " + b2d.length + " " + b2d.length + " Exception "); System.out.print(c2d.length + " " + c2d.length + " " + c2d.length); } } 2 What is the result of 7&2 Consider the following codes: int x=2; 1 System.out.println(--x); What will be the EXACT output? What will be the output of the following program? class ArrayOutput { public static void main(String args[]) { int[][] scores = new int[]; scores = new int; Throws ArrayIndexOut scores = new int; OfBoundsException scores = new int; for(int i = 0; i < scores.length; i++) { for(int j = 0; j < scores.length; j++) { scores[i][j] = i + j; System.out.print(scores[i][j] + " "); } } } } ~ (bitwise compliment) An operator that has the effect of 'flipping' bits. What is the EXACT output: int i = 4; k = 16 int j = 21; int k = ++i * 7 + 2 - j--; System.out.println("k = " + k); What is the output of the following program fragment? for ( int j = 0; j < 5; j++ ) { 01234 System.out.print( j + " " ); } System.out.println( ); = Assigns values from right side operands to left side operand. shift operator An operator that shifts bits to the left or right shift. What will be the output of the following program? int c = 0, e = 50; e = 51 boolean b = (c == 1) || (++e < 100); e = 52 System.out.println("e = " + e); boolean f = (e++ < 100) || (c == 1); System.out.println("e = " + e); public class Network { public static void main(String[] args) { float f = 42.0f; float[] f1 = new float; float[] f2 = new float; float[] f3 = f1; long x = 42; f1 = 42.0f; } 2, 4 and 5 } Which of the following statement(s) is/are true? Option 1. f1 == f2 Option 2. f1 == f3 Option 3. f2 == f1 Option 4. x == f1 Option 5. f == f1 arithmetic operator It is a mathematical function that takes two operands and performs a calculation on them. || If any of the two operands are non-zero, then the condition becomes true. true Conditional operator is also known as the ternary operator that accepts three operands What will be the output of the following program? public class ArrayOutput My Array length is: 3 { Student Marks Array public static void main(String s[]) length is: 3 { int student_marks[] = new int; student_marks = new int[]{10, 20, 30}; int[] my_array = null; my_array = student_marks; System.out.println("My Array length is: " + my_array.length); System.out.println("Student Marks Array length is: " + student_marks.length); }} decrement operators decrease the value of the variable by a particular number by which it true was decreased The break statement causes the program flow to exit prematurely from the body of the True loop statement. arithmetic operator is a mathematical function that takes two operands and performs a True calculation on them. What will be the output of the following program? boolean lampX = false, result; boolean lampY = true; Lamp switch-on true result = lampY || lampX; Lamp switch-on true System.out.println("Lamp switch-on " + result); result = lampY | lampX; System.out.println("Lamp switch-on " + result); true unary operator is an operator that takes only one value for its operation A sequence of values. What is an array? | (bitwise OR) An operator that copies a bit if it exists in either operand. bitwise operator returns the result of shifting the bits of the left operand by the number of False, Shift positions specified by the right operand. What does the code output? int p=0; hi while (p 0; i--) 15 { System.out.println(a[i]); } } } % An operator that divides left-hand operand by right-hand operand and returns remainder. The _____ statement causes the program flow to exit prematurely from the body of the Break loop statement. 1 What does the code output? 2 int p=0; 3 while (p

Use Quizgecko on...
Browser
Browser