Java Queries Here..

TheSloth

The Slowest One
^this. And to understand why or how do we use Class/Interface names to call static method, you should read how the memory allocation works in Java.
 

quicky008

Technomancer
i'm sorry if this seems irrelevant,but can someone recommend some good books for the foll. subjects:

1.Algorithms-it should cover all the essential precepts,including things like time complexity,space complexity etc in an easy to understand manner.

2.Automata.-i hardly know much about automata and would like to improve my understanding and knowledge of this subject to a greater extent.Ullman's book on automata is really popular-but is it easy to grasp for people who are not very familiar with this subject?

3.Data structures-the market seems flooded with a myriad books on this subject.But which one would be truly helpful for beginners?

4.Assembly language programming-while i have no immediate need for learning this subject,i still would like to explore it sometime later,simply because of my interest in this field.

5.Core java and advanced java programming.

Ps. recently i came across a book called "cracking the coding interview" on amazon.It seems very highly rated and is probably intended to help people acquire a more in-depth knowledge of the process of solving difficult problems that one may be given during tech-interviews/exams etc-is this book really as good as its made out to be?
 
Last edited:

TheSloth

The Slowest One
The last book I used to learn anything related to career was probably 6-7yrs back, from the book Desmond suggested. It really is a good book for beginners. You could also try Head First Java. I usually go for online resources. You could try Udemy, MOOC EDX Online courses for all these topics. They provide demo and you get the option of refund if you didn't like the teaching of the instructor on Udemy.
 

thetechfreak

Legend Never Ends
Don't know about others but Herbert Schildt's book is best for Java. I think it's called Java complete reference or something.
+1 for this. My college professor(during bachelor degree) consulted this book and Head First. Both of them are very good. Great for learning Java. It's a shame I haven't written much Java after my Bachelor's degree(other than for Android).
 

thetechfreak

Legend Never Ends
*www.humblebundle.com/books/java-programming-more-oreilly-books

5 Java based books fro $1.
Yeah worth it. Also, a whole book dedicated to threads. Wow. @dDesmond David could use it maybe.

The 8$ bundle with Kotlin is something I could consider.

Sent from my vivo 1807 using Tapatalk
 

Desmond

Destroy Erase Improve
Staff member
Admin
Wow, those are some pretty good books.

Edit: Bought all of them. Now will I get time to read, that is the question.
 
Last edited:

TheSloth

The Slowest One
I also have been thinking to buy because of Java Threads but I am not able to decide. Do we really need to think about threads in web development when all the java based frameworks like Spring Boot, Play etc runs in a container which is self managed by the containers. Am I right?
What use cases do we have in today's Java programming where deep knowledge on Threads might come handy?
 

Desmond

Destroy Erase Improve
Staff member
Admin
Do we really need to think about threads in web development
Not really but depends on your use case. It's most helpful if you are doing something like batch processing.
Spring Boot, Play etc runs in a container which is self managed by the containers. Am I right?
These don't run in a container by default. You will have to write a Dockerfile for your build to run in a container.
What use cases do we have in today's Java programming where deep knowledge on Threads might come handy?
Like I said, batch processing or data processing. Like if you have to process a large number of files, then you will have to use threads to process them parallelly to increase throughput. But then again you don't have to know too much for most common use cases, just general idea is usually enough.
 

TheSloth

The Slowest One
These don't run in a container by default. You will have to write a Dockerfile for your build to run in a container.
Doesn't spring/play comes with its own container which creates a independent thread for each (http)request and those threads are managed until the purpose is served.
 

Desmond

Destroy Erase Improve
Staff member
Admin
Doesn't spring/play comes with its own container which creates a independent thread for each (http)request
If you are speaking about servlet container, then yes. But this is not something spectacular, a servlet container is basically same as an ordinary web server with the added functionality of running web applications and routing the requests to the appropriate web applications. As such, like any other web server, it creates new threads to handle requests.
those threads are managed until the purpose is served.
But not by us, the request thread's lifecycle is handled internally by the servlet container. We can spawn new threads for our own purposes though INSIDE the servlets but not in the servlet container itself.

For example, say I want to create a web application that takes a date range and calculates the average salary of all employees within that time range. In that case, you can define a servlet to spawn multiple threads to perform this calculation in parallel. But this is after the servlet container receives the request and spawns a thread to handle the request and then route the request to your container. So, you don't have to worry about how the servlet container is handling the threads.
 

TheSloth

The Slowest One
Very well explained. So far I have not implemented anything significant/exciting using Threads and since everything gets taken care by servlet container itself, I feel even more lazy to go through this topic since I have other things to focus on.

Also i gave in and bought the books for my collection. Paid Rs.77.71 instead of 74.
 

quicky008

Technomancer
In a java program on file handling,I came across this statement: copy("temp.txt",Filename);

what does the copy command do here exactly?

When i tried to run it,it shows an error that says
Unresolved compilation problem:
The method copy(String, String) is undefined for the type file5 (where file5 was the class name)

Any ideas as to why is this happening?

couldn't find much info or examples on copy anywhere online.
 

thetechfreak

Legend Never Ends
I think the variables you pass in the copy method need to be the source and destination to paste the files.

So source.txt needs another filenane to copy into..


Can you share your code via pastebin or something?

Sent from my vivo 1807 using Tapatalk
 

quicky008

Technomancer
it looks like this:

import java.io.*;
public class file5 {

//wap to insert a record in an existing file

public static void main(String[] args) throws IOException
{

String fileName="c:\\java\\student.txt";
String nametoinsert="B2";
String after="B";
int age=24,marks=25;


FileReader fr=new FileReader(fileName);
BufferedReader br=new BufferedReader(fr);
FileWriter fw=new FileWriter("c:\\java\\TEMP.TXT",false);
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter pw=new PrintWriter(bw);
String name;
while((name=br.readLine())!=null)
{
pw.println(name);
if(name.equalsIgnoreCase(after))
{ pw.println(nametoinsert);
pw.println(age);
pw.println(marks);
}
}
br.close();
fr.close();
pw.close();
bw.close();
fw.close();

copy("c:\\java\\TEMP.TXT",fileName);

System.out.println("Record inserted successfully !");
}





}

}
 

Desmond

Destroy Erase Improve
Staff member
Admin
The method copy(String, String) is undefined for the type file5 (where file5 was the class name)
Seems like a custom written method. It's probably outside the main() method in the same class. Do you have the code for the whole class?

Perhaps you are expected to write that method yourself.
 

TheSloth

The Slowest One
Also, would suggest to learn nio package in java APIs, way better than using buffered input streams for common works like these. I just feel that it looks more organized and straight-forward when reading code which uses nio package.
 
Top Bottom