Life long sharing . . .

Archive for the ‘Java’ Category

Here is a summary from the Tutorials Point website.

Lesson13-note1

Three Types of Exceptions: (Checked exceptions, Unchecked exceptions, Errors)

Lesson13-note2

If you try to compile the below program, what will you get?

Lesson13-code1

Lesson13-note3

Try compile the below codes. Do you get any exception?

Lesson13-code3

Try execute the codes. What do you get?

Lesson13-note4

Here is the hierarchy of exception classes in Java:

Lesson13-note5

Here is the list of commonly used/encountered Java Unchecked (Runtime) exceptions:

Lesson13-list1

Here is the one for Checked exceptions:

Lesson13-list2

Lesson13-note6

Lesson13-note7

Try compile and execute the below codes. What is the output?

Lesson13-code6

Lesson13-note9

Try the below codes. What is the output?

Lesson13-code7

Lesson13-note11

Study the below codes:

Lesson13-code8

Lesson13-note12

Lesson13-note8

 

Source: http://www.tutorialspoint.com/java/java_exceptions.htm

Advertisements

Java provides rich library for Input/Output (I/O) related to files and networks. We will cover those commonly used one.

Lesson12-note1

Lesson12-note2

Lesson12-code1

Lesson12-note3

Lesson12-code2

Lesson12-note4

Lesson12-code3

Lesson12-note5

Lesson12-code6

Lesson12-note6

Lesson12-code4

Lesson12-note7

Lesson12-note8

Lesson12-code5

Source: http://www.tutorialspoint.com/java/java_files_io.htm

This website has a good explanation of the date class: http://www.tutorialspoint.com/java/java_date_time.htm.

Let’s recap those important one here.

Lesson9-note1

Lesson9-note2

Lesson9-note3

Lesson9-code1

You will get:

Lesson9-code2

Lesson9-note4

Lesson9-code3

You will get if no input parameter is supplied (study line 9 carefully):

Lesson9-code4

Here is another example for comparing dates:

Lesson9-code5

Exercise: try to modify the above codes to use ” int compareTo(Date date)” method instead of “boolean before(Date date)” and “boolean after(Date date)”.

Lesson9-note5

Lesson9-note6

Try to read and understand the below codes.  How long in second that the thread sleep?

Lesson9-code6

 

 

Lesson11-note1

Lesson11-code1

What is the output for the above codes?

Lesson11-note2

Let’s try the below program. What is the output?

Lesson11-code2

Source: http://www.tutorialspoint.com/java/java_methods.htm

method1

1. Method returning value:

Lesson10-code1

What is the result for the above codes?

2. Method without returning value:

Lesson10-code2

What is the result for the above codes?

The next topic we are going to learn is way parameters is being passed. For Java, parameter is passed by value.

Lesson10-note2

In some other programming language, parameter can be passed by reference. Try to think it from a

1. What is the value of a and b after swapping?

Lesson10-code3

2. What is the name of dogA and dogB at the end of the program? And Java passes by ??

Lesson10-code5

Lesson10-note3

In changeName() method, the code modifies the name field of the object.

In changeDog() method, the method reference points to a new object.

3. What is the value of array after swapping?

Lesson10-code4

Lesson10-note6

Try to add in the missing codes in the below program.

Lesson10-code7

Lesson10-note4

Lesson10-code6

What is the output of the above codes?

Lesson10-note5

Source: http://www.tutorialspoint.com/java/java_methods.htm

Lesson7-note1

Lesson7-note2

Lesson7-note4

Loop Control Statements:

Lesson7-note3

What do you think is the output of the above two programs?

 

 

 

Source: http://www.tutorialspoint.com/java/java_loop_control.htm

Lesson8-note1

Lesson8-note2

Lesson8-note3

Let’s try this exercise. Try amend the codes to get 1) the total of values and 2) the largest value in the array.

Lesson8-code1

Now, try to add this line to the end of the code and try running the program. What will you get?

Lesson8-code2

Yes, ArrayIndexOutOfBounds errors occur whenever you exceed the maximum index in an array. Remember, array indices are 0-based.

Two dimensional Arrays:

Two dimensional arrays are declared, allocated and initialized much like one dimensional arrays. However we have to specify two dimensions rather than one, and we typically use two nested for loops to fill the array.

Try below codes.

Lesson8-code3

This is the picture representing my2DimList:

Lesson8-code4

Oh ya, I almost forget this.

Lesson8-note4.png

For example:

Lesson8-code5

Try to compile and run this program as below. What is the output for each of the command below?

java MainArray

java MainArray Jan

java MainArray Nov 2005

java MainArray 2015

Reference:

http://www.tutorialspoint.com/java/java_arrays.htm

http://www.freejavaguide.com/arrays.htm


Archives

September 2017
M T W T F S S
« May    
 123
45678910
11121314151617
18192021222324
252627282930  

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 180 other followers