This is going to be the first article of the Master Java series. π
π° History of Java:
Java was created in 1995 by James Gosling(who is also called as the father of Java). James and team (who were working for Sun Microsystems owned by Oracle) started with a project to create a language for television technology but apparently, at that time Java was too advance for television and it turned out to be more useful for programming.
Naming this language also has an interesting back story. First, they named it Green talk (which had a file extension .gt). Then they changed it to Oak (Interestingly, Oak is the national tree of USA) then they finally changed it to Java (since the name Oak was already trademarked by Oak technologies).
Fun fact - Java is an island in Indonesia where the first coffee was made called Java coffee and apparently James made this decision of naming it Java while having coffee in his office.
π° Why Java over other languages?
Java has amazing advantages compared to other languages and that is the reason it has gotten so much name in the software industry for the past two decades. Some of the advantages of Java are as follows:
π― Object-oriented language - you can create programs in modules, which means you can reuse these programs.
π― Platform Independence - Create your program in one type of machine and run it on any other machine using the help of JVM(Java Virtual Machine).
π― Secure - Java has a security manager that defines the access of classes.
π― Multithreading - can perform multiple tasks at the same time.
π― Memory - Java uses heap and stack for memory allocation, which helps us to store and retrieve data easily.
π° Writing your first java program:
Let us write a simple java program.
class first{
public static void main(String args[]){
System.out.print("Hello world");
}
}
save these lines of code in a file called first.java (name should match with our class) and run the following commands in the command line.
javac first.java
java first
We should get the output as Hello World! Let us understand the parameters that we used.
β© class keyword is used to declare a class in java.
β© public keyword is an access modifier that represents visibility. It means it is visible to all.
β© static is a keyword. If we declare any method as static, it is known as the static method. The core advantage of the static method is that there is no need to create an object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create an object to invoke the main method. So it saves memory.
β© void is the return type of the method. It means it doesn't return any value.
main represents the starting point of the program.
String[] args is used for the command-line argument. We will learn it later.
β© System.out.println() is used to print statement. Here, System is a class, out is the object of PrintStream class, println() is the method of PrintStream class.
... To be continued! π
Keep learning! keep coding! π
Top comments (10)
I know it's early to ask but can you tell me how to create a user defined 'FastReader class'.
I want to use it because Scanner class takes a lot of time resulting in time limit exceed in competitive programming and BufferReader class is also never recommended in competitive programming because of its complexity.
Hey Parth! When it comes to competitive programming, if you are ending up with TLE, try to optimize the time complexity by changing the approach of solving the problem, but if you are not able to do that, then you can use the FastReader class, I will be writing the article on it soon. Meanwhile do refer to the article given by Mohamed given in the comments!
PS - it is always better to use Scanner class since fast I/O methods make your program very lengthy. And these type of questions are really rare and won't be asked in interviews as such!
Thank you Raksha! :)
While the author replies, check out the geeks-for-geeks post about this: geeksforgeeks.org/fast-io-in-java-...
Thanks Mohamed Moustafa :)
Great post! Looking forward to the next one.
Thank you! π
Cool! Waiting for the next one.
Glad you liked it! :)
Some questions related to java: tutorialsmate.com/2020/06/core-jav...
Quick learning...