Friday, July 3, 2015

Resources of java practice problems

To learn any programming language one must practice. It is the only way to become master in any particular language.

There are many sites for Java practice depending upon your expertise. There are some suggestions below.

For Experts:
  •  Hacker Rank
  •  Code Chef
  •  Coding Bat


For Beginners:

But if you want to start from beginning then I would recommend you to Merit CampusThere are various topics which you can read online. They also have good practice tests which will help you become expert in the field. There online compiler helps in checking the programs immediately with out having to install JDK on your machine or PC.

Java Topics:
http://java.meritcampus.com/java-tests?tc=mm32

Online Compiler:
http://java.meritcampus.com/java_compiler/run?tc=mm31

Also, expert training is provided by this site where experts will give online coaching to students.

Expert Training:
http://java.meritcampus.com/expert-java-training?tc=mm30

Hope that you will have a good programming journey.


Difference between string literal and object


String: String is class in java. It is used to hold the group of characters.


There are two ways of declaring strings:

1) String Literal

2) String Object


Example: 

i) String str="JAVA";

ii) String str=new String("JAVA");

The first type of string is a String Literal. 

The second type of string is an String object.


There is no difference in the content, but creating object occupies a lot of memory in your system. so JVM (Java Virtual Machine) uses some trick to reduce the cost of memory occupied by the string. JVM maintains a string Pool which contains all the unique string literals declared by your programs. 

So, Whenever you declare any String literal, JVM checks the string pool if that string is present in that pool then again memory is not occupied by that string instead both the string points to one memory location.' 

See this image for more information. 
                                                    Fig: String Pool


For more Details Refer following links: 

Is java easier than C?


JAVA is much more easier than C. 



JAVA is very Simple and easy to learn as very difficult Concepts of C like: 


  •  Pointers 

  •  Operator Overloading

  •  free() memory explicitly 




are removed from the JAVA. And many more features like "Garbage Collection" and "Security" as pointers are not there. 


For more features refer following link: 






To learn java you can refer books for theory knowledge like: 

Books on java:

1) Complete Reference 


2) Balaguruswamy 

Also, There are many Website from where you can learn java online: 

For Difficult Programs:

1) Codechef 

2) Hackerearth 
3) Hackerrank 






For Beginners: 
1) Meritcampus (Various Topics+ Online Compiler+ practice Tests + Expert Training)



2) W3school

C,C++,CSS and Java vs javascript


C,C++,CSS


C is a popular programming language developed by "Dennis Richie" where there is important concept of pointers but there is no objects at all. Everything is written inside main(). It is still used by many organizations as it work with core and basic memory functions like free(), malloc() and alloc() etc. 


C++ is like C but with object-oriented capabilities. You can define your own class and make objects of that class. 


There are many features of c++ like: 

  • Encapsulation 
  • object-oriented 
  • Inheritance 
  • Overriding and overloading 


CSS stands for Cascading style sheet. It is used to define style for HTML page. Instead of defining font for each and every tag of every page just create one css file and link it to every page of HTML. 

Advantages of CSS: 

1) Saves time and memory 
2) Sepration between content and presentation 

For more Details on above languages Refer following link: 






 JAVA VS Java Script: 


JAVA: Java is object-oriented programming language which is developed by "James Gosling" and his team and which was previously called as "OAK". 

Java is full-featured programming language with many features like: 

1) Platform independence 
2) Object-oriented 
3) Multithreaded 
4) secure 
5) Robust 
6) Distributed 
6) Simple and many more...


For more Details Refer following link: 



Java Script: Java script is interpreted language which is generally embedded inside an HTML page. It is client-side scripting language which is used to create interactivity within static HTML pages and decrease the burden of server by providing instant feedback to server. 

Java script is scripting language not programming language. 

For more Details Refer following link: 









Java applet vs application


JAVA Applet: Applet is a small program that doesn't have any main() method and which runs either in browser or in appletviewer. 


JAVA Application: Java application is a program with main() method which has input and display output on standard command prompt. 


There are many differences between JAVA Applet and JAVA Application: 

1) Applet requires appletviewer and application requires java interpreter.

2) Applet can not have access to local files on system whereas application has.

3) Applet has paint() method and application has main() method. 

4) Applet is required for building GUI based application.



                                                               Fig: Java Applet



For more Details Refer following link



Exceptions in java



 Exceptions are one of the important concept of Java.

Exception: Exceptions are nothing but Run-time error which comes in program due to Logical errors in program like "Divide by Zero", "Null pointer Exception" etc. Exception is a class in java. Sometimes there is no Compilation Error (Syntactical error) in your program but due to some errors at run-time like wrong user input error may arise and your program will be abruptly closed.



Fig: Exception Class Hierarchy

So, To avoid your program to be closed abruptly, you must know how to handle Exception by using "Try-Catch" block. 

There are two types of Exception:



1) System Defined (handled by throws/throw)



2) User Defined (handled by throw) 

There are various Exception classes in java like:


  •  ArrayIndexOutOfBoundsException
  •  DivideByZeroException
  •  IOException
  • NullPointerException and many more...



For  more Details Refer following link:



Garbage collection in Java


Garbage Collection is one the important feature of programming language like JAVA which is related with the memory management. At the end of program execution, objects which go out of scope or which are no longer referenced in the programs Java Virtual Machine (JVM) reclaims the memory associated with them. Unlike C++, there is no need of freeing the memory by using free() method explicitly; instead JVM automatically frees the memory allocated by objects.

Fig: Garbage Collection

finalize() method is invoked whenever object is collected for garbage.So, One can place the code for releasing resourcing or closing of files inside this method by overriding this.

For more Details Refer following link:




Is Java compiled or interpreted?


Java is both Compiled and interpreted Language. Therefore Executing a java program is two stage process described as follows:

  1.  Compiling a source file(.java) and create byte code file(.class)
  2.  Interpreting byte code(.class) file and create binary code(.exe)file




                                           Fig: Java program Execution process

See the diagram:

i) Java program is converted into byte code file by java compiler (javac)

ii) JVM converts byte code file into binary code (.exe) file i.e. instructions which can be understood by operating system and hardware directly. 
 
This two stage process makes java platform independent as java files are not directly converted to executable files instead they are converted to byte code file which can be used on any platform.


For more features refer following link:



Java's security than other languages


Java is much more Secure than other languages like C and C++.


Following are the reasons support this fact:


1) There are no pointers in java: pointers directly access memory location.so, any one can write erroneous program to harm your data stored in computer memory. 

2) Memory management: feature so there are no memory leaks.

3) Garbage Collection: Java Virtual Machine (JVM) is responsible for collecting the memory which is not in use like when objects go out of scope they are not useful, then JVM collects the memory occupied by the object.

4) Exception Handling: Exception is a Run-time error in program which comes due to logical errors in program like Divide by zero etc. Exception is a class in java.

5) Crash recovery: Program written in java never crashes. It terminates successfully.

Also,Extra security is provided for java applets.Applets can not access local files on your system. 


For more information please refer: 


http://java.meritcampus.com/t/76/Java---other-features?tc=mm84


http://java.meritcampus.com/t/73/Java-and-internet?tc=mm85


Why there are no pointers in Java?

Pointer is used to hold the address of a variable or object.


                              

                                                              Fig: Pointer

Pointer is very important concept of C which helps us to directly access memory location and provide a way of passing values by reference and making permanent changes in variable values which is a concept of "Pass by Reference"

Pointers can directly access the memory locations so sometimes it can be dangerous to use them,any attacker may write program ruin all your computer memory data which can create big problem for users.So, In java concept of pointers is removed. However, the same functionality can be achieved by creating object reference. 


Java has references, but not pointers

There are wrapper classes in java which  are used to convert primitive data types into objects. These objects can act as an reference.

Below is the syntax of creating object reference and object.


For eg. if the class name is Student then we will do Object Instantiation using
Student s = new Student(); Object Instantiation: Class_name obj = new Class_name
Object Reference: Class_name obj;

For more information please refer: 




Interesting facts on java

Interesting Facts on JAVA:

Do you know what is the meaning of java? Well, It means Coffee. Search on google, the first result it gives you is as follows:


                                                           Fig: Meaning of java

If you are a beginner of java, You might be having many questions on java like what is java, What is the full-form of java, what is the history of this language etc. Below are the answers of your questions.

  • What is java?

Java is a programming language which was developed by the "James Gosling" and his team. Java was first named as "OAK" and was designed for embedded system (To control the operation of hardware devices).

Java has many Features like:

1.Platform Independence (can run on any platform)

2.Secure (do not have pointers and there is memory management)
3. Robust (no crashing)
4.simple and easy (no overloading and pointer concept)
5. Multi threading (many processes can run together)
6. Distributed (many developers can work together from different areas)



You can refer books for theory and online sites for practices as "Practice makes man perfect".
Various online sites are available like tutorials point etc but to start from beginning go for Merit Campus Website.

Link for Merit Campus Website:

http://java.meritcampus.com/?tc=mm4

For more Features and creation of java refer following links: 

  • What is the meaning of word java OR What is the full-form of word java?

    There is no full-form of java, It was first named as "OAK" but due to some naming issues it was named as "JAVA" which is name of "Coffee Island". As already stated, The reason of choosing this name was team has consumed a lot of coffee during the development of this programming language. 

    For more details on features and creation of java refer following links: 

    http://java.meritcampus.com/t/72/Creation-of-java?tc=mm90


  • What is the background of java?
 Java was designed for embedded system but later found that it can be used as general purpose language and due to naming issue,it was named as "JAVA" which is name of "island of coffee". 


The reason for keeping this name was team has consumed a lot of coffee during the development of this language. James Gosling and his team were given a job of "Finding a language" which best suits their requirements. They were developing application for "Set top Box", So they were looking for a Portable language. But, they didn't find one and they came with new language which satisfies all their requirements.

For more details on features and creation of java refer following links: 



http://java.meritcampus.com/t/76/Java---other-features?tc=mm112

  • What is core java?
Core java is nothing but basic of java like knowing the basic concepts such as objects, encapsulation, Inheritance etc. 

You can refer books.There are various books for java like: 

1) Complete reference 
2) balaguruswamy 

Here is a link where you can get free pdf for various java books: 
Free Java Books : PDF Download 


http://www.onlineprogrammingbooks.com/java/


Also refer sites to practice programs like: 

For Difficult programs: 
Codechef 
Hackerrank 
Tutorialspoint 

For Beginners: 
Merit Campus (Topics on java+ practice test+expert training+online java compiler)

http://java.meritcampus.com/?tc=mm113