Page 1 :
Java notes :Q1. What is Java?, Java is a popular programming language, created in 1995.It is owned by Oracle, and more than 3 billion, devices run Java. It is used for:, Mobile applications ( specially Android apps), Desktop applications, Web applications, Web servers and application servers, Games, Database connection, And much, much more!, Q2. Why Use Java?, Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.), It is one of the most popular programming language in the world, It is easy to learn and simple to use, It is open-source and free, It is secure, fast and powerful, It has a huge community support (tens of millions of developers), Java is an object oriented language which gives a clear structure to programs and allows code to be reused,, lowering development costs, As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or vice versa, Q3. Write Java Syntax to print “Hello World”:public class Main, {, public static void main(String[] args) {, System.out.println("Hello World");, }, }, Example explained, Every line of code that runs in Java must be inside a class. In our example, we named the class Main. A class, should always start with an uppercase first letter., Note: Java is case-sensitive: "MyClass" and "myclass" has different meaning., The name of the java file must match the class name. The output should be:, Hello World, Q4. What is computer program?, Ans. A computer program is a sequence of instructions given to the computer in order to accomplish a, specific task. The instructions tell the computer what to do and how to do it., Q5. How java program executes?, Ans. Compilation Flow:, When we compile Java program using javac tool, the Java compiler converts the source code into byte code.
Page 2 :
Q6. What is the meaning of class, public, static, void, main, String[], System.out.println()., 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 creating 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 or String args[] is used for command line argument. We will discuss it in coming section., System.out.println() is used to print statement. Here, System is a class, out is an object of the PrintStream, class, println() is a method of the PrintStream class. We will discuss the internal working of, System.out.println() statement in the coming section., Q7. What are the different codes to write the main method :public static void main(String[] args), public static void main(String args[]), Q8. What are the features of java?, Ans. a) Simple : Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to, Sun Microsystem, Java language is a simple programming language because:, Java syntax is based on C++ (so easier for programmers to learn it after C++)., b) Object-oriented, Java is an object-oriented programming language. Everything in Java is an object. Object-oriented means we, organize our software as a combination of different types of objects that incorporate both data and, behavior., c) Platform Independent : Java is platform independent because it is different from other languages like C,, C++, etc. which are compiled into platform specific machines while Java is a write once, run anywhere, language. A platform is the hardware or software environment in which a program runs., d)Portable, Java is portable because it facilitates you to carry the Java byte code to any platform. It doesn't require any, implementation., Q9. What are variables?, Ans. A variable is a placeholder for data that can change its value during program execution. A variable is the, name for a storage location in the computer's internal storage. For exp:- int a;, a is here, name of the variable., Q10. What are the rules to write variable in java?, Ans. a) Variable names can begin with either an alphabetic character, an underscore (_), ($).They can consist, of only alphabets, digits and underscore., b) Spaces are not allowed in variable name . It cannot be a reserved word (int, if), c) Java is case sensitive language. For exp:- Percentage and PERCENTAGE are not same., d) Variable name should be meaningful.