-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Java examples #1
base: master
Are you sure you want to change the base?
Conversation
Added Java examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work. Just add a few changes, please.
private String city; | ||
private int born; | ||
|
||
public Objects() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO you should rename Objects
to some more appropriate class name, Person
, for example.
@@ -0,0 +1,45 @@ | |||
package com.company; | |||
|
|||
public class Objects { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd better rename this class to ObjectDemo
and make your object itself a static class in your demo, or make it separate at all.
/** | ||
* Created by Vova Moskalenko on 03.06.2017. | ||
*/ | ||
public class ObjectAccess { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as about Object.
|
||
public ObjectAccess() {} | ||
|
||
public String getCity() {return city;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style.
Serialization person = new Serialization(); | ||
//serialization | ||
try { | ||
FileOutputStream fileOut = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File input and output are redundant here. You should display exactly serialization and deserialization in this example. For instance, you can use JSON serialization and deserialization as in JavaScript example.
person2 = (Serialization) in.readObject(); | ||
in.close(); | ||
fileIn.close(); | ||
}catch(IOException i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style.
}catch(IOException i) { | ||
i.printStackTrace(); | ||
return; | ||
}catch(ClassNotFoundException c) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style.
out.close(); | ||
fileOut.close(); | ||
System.out.printf("Serialized data is saved in person.txt"); | ||
}catch(IOException i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style.
letters.add('C'); | ||
System.out.println(letters); | ||
|
||
String[] arr = {"C++", "JavaScript", "Python", "Haskell", "Swift"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why won't you make an arr
a List<String>
from the start?
|
||
String[] arr = {"C++", "JavaScript", "Python", "Haskell", "Swift"}; | ||
List<String> languages = Arrays.asList(arr); | ||
System.out.print("length: " + languages.size() + " " + "languages[0]:" + " " + languages.get(0) + " " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you split this line to fit 100 symbols in line, please? Just a code style suggestion.
Added Java examples