DEV Community

Divyansh Pratap Singh
Divyansh Pratap Singh

Posted on

Java Summary ‎️‍🔥‎️‍🔥

1.You can write java program in Javashell easily -
ex- System.out.print("hello World"); Simple right?
but not on vs code or machine easily- needs some steps
1.compile that file in which we have written code
2.we need jvm in our machine

coder --> written Code in VsCode --> Compile this code by typing in the terminal (javac) --> After compiling it gives us a byte code (give .class file)--> JVM --> will Ask machine Do you have main method ?(Public static void main) and then this method will say see java is a object oriented language means everything should be in object . so this method will check for class is present or not.
and if all the things are present then our code start to executing by typing these two commands in terminal - 1 javac

For a developer you need to install jdk because -

Image description

Javascript is a strongly typed language means we need to add int string before variable

3.Switch statement -
int n = 1;
switch (n) {
case 1 : syso("Monday")
case 2 : syso ("tuesday")
break ;

Objects have states and behaviors.It know something in brain and do activities
example -
ex1- A pen Which having state of Solid and its behaviour is For writing purpose
ex2- Your marks

Class is A collection of Objects .
A class can be defined as a template/blueprint that describes the behavior/state that the object of its type support.
ex- If lets suppose You are topper and a fluent speaker of your class then How your relatives will be know that you are really topper or not?
when they know Test your Knowledge And By seeing your marks

Class youAreTopper(){
int lastYearResult = 98%;
string yourConfidence = "High"
stringg yourSpeakingSkills = "High"

6.single line loop?
int n = 4 ;
result = n%2 == 0 ? 10:20;

7.static meaning-
The static keyword is used to declare a method or a variable as belonging to the class itself, rather than to an instance (object) of the class. This means that you can call a static method or access a static variable directly through the class name, without creating an instance of the class.

ex -
class Calculator {
public int add(int n1, int n2) {
int result = n1 + n2;
return result;
public static void main(String[] args) {
calculator calc = new calculator();
int result = calc.add(num1 + num2)
Here you are creating the instance of name calculator

void meaning-
The void keyword is used to indicate that a method does not return any value. When a method is declared with void as its return type, it means the method performs some actions or operations but does not produce a result that needs to be returned.

class calculator;
public int add(int n1, int n2)
Aise hota then it will return the result in integer only

8.Methods -
Here is the best explaination for methods in java

  1. Recursion - Example undertand it public class Main { public static void main(String[] args) { int result = sum(10); System.out.println(result); } public static int sum(int k) { if (k > 0) { return k + sum(k - 1); } else { return 0; } } }

10 + sum(9)
10 + ( 9 + sum(8) )
10 + ( 9 + ( 8 + sum(7) ) )
10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + sum(0)
10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0

Constructor in java is used to create the instance of the class.

Top comments (1)

sloan profile image
Sloan the DEV Moderator

Just a heads up that you can add highlighting to the code blocks if you'd like. Just change:

code block with no colors example

... to specify the language:

code block with colors example

More details in our editor guide!