Chettinad College of Engineering & Technology Department of Information Technology Internal Examination II (Answer Key)
|
|
- Evan McLaughlin
- 5 years ago
- Views:
Transcription
1 Chettinad College of Engineering & Technology Department of Information Technology Internal Examination II (Answer Key) Branch & Section : B.Tech-IT / III Date: Semester : III Year V Sem Max. Marks: 50 Subject Code & Title : IT2301 Java Programming Staff In-charge: Mrs P.Susila Part A (5 x 2 = 10 marks) Answer all the Questions 1. Differentiate a vector and array in Java. A vector is a dynamic array, whose size can be increased, where as an array size cannot be changed. Reserve space can be given for vector, whereas for arrays cannot. A vector is a class where as an array is not. Vectors can store any type of objects, where as an array can store only homogeneous values. 2. What is a package? How to import a single package? A package is a group of similar types of classes, interfaces and sub-packages. The grouping is usually done according to functionality. In fact, packages act as containers for classes. Package can be categorized in two form, built-in package and user-defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc. 3. What is the difference between String and StringBuffer? String is immutable (once created cannot be changed) object. The object created as a String is stored in the Constant String Pool. String once assigned cannot be changed. StringBuffer is mutable means one can change the value of the object. The object created through StringBuffer is stored in the heap. StringBuffer is faster when performing concatenations. This is because when you concatenate a String, you are creating a new object (internally) every time since String is immutable. String Buffer can be converted to the string by using tostring() method. 4. What is object cloning? When a copy of a variable is made, the original and the copy objects have references to the same object. This means a change to either variable also affects the other. 1
2 Cloning is about creating the copy of original object. By default, java cloning is field by field copy. So, JVM when called for cloning, do following things: 1) If the class has only primitive data type members then a completely new copy of the object will be created and the reference to the new object copy will be returned. 2) If the class contains members of any class type then only the object references to those members are copied and hence the member references in both the original object as well as the cloned object refer to the same object. Types of Cloning: 1. Shallow Cloning Default Cloning method 2. Deep Cloning To do cloning a class must 1. Implement the Cloneable interface, and 2. Redefine the Clone method with the public access modifier. 5. How does the declaration of a local inner class differ from the declaration of an anonymous inner class? Local Inner Class: A class that is created inside a method is known as local inner class. If you want to invoke the methods of local inner class, you must instantiate this class inside the method. Their scope is always restricted to the block in which they are declared. Anonymous Inner Class: When using local inner classes, we can create any number of Objects for the Inner Class. If to make only a single object of a class, no need to give the class name. Such a class is called an Anonymous Inner Class. Here, Interface can be used, the inner class implements that interface. Outer Class s methods define the implementation of the inner class within its own member function. Part B (40 marks) Answer All the Questions 6. a. Write a java program to maintain the books details like BookId, accession number; book name, author, publication in books package and keep the journal details such as journal id; journal name; in journal package in main class use these two packages details for staff and student classes and display the books and journals information as requested by the user. (16) Packages Packages are java s way of grouping a variety of classes and / or interfaces together. The grouping is usually done according to functionality. In fact, packages act as containers for classes. Benefits of Packages The classes contained in the packages can be easily reused. In packages, classes can be unique compared with classes in other packages. That is, two classes in two different packages can have the same name. They 2
3 may be referred by their fully qualified name, comprising the package name and class name. Package provide a way to hide classes thus preventing other programs or package from accessing classes that are meant for internal use only. Packages also provide a way for separating design from coding. First we can design classes and decide their relationships, and then we can implement the java code needed for the methods. It is possible to change the implementation of any method without affecting the rest of the design. Types of Packages Java packages are therefore classified into two types. Pre defined packages (Java API Packages) User defined packages Sample Example Program package PackageBook; import java.io.*; public class Book int book_no, book_id, book_pages; public Book(int a, int b, int c) book_no=a; book_id=b; book_pages=c; public void BookInfo() System.out.println("The Book No "+book_no); System.out.println("The Book Id "+book_id); System.out.println("The Book Pages "+book_pages); import java.io.*; import PackageBook.Book; public class BookReader public static void main(string[] args) Book b=new Book(10, 15, 90); b.bookinfo(); 3
4 (Or) b. How to declare and initialize a string in java and also explain the different string handling functions with suitable examples. (16) String: Java s String type called String, is not a Simple Type, nor is it simply an array of characters. Rather String defines an Object. The String type is used to declare string variable. Java Strings are sequences of Unicode Characters. Use an object of type string as an argument to println(); String str = Welcome to JAVA ; System.out.println(str); Java has methods to compare two strings, search for a substring, concatenate two strings, and change the case of letters within a String. String object has been created, you cannot change the characters that comprise that string. String Constructors: The String class supports several constructors. To create an empty string call the default constructor. String str = new String(); Initialize the values through array of characters. char ch[] = a, b, c ; String str = new String(ch); o/p: abc 1. Subrange: String(char ch[], int start,int numchar); char ch[] = a, b, c, d, e,f ; String s = new String(ch,2,3); o/p: cde 2. String copy: String(String strobj); char ch[] = J, A, V, A ; String s1 = new String(ch); String s2 = new String(s1); System.out.println(s1); O/P: JAVA System.out.println(s2); O/P: JAVA 3. ASCII char: String (byte asciichars[]); String(byte asciichars[], int start, int numchars); byte ascii[] =65,66,67,68,69,70; String s1 = new String(ascii); System.out.println(s1); O/P: ABCDEF String s2 = new String(ascii,2,3); O/P: CDE 4
5 SPECIAL STRING OPERATIONS 1. Automatic creation of new String instances from string literals. 2. Concatenation of multiple String object by used of the + operators 3. Conversion of other data types to a string representation. Write some example programs for String class using methods like length(), concat(), charat(), getchars(), msg.getbytes(), tochararray(), equals() and equalsignorecase(), startswith() and endswith(),equals() Versus ==, compareto(), modifying a string like substring(), replace(), trim(), touppercase() and tolowercase(), etc., and StringBuffer methods. 7. a. i) Explain about JavaDoc comments. (8) JavaDoc Comments: Javadoc is a tool which comes with JDK and it is used for generating Java code documentation in HTML format from Java source code which has required documentation in a predefined format. The Java language supports three types of comments: /* text */ - The compiler ignores everything from /* to */. // text - The compiler ignores everything from // to the end of the line. /** documentation */ - This is a documentation comment and in general its called doc comment. The JDK javadoc tool uses doc comments when preparing automatically generated documentation. Types of Comments Class Comments - /*.*/ and /* * */ Method @throws Field Comments Data Members - /* * */ General @since. /** * The HelloWorld program implements an application that * simply displays "Hello World!" to the standard output. * John */ public class HelloWorld public static void main(string[] args) /* Prints Hello, World! on standard output. */ System.out.println("Hello World!"); 5
6 The JavaDoc Tags: Give explanation and syntax for the @since, ii) Consider a class Student with attributes name and subject. Write a java program to create and clone instances of Student class. (8) Object Cloning in Java: When a copy of a variable is made, the original and the copy objects have references to the same object. This means a change to either variable also affects the other. Student original = new Student(1001, CCET ); Student copy = original; // taking copy copy.dept_change( CSE ); // Original Objects also changed In order to copy an old object into another new object which should not refer to the old object but the values has to copied to a new reference then use the clone method. The object cloning is a way to create exact copy of another object without affecting one another. Student copy = original.clone(); copy.dept_change( CSE ); //Original unchanged The java.lang.cloneable interface must be implemented by the class whose object clone we want to create. If we don't implement Cloneable interface, clone() method generatesclonenotsupportedexception. The clone() method is a protected method defined in the Object class. Syntax of the clone() method is as follows: Syntax: protected Object clone() throws CloneNotSupportedException Types of Cloning: 1. Shallow Cloning Default Cloning method 2. Deep Cloning To do cloning a class must Implement the Cloneable interface, and Redefine the Clone method with the public access modifier. Program for Shallow Copy class Subject String name; String getname() 6
7 return name; void setname(string s) name = s; Subject(String s) name = s; class Student implements Cloneable //Contained object Subject subj; String name; Student(String s, String sub) name = s; subj = new Subject(sub); String getname() return name; void setname(string s) name = s; Subject getsubj() return subj; public Object clone() //shallow copy try return super.clone(); catch (CloneNotSupportedException e) 7
8 return null; public class ShallowCopy public static void main(string[] args) //Original Object Student stud = new Student("John", "Algebra"); System.out.println("Original Object: " + stud.getname() + " - " + stud.getsubj().getname()); //Clone Object Student clonedstud = (Student)stud.clone(); System.out.println("Cloned Object: " + clonedstud.getname() + " - " + clonedstud.getsubj().getname()); stud.setname("dan"); stud.getsubj().setname("physics"); System.out.println("Original Object after it is updated: " + stud.getname() + " - " + stud.getsubj().getname()); System.out.println("Cloned Object after updating original object: " + clonedstud.getname() + " - " + clonedstud.getsubj().getname()); (Or) b. What is exception handling in java? Why it is used? Write a java code to simulate the way a stack mechanism works with exception handling, throwing and dealing with exceptions such as stack is full(if you want to add more elements into the stack) or stack is empty (if you want to pop elements from the stack). (16) Exception An Exception is a condition that is caused by a run time error in the program. Exception Handling If the exception object is not caught and handled properly, the compiler will display an error message and will terminate the program. If we want the program to continue with the execution of the remaining appropriate message for taking corrective actions. This task is known as exception handling. 8
9 All Exception types are subclasses of the built in class Throwable. Throwable is at the top of the exception class hierarchy Exception Handling Mechanism The purpose of the exception handling mechanism is to provide means to detect and report an exceptional circumstance, so that appropriate action can be taken. The Error Handling code that performs the following tasks: 1. Find the problem (Hit the Exception) 2. Inform that an error has occurred (Throw the exception) 3. Receive the error information (Catch the exception) 4. Take corrective actions (Handle the exception) Program import java.util.linkedlist; class Stackimp implements Mystack int stack[]=new int[n]; int top=-1; public void push() try DataInputStream dis=new DataInputStream(System.in); if(top==(n-1)) System.out.println("overflow"); return; else System.out.println("enter element"); int ele=integer.parseint(dis.readline()); stack[++top]=ele; catch(exception e) System.out.println(e); public void pop() 9
10 class stackadt if(top<0) System.out.println("underflow"); return; else int popper=stack[top]; top--; System.out.println("popped element "+popper); public void peek() if(top<0) System.out.println("underflow"); return; else int popper=stack[top]; System.out.println("popped element "+popper); public void display() if(top<0) System.out.println("empty"); return; else String str=""; for(int i=0;i<=top;i++) str=str+" "+stack[i]; System.out.println("elements are "+str); 10
11 public static void main(string arg[])throws IOException DataInputStream dis=new DataInputStream(System.in); int ch1=0; do System.out.println("Enter your choice for 1.Stack in Array 2.Stack in linkedlist 3.Exit"); ch1=integer.parseint(dis.readline()); switch(ch1) case 1: int ch2=0; Stackimp stk=new Stackimp(); do System.out.println("Stack in Array"); System.out.println("Enter your choice for 1.push 2.pop 3.peek 4.display 5.exit"); ch2=integer.parseint(dis.readline()); switch(ch2) case 1:stk.push(); case 2:stk.pop(); case 3:stk.peek(); case 4:stk.display(); case 5: while(ch2<5); case 2: int ch3=0; stacklist st=new stacklist(); do System.out.println("Stack in LinkedList"); System.out.println("enter your choice for 1.push 2.pop 3.peek 4.display 5.exit"); ch3=integer.parseint(dis.readline()); 11
12 switch(ch3) case 1:st.push(); case 2:st.pop(); case 3:st.peek(); case 4:st.display(); case 5: while(ch3<5); case 3:System.exit(0); while(ch1<=3); 8. What is meant by stream? What are the types of streams and classes? Explain in detail. (8) Stream A Stream is a sequence of data. It is composed of bytes. It is basically a channel on which the data flow from sender to receiver. The Java I/O means Java Input/Output. It is provided by the java.io package. This package has an InputStream and OutputStream. Java InputStream is defined for reading the stream, byte stream and array of byte stream. An input object that reads the stream of data from a file is called input stream and the output object that writes the stream of data to a file is called output stream. Java implements streams within the classes that are defined in java.io package. Types of streams Character Stream Byte Stream Character Stream The two super classes in character stream are Reader and Writer. Byte Stream The two super clasess in byte stream are InputStream and OutputStream from which most of the other classes are derived. 12
13 Some important Character Stream classes: Reader, Writer, BufferedReader, BufferedWriter, FileReader, FileWriter, InputStreamReader, OutputStreamReader, PrintWriter. Some important Byte Stream classes: InputStream, OutputStream, BufferedInputStream, BufferedOutputStream, DataInputStream, DataOutputStream, FileInputStream, FileOutputStream, PrintStream. Write example program using some of the above classes Sample Program import java.io.*; public class BRReadLines public static void main(string args[]) throws IOException BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str; System.out.println("Enter lines of text."); System.out.println("Enter 'end' to quit."); do str = br.readline(); System.out.println(str); while(!str.equals("end")); Faculty In-charge HOD/IT 13
copy.dept_change( CSE ); // Original Objects also changed
UNIT - III Topics Covered The Object class Reflection Interfaces Object cloning Inner classes Proxies I/O Streams Graphics programming Frame Components Working with 2D shapes. Object Clone Object Cloning
More informationDarshan Institute of Engineering & Technology for Diploma Studies
Streams A stream is a sequence of data. In Java a stream is composed of bytes. In java, 3 streams are created for us automatically. 1. System.out : standard output stream 2. System.in : standard input
More informationString. Other languages that implement strings as character arrays
1. length() 2. tostring() 3. charat() 4. getchars() 5. getbytes() 6. tochararray() 7. equals() 8. equalsignorecase() 9. regionmatches() 10. startswith() 11. endswith() 12. compareto() 13. indexof() 14.
More informationDEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
Internal Examination 1 Answer Key DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Branch & Sec : CSE Date : 08.08.2014 Semester : V Sem Max Marks : 50 Marks Sub Code& Title : CS2305 Programming Paradigms
More informationByte and Character Streams. Reading and Writing Console input and output
Byte and Character Streams Reading and Writing Console input and output 1 I/O basics The io package supports Java s basic I/O (input/output) Java does provide strong, flexible support for I/O as it relates
More informationObject-Oriented Programming Design. Topic : Streams and Files
Electrical and Computer Engineering Object-Oriented Topic : Streams and Files Maj Joel Young Joel Young@afit.edu. 18-Sep-03 Maj Joel Young Java Input/Output Java implements input/output in terms of streams
More informationIT101. File Input and Output
IT101 File Input and Output IO Streams A stream is a communication channel that a program has with the outside world. It is used to transfer data items in succession. An Input/Output (I/O) Stream represents
More informationLecture 11.1 I/O Streams
21/04/2014 Ebtsam AbdelHakam 1 OBJECT ORIENTED PROGRAMMING Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 2 Outline I/O Basics Streams Reading characters and string 21/04/2014 Ebtsam AbdelHakam
More informationSpecial error return Constructors do not have a return value What if method uses the full range of the return type?
23 Error Handling Exit program (System.exit()) usually a bad idea Output an error message does not help to recover from the error Special error return Constructors do not have a return value What if method
More informationCOMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output
COMP 213 Advanced Object-oriented Programming Lecture 19 Input/Output Input and Output A program that read no input and produced no output would be a very uninteresting and useless thing. Forms of input/output
More informationToday. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes. Debugging tools
Today Book-keeping File I/O Subscribe to sipb-iap-java-students Inner classes http://sipb.mit.edu/iap/java/ Debugging tools Problem set 1 questions? Problem set 2 released tomorrow 1 2 So far... Reading
More informationChapter 10. IO Streams
Chapter 10 IO Streams Java I/O The Basics Java I/O is based around the concept of a stream Ordered sequence of information (bytes) coming from a source, or going to a sink Simplest stream reads/writes
More information1.00 Lecture 30. Sending information to a Java program
1.00 Lecture 30 Input/Output Introduction to Streams Reading for next time: Big Java 15.5-15.7 Sending information to a Java program So far: use a GUI limited to specific interaction with user sometimes
More informationFile Operations in Java. File handling in java enables to read data from and write data to files
Description Java Basics File Operations in Java File handling in java enables to read data from and write data to files along with other file manipulation tasks. File operations are present in java.io
More informationChapter 10 Input Output Streams
Chapter 10 Input Output Streams ICT Academy of Tamil Nadu ELCOT Complex, 2-7 Developed Plots, Industrial Estate, Perungudi, Chennai 600 096. Website : www.ictact.in, Email : contact@ictact.in, Phone :
More informationI/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O
I/O 10-7-2013 I/O in Java I/O streams vs. Reader/Writer HW#3 due today Reading Assignment: Java tutorial on Basic I/O public class Swimmer implements Cloneable { public Date geteventdate() { return (Date)
More informationWeek 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O
Week 12 Streams and File I/O Overview of Streams and File I/O Text File I/O 1 I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or a file
More information09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.
CSE 143 Java Streams Reading: 19.1, Appendix A.2 GREAT IDEAS IN COMPUTER SCIENCE REPRESENTATION VS. RENDERING 4/28/2002 (c) University of Washington 09-1 4/28/2002 (c) University of Washington 09-2 Topics
More informationCS 251 Intermediate Programming Java I/O Streams
CS 251 Intermediate Programming Java I/O Streams Brooke Chenoweth University of New Mexico Spring 2018 Basic Input/Output I/O Streams mostly in java.io package File I/O mostly in java.nio.file package
More informationFile IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20
File IO Computer Science and Engineering College of Engineering The Ohio State University Lecture 20 I/O Package Overview Package java.io Core concept: streams Ordered sequences of data that have a source
More informationJava Input/Output. 11 April 2013 OSU CSE 1
Java Input/Output 11 April 2013 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter
More informationAny serious Java programmers should use the APIs to develop Java programs Best practices of using APIs
Ananda Gunawardena Java APIs Think Java API (Application Programming Interface) as a super dictionary of the Java language. It has a list of all Java packages, classes, and interfaces; along with all of
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More information2. All the strings gets collected in a special memory are for Strings called " String constant pool".
Basics about Strings in Java 1. You can create Strings in various ways:- a) By Creating a String Object String s=new String("abcdef"); b) By just creating object and then referring to string String a=new
More informationInput, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003
Input, Output and Exceptions COMS W1007 Introduction to Computer Science Christopher Conway 24 June 2003 Input vs. Output We define input and output from the perspective of the programmer. Input is data
More informationPIC 20A Streams and I/O
PIC 20A Streams and I/O Ernest Ryu UCLA Mathematics Last edited: December 7, 2017 Why streams? Often, you want to do I/O without paying attention to where you are reading from or writing to. You can read
More informationTirgul 1. Course Guidelines. Packages. Special requests. Inner classes. Inner classes - Example & Syntax
Tirgul 1 Today s topics: Course s details and guidelines. Java reminders and additions: Packages Inner classes Command Line rguments Primitive and Reference Data Types Guidelines and overview of exercise
More informationJava Intro 3. Java Intro 3. Class Libraries and the Java API. Outline
Java Intro 3 9/7/2007 1 Java Intro 3 Outline Java API Packages Access Rules, Class Visibility Strings as Objects Wrapper classes Static Attributes & Methods Hello World details 9/7/2007 2 Class Libraries
More informationLab 14 & 15: String Handling
Lab 14 & 15: String Handling Prof. Navrati Saxena TA: Rochak Sachan String Handling 9/11/2012 22 String Handling Java implements strings as objects of type String. Once a String object has been created,
More informationBasic I/O - Stream. Java.io (stream based IO) Java.nio(Buffer and channel-based IO)
I/O and Scannar Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 I/O operations Three steps:
More informationCore Java Contents. Duration: 25 Hours (1 Month)
Duration: 25 Hours (1 Month) Core Java Contents Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing a Java Application at command prompt Java
More informationUSING LIBRARY CLASSES
USING LIBRARY CLASSES Simple input, output. String, static variables and static methods, packages and import statements. Q. What is the difference between byte oriented IO and character oriented IO? How
More informationThe Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)
The Java I/O System Binary I/O streams (ASCII, 8 bits) InputStream OutputStream The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing binary I/O to character I/O
More informationTEXT-BASED APPLICATIONS
Objectives 9 TEXT-BASED APPLICATIONS Write a program that uses command-line arguments and system properties Write a program that reads from standard input Write a program that can create, read, and write
More information1993: renamed "Java"; use in a browser instead of a microwave : Sun sues Microsoft multiple times over Java
Java history invented mainly by James Gosling ([formerly] Sun Microsystems) 1990: Oak language for embedded systems needs to be reliable, easy to change, retarget efficiency is secondary implemented as
More informationneeds to be reliable, easy to change, retarget efficiency is secondary implemented as interpreter, with virtual machine
Java history invented mainly by James Gosling ([formerly] Sun Microsystems) 1990: Oak language for embedded systems needs to be reliable, easy to change, retarget efficiency is secondary implemented as
More informationJava How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Data stored in variables and arrays is temporary It s lost when a local variable goes out of scope or when
More informationA Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.
A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. 9 Classes and Objects p. 11 Creating Objects p. 12 Static or
More informationLecture 22. Java Input/Output (I/O) Streams. Dr. Martin O Connor CA166
Lecture 22 Java Input/Output (I/O) Streams Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics I/O Streams Writing to a Stream Byte Streams Character Streams Line-Oriented I/O Buffered I/O
More informationSoftware Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)
Software Development & Education Center Java Platform, Standard Edition 7 (JSE 7) Detailed Curriculum Getting Started What Is the Java Technology? Primary Goals of the Java Technology The Java Virtual
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: alt. office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1214
More informationContents. iii Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1998, Revision B
Contents About the Course...xv Course Overview... xvi Course Map... xvii Module-by-Module Overview... xviii Course Objectives... xxii Skills Gained by Module... xxiii Guidelines for Module Pacing... xxiv
More informationExceptions and Working with Files
Exceptions and Working with Files Creating your own Exceptions. You have a Party class that creates parties. It contains two fields, the name of the host and the number of guests. But you don t want to
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationJava in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
More informationObject-Oriented Programming in the Java language
Object-Oriented Programming in the Java language Part 5. Exceptions. I/O in Java Yevhen Berkunskyi, NUoS eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Exceptions Exceptions in Java are objects. All
More information5/23/2015. Core Java Syllabus. VikRam ShaRma
5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5
More informationJAVA. Duration: 2 Months
JAVA Introduction to JAVA History of Java Working of Java Features of Java Download and install JDK JDK tools- javac, java, appletviewer Set path and how to run Java Program in Command Prompt JVM Byte
More informationSri Vidya College of Engineering & Technology Question Bank
1. What is exception? UNIT III EXCEPTION HANDLING AND I/O Part A Question Bank An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program s instructions.
More informationOverview CSE 143. Input and Output. Streams. Other Possible Kinds of Stream Converters. Stream after Stream... CSE143 Wi
CSE 143 Overview Topics Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Ch. 16 2/3/2005 (c) 2001-5, University of Washington 12-1 2/3/2005 (c) 2001-5,
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 30 April 4, 2018 I/O & Histogram Demo Chapters 28 HW7: Chat Server Announcements No penalty for late submission by tomorrow (which is a HARD deadline!)
More informationProgram 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*;
Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*; /* */ public
More informationHST 952. Computing for Biomedical Scientists Lecture 8
Harvard-MIT Division of Health Sciences and Technology HST.952: Computing for Biomedical Scientists HST 952 Computing for Biomedical Scientists Lecture 8 Outline Vectors Streams, Input, and Output in Java
More informationClass Library java.lang Package. Bok, Jong Soon
Class Library java.lang Package Bok, Jong Soon javaexpert@nate.com www.javaexpert.co.kr Object class Is the root of the class hierarchy. Every class has Object as a superclass. If no inheritance is specified
More informationToday s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO
Today s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO Ananda Gunawardena Objects and Methods working together to solve a problem Object Oriented Programming Paradigm
More informationHere is a hierarchy of classes to deal with Input and Output streams.
PART 15 15. Files and I/O 15.1 Reading and Writing Files A stream can be defined as a sequence of data. The InputStream is used to read data from a source and the OutputStream is used for writing data
More informationUNIT - II Object Oriented Programming - Inheritance
UNIT - II Object Oriented Programming - Inheritance Topics to be Covered: 1. Inheritance 2. Class Hierarchy 3. Polymorphism 4. Dynamic Binding 5. Final Keyword 6. Abstract Classes 7. Object Class 8. Reflection
More informationObjec&ves. Review. Standard Error Streams
Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 Review What are benefits of excep&ons What principle of Java do files break if we re not careful? What class
More informationCS Week 11. Jim Williams, PhD
CS 200 - Week 11 Jim Williams, PhD This Week 1. Exam 2 - Thursday 2. Team Lab: Exceptions, Paths, Command Line 3. Review: Muddiest Point 4. Lecture: File Input and Output Objectives 1. Describe a text
More informationLecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8
Today... Java basics S. Bowers 1 of 8 Java main method (cont.) In Java, main looks like this: public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World!"); Q: How
More informationWOSO Source Code (Java)
WOSO 2017 - Source Code (Java) Q 1 - Which of the following is false about String? A. String is immutable. B. String can be created using new operator. C. String is a primary data type. D. None of the
More informationObject Oriented Design. Object-Oriented Design. Inheritance & Polymorphism. Class Hierarchy. Goals Robustness Adaptability Flexible code reuse
Object-Oriented Design Object Oriented Design Goals Robustness Adaptability Flexible code reuse Principles Abstraction Encapsulation Modularity March 2005 Object Oriented Design 1 March 2005 Object Oriented
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationOverview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE
Overview CSE 143 Topics Data representation bits and bytes Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Sec. 19.1, Appendix A2 11/2/2003 (c) 2001-3,
More informationVariables of class Type. Week 8. Variables of class Type, Cont. A simple class:
Week 8 Variables of class Type - Correction! Libraries/Packages String Class, reviewed Screen Input/Output, reviewed File Input/Output Coding Style Guidelines A simple class: Variables of class Type public
More informationOverview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE. Representation of Primitive Java Types. CSE143 Au
Overview CSE 143 Topics Data representation bits and bytes Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Sec. 19.1, Appendix A2 11/2/2003 (c) 2001-3,
More informationOverview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE. Representation of Primitive Java Types. CSE143 Sp
Overview CSE 143 Topics Data representation bits and bytes Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Ch. 16 4/27/2004 (c) 2001-4, University of
More informationGUJARAT TECHNOLOGICAL UNIVERSITY
GUJARAT TECHNOLOGICAL UNIVERSITY MASTER OF COMPUTER APPLICATIONS (COURSE CODE-6) Subject: Java Programming Subject Code: 2630002 Year II (Semester III) (W.E.F. JULY 2013) Objectives: To develop proficiency
More informationתוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת
תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת A Typical Program Most applications need to process some input and produce some output based on that input The Java IO package (java.io) is to make that possible
More informationGetting Started in Java. Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park
Getting Started in Java Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park Hello, World In HelloWorld.java public class HelloWorld { public static void main(string [] args) { System.out.println(
More informationLesson 3: Accepting User Input and Using Different Methods for Output
Lesson 3: Accepting User Input and Using Different Methods for Output Introduction So far, you have had an overview of the basics in Java. This document will discuss how to put some power in your program
More informationJOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide
Module 10 I/O Fundamentals Objectives Upon completion of this module, you should be able to: Write a program that uses command-line arguments and system properties Examine the Properties class Construct
More information40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the
Answers 1) B 2) C 3) A 4) D 5) Non-static members 6) Static members 7) Default 8) abstract 9) Local variables 10) Data type default value 11) Data type default value 12) No 13) No 14) Yes 15) No 16) No
More informationOverview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE
CSE 143 Overview Topics Data representation bits and bytes Streams communicating with the outside world Basic Java files Other stream classes Streams Reading: Ch. 16 10/20/2004 (c) 2001-4, University of
More informationJava Input / Output. CSE 413, Autumn 2002 Programming Languages.
Java Input / Output CSE 413, Autumn 2002 Programming Languages http://www.cs.washington.edu/education/courses/413/02au/ 18-November-2002 cse413-18-javaio 2002 University of Washington 1 Reading Readings
More informationI/O Streams. Object-oriented programming
I/O Streams Object-oriented programming Outline Concepts of Data Streams Streams and Files File class Text file Binary file (primitive data, object) Readings: GT, Ch. 12 I/O Streams 2 Data streams Ultimately,
More informationExceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages
References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/
More informationObject-Oriented Design. March 2005 Object Oriented Design 1
Object-Oriented Design March 2005 Object Oriented Design 1 Object Oriented Design Goals Robustness Adaptability Flexible code reuse Principles Abstraction Encapsulation Modularity March 2005 Object Oriented
More informationVALLIAMMAI ENGINEERING COLLEGE
VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 60 0 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK III SEMESTER CS89- Object Oriented Programming Regulation 07 Academic Year 08 9 Prepared
More informationToday s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO. Understanding Board
Ananda Gunawardena Today s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO Lab 1 Objectives Learn how to structure TicTacToeprogram as
More informationExceptions. CSE 142, Summer 2002 Computer Programming 1.
Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 12-Aug-2002 cse142-19-exceptions 2002 University of Washington 1 Reading Readings and References»
More informationExceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.
Readings and References Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ Reading» Chapter 18, An Introduction to Programming and Object Oriented
More informationString is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents
String is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents character strings. All string literals in Java programs,
More informationI/O STREAM (REQUIRED IN THE FINAL)
I/O STREAM (REQUIRED IN THE FINAL) STREAM A stream is a communication channel that a program has with the outside world. It is used to transfer data items in succession. An Input/Output (I/O) Stream represents
More informationWrite a program to implement stack or any other data structure in Java ASSIGNMENT NO 15
Write a program to implement stack or any other data structure in Java ASSIGNMENT NO 15 Title: Demonstrate implementation of data structure in Java Objectives: To learn implementation of data structure
More informationChapter 4 Java I/O. X i a n g Z h a n g j a v a c o s q q. c o m
Chapter 4 Java I/O X i a n g Z h a n g j a v a c o s e @ q q. c o m Content 2 Java I/O Introduction File and Directory Byte-stream and Character-stream Bridge between b-s and c-s Random Access File Standard
More informationJava Just in Time: Collected concepts after chapter 18
Java Just in Time: Collected concepts after chapter 18 John Latham, School of Computer Science, Manchester University, UK. April 15, 2011 Contents 1 Computer basics 18000 1.1 Computer basics: hardware
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationAgenda & Reading. Python Vs Java. COMPSCI 230 S Software Construction
COMPSCI 230 S2 2016 Software Construction File Input/Output 2 Agenda & Reading Agenda: Introduction Byte Streams FileInputStream & FileOutputStream BufferedInputStream & BufferedOutputStream Character
More informationCSPP : Introduction to Object-Oriented Programming
CSPP 511-01: Introduction to Object-Oriented Programming Harri Hakula Ryerson 256, tel. 773-702-8584 hhakula@cs.uchicago.edu August 7, 2000 CSPP 511-01: Lecture 15, August 7, 2000 1 Exceptions Files: Text
More informationCS 200 File Input and Output Jim Williams, PhD
CS 200 File Input and Output Jim Williams, PhD This Week 1. WaTor Change Log 2. Monday Appts - may be interrupted. 3. Optional Lab: Create a Personal Webpage a. demonstrate to TA for same credit as other
More informationDo not turn to the next page until the start of the exam.
Principles of Java Language with Applications, PIC20a E. Ryu Winter 2017 Final Exam Monday, March 20, 2017 3 hours, 8 questions, 100 points, 11 pages While we don t expect you will need more space than
More informationSoftware 1 with Java. Recitation No. 9 (Java IO) December 10,
Software 1 with Java Recitation No. 9 (Java IO) December 10, 2006 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files
More informationExample: Copying the contents of a file
Administrivia Assignment #4 is due imminently Due Thursday April 8, 10:00pm no late assignments will be accepted Sign up in the front office for a demo time Dining Philosophers code is online www.cs.ubc.ca/~norm/211/2009w2/index.html
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More information23 Error Handling What happens when a method is called? 23.1 What is Exception Handling? A.m() B.n() C.p()
23 Error Handling Exit program (System.exit()) usually a bad idea Output an error message does not help to recover from the error Special error return Constructors do not have a return value What if method
More informationClasses Basic Overview
Final Review!!! Classes and Objects Program Statements (Arithmetic Operations) Program Flow String In-depth java.io (Input/Output) java.util (Utilities) Exceptions Classes Basic Overview A class is a container
More informationSoftware 1 with Java. Recitation No. 7 (Java IO) May 29,
Software 1 with Java Recitation No. 7 (Java IO) May 29, 2007 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes
More informationCore Java SYLLABUS COVERAGE SYLLABUS IN DETAILS
Core Java SYLLABUS COVERAGE Introduction. OOPS Package Exception Handling. Multithreading Applet, AWT, Event Handling Using NetBean, Ecllipse. Input Output Streams, Serialization Networking Collection
More informationObjec&ves STANDARD ERROR. Standard Error Streams. Ø Byte Streams Ø Text Streams 10/5/16. Oct 5, 2016 Sprenkle - CSCI209 1
Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 STANDARD ERROR Oct 5, 2016 Sprenkle - CSCI209 2 1 Standard Streams Preconnected streams Ø Standard Out: stdout
More information